Skip to content

Commit 3551c4b

Browse files
authored
Fix UniFi Protect G6 Instant speaker volume control (home-assistant#157549)
1 parent e7edd51 commit 3551c4b

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

homeassistant/components/unifiprotect/media_player.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ class ProtectMediaPlayer(ProtectDeviceEntity, MediaPlayerEntity):
7979
def _async_update_device_from_protect(self, device: ProtectDeviceType) -> None:
8080
super()._async_update_device_from_protect(device)
8181
updated_device = self.device
82-
self._attr_volume_level = float(updated_device.speaker_settings.volume / 100)
82+
speaker_settings = updated_device.speaker_settings
83+
volume = (
84+
speaker_settings.speaker_volume
85+
if speaker_settings.speaker_volume is not None
86+
else speaker_settings.volume
87+
)
88+
self._attr_volume_level = float(volume / 100)
8389

8490
if (
8591
updated_device.talkback_stream is not None

homeassistant/components/unifiprotect/number.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ def _get_chime_duration(obj: Camera) -> int:
9292
ufp_set_method="set_mic_volume",
9393
ufp_perm=PermRequired.WRITE,
9494
),
95+
ProtectNumberEntityDescription(
96+
key="system_sounds_volume",
97+
translation_key="system_sounds_volume",
98+
icon="mdi:volume-high",
99+
entity_category=EntityCategory.CONFIG,
100+
native_unit_of_measurement=PERCENTAGE,
101+
ufp_min=0,
102+
ufp_max=100,
103+
ufp_step=1,
104+
ufp_required_field="feature_flags.has_speaker",
105+
ufp_value="speaker_settings.volume",
106+
ufp_enabled="feature_flags.has_speaker",
107+
ufp_set_method="set_volume",
108+
ufp_perm=PermRequired.WRITE,
109+
),
110+
ProtectNumberEntityDescription(
111+
key="doorbell_ring_volume",
112+
translation_key="doorbell_ring_volume",
113+
icon="mdi:bell-ring",
114+
entity_category=EntityCategory.CONFIG,
115+
native_unit_of_measurement=PERCENTAGE,
116+
ufp_min=0,
117+
ufp_max=100,
118+
ufp_step=1,
119+
ufp_required_field="feature_flags.is_doorbell",
120+
ufp_value="speaker_settings.ring_volume",
121+
ufp_enabled="feature_flags.is_doorbell",
122+
ufp_set_method="set_ring_volume",
123+
ufp_perm=PermRequired.WRITE,
124+
),
95125
ProtectNumberEntityDescription(
96126
key="zoom_position",
97127
translation_key="zoom_level",

homeassistant/components/unifiprotect/strings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@
289289
"chime_duration": {
290290
"name": "Chime duration"
291291
},
292+
"doorbell_ring_volume": {
293+
"name": "Doorbell ring volume"
294+
},
292295
"infrared_custom_lux_trigger": {
293296
"name": "Infrared custom lux trigger"
294297
},
@@ -298,6 +301,9 @@
298301
"motion_sensitivity": {
299302
"name": "Motion sensitivity"
300303
},
304+
"system_sounds_volume": {
305+
"name": "System sounds volume"
306+
},
301307
"volume": {
302308
"name": "[%key:component::sensor::entity_component::volume::name%]"
303309
},

tests/components/unifiprotect/fixtures/sample_camera.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@
173173
"speakerSettings": {
174174
"isEnabled": true,
175175
"areSystemSoundsEnabled": false,
176-
"volume": 100
176+
"volume": 100,
177+
"speakerVolume": 100,
178+
"ringVolume": 100
177179
},
178180
"recordingSettings": {
179181
"prePaddingSecs": 10,

tests/components/unifiprotect/test_media_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def test_media_player_setup(
6666
assert entity
6767
assert entity.unique_id == unique_id
6868

69-
expected_volume = float(doorbell.speaker_settings.volume / 100)
69+
expected_volume = float(doorbell.speaker_settings.speaker_volume / 100)
7070

7171
state = hass.states.get(entity_id)
7272
assert state

tests/components/unifiprotect/test_number.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ async def test_number_setup_camera_all(
107107
camera.feature_flags.has_led_ir = True
108108
camera.isp_settings.icr_custom_value = 1
109109
camera.isp_settings.ir_led_mode = IRLEDMode.CUSTOM
110+
camera.feature_flags.has_speaker = True
111+
camera.speaker_settings.volume = 1
112+
camera.feature_flags.is_doorbell = True
113+
camera.speaker_settings.ring_volume = 1
110114
await init_entry(hass, ufp, [camera])
111-
assert_entity_counts(hass, Platform.NUMBER, 5, 5)
115+
assert_entity_counts(hass, Platform.NUMBER, 7, 7)
112116

113117
for description in CAMERA_NUMBERS:
114118
unique_id, entity_id = await ids_from_device_description(

0 commit comments

Comments
 (0)