diff --git a/homeassistant/components/matter/icons.json b/homeassistant/components/matter/icons.json index 874156c2831a..2e9f41f6a27a 100644 --- a/homeassistant/components/matter/icons.json +++ b/homeassistant/components/matter/icons.json @@ -54,6 +54,14 @@ "laundry_washer_spin_speed": { "default": "mdi:reload" }, + "night_vision": { + "default": "mdi:weather-night", + "state": { + "auto": "mdi:weather-night-partly-cloudy", + "off": "mdi:weather-sunny", + "on": "mdi:weather-night" + } + }, "power_level": { "default": "mdi:power-settings" }, diff --git a/homeassistant/components/matter/select.py b/homeassistant/components/matter/select.py index f784d1750b6f..7f8f848c1089 100644 --- a/homeassistant/components/matter/select.py +++ b/homeassistant/components/matter/select.py @@ -50,6 +50,17 @@ PUMP_OPERATION_MODE_MAP = { } PUMP_OPERATION_MODE_MAP_REVERSE = {v: k for k, v in PUMP_OPERATION_MODE_MAP.items()} +CAMERA_FEATURE_NIGHT_VISION = ( + clusters.CameraAvStreamManagement.Bitmaps.Feature.kNightVision +) + +NIGHT_VISION_MAP = { + clusters.CameraAvStreamManagement.Enums.TriStateAutoEnum.kOff: "off", + clusters.CameraAvStreamManagement.Enums.TriStateAutoEnum.kOn: "on", + clusters.CameraAvStreamManagement.Enums.TriStateAutoEnum.kAuto: "auto", +} +NIGHT_VISION_MAP_REVERSE = {v: k for k, v in NIGHT_VISION_MAP.items()} + type SelectCluster = ( clusters.ModeSelect | clusters.OvenMode @@ -599,6 +610,20 @@ DISCOVERY_SCHEMAS = [ clusters.PumpConfigurationAndControl.Attributes.OperationMode, ), ), + MatterDiscoverySchema( + platform=Platform.SELECT, + entity_description=MatterSelectEntityDescription( + key="CameraAvStreamManagementNightVision", + entity_category=EntityCategory.CONFIG, + translation_key="night_vision", + options=list(NIGHT_VISION_MAP.values()), + device_to_ha=NIGHT_VISION_MAP.get, + ha_to_device=NIGHT_VISION_MAP_REVERSE.get, + ), + entity_class=MatterAttributeSelectEntity, + required_attributes=(clusters.CameraAvStreamManagement.Attributes.NightVision,), + featuremap_contains=CAMERA_FEATURE_NIGHT_VISION, + ), MatterDiscoverySchema( platform=Platform.SELECT, entity_description=MatterSelectEntityDescription( diff --git a/homeassistant/components/matter/strings.json b/homeassistant/components/matter/strings.json index c0d9ed6971b1..5e5e48904104 100644 --- a/homeassistant/components/matter/strings.json +++ b/homeassistant/components/matter/strings.json @@ -368,6 +368,14 @@ "stretch": "Stretch" } }, + "night_vision": { + "name": "Night vision", + "state": { + "auto": "[%key:common::state::auto%]", + "off": "[%key:common::state::off%]", + "on": "[%key:common::state::on%]" + } + }, "power_level": { "name": "Power level (W)" }, diff --git a/tests/components/matter/snapshots/test_select.ambr b/tests/components/matter/snapshots/test_select.ambr index ab5ff7037361..ca1598c67902 100644 --- a/tests/components/matter/snapshots/test_select.ambr +++ b/tests/components/matter/snapshots/test_select.ambr @@ -1,4 +1,65 @@ # serializer version: 1 +# name: test_selects[aqara_camera_hub_g350][select.aqara_camera_hub_g350_night_vision-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'off', + 'on', + 'auto', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': , + 'entity_id': 'select.aqara_camera_hub_g350_night_vision', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Night vision', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Night vision', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'night_vision', + 'unique_id': '00000000000004D2-00000000000000BB-MatterNodeDevice-2-CameraAvStreamManagementNightVision-1361-22', + 'unit_of_measurement': None, + }) +# --- +# name: test_selects[aqara_camera_hub_g350][select.aqara_camera_hub_g350_night_vision-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Aqara Camera Hub G350 Night vision', + : list([ + 'off', + 'on', + 'auto', + ]), + }), + 'context': , + 'entity_id': 'select.aqara_camera_hub_g350_night_vision', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'auto', + }) +# --- # name: test_selects[aqara_led_strip_t2][select.aqara_led_strip_t2_music_sync_effect-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/matter/test_select.py b/tests/components/matter/test_select.py index 52e0238b0a9d..b500ba916f72 100644 --- a/tests/components/matter/test_select.py +++ b/tests/components/matter/test_select.py @@ -241,6 +241,94 @@ async def test_pump( assert state.state == "local" +@pytest.mark.parametrize("node_fixture", ["aqara_camera_hub_g350"]) +async def test_camera_night_vision( + hass: HomeAssistant, + matter_client: MagicMock, + matter_node: MatterNode, +) -> None: + """Test the CameraAvStreamManagement night vision select.""" + entity_id = "select.aqara_camera_hub_g350_night_vision" + # fixture reports NightVision as TriStateAutoEnum.kAuto + state = hass.states.get(entity_id) + assert state + assert state.state == "auto" + assert state.attributes["options"] == ["off", "on", "auto"] + + attribute_path = create_attribute_path_from_attribute( + endpoint_id=2, + attribute=clusters.CameraAvStreamManagement.Attributes.NightVision, + ) + set_node_attribute(matter_node, 2, 1361, 22, 0) + await trigger_subscription_callback( + hass, + matter_client, + data=0, + node_id=matter_node.node_id, + attribute_path=attribute_path, + ) + state = hass.states.get(entity_id) + assert state + assert state.state == "off" + await hass.services.async_call( + "select", + "select_option", + {"entity_id": entity_id, "option": "on"}, + blocking=True, + ) + assert matter_client.write_attribute.call_args_list == [ + call(node_id=matter_node.node_id, attribute_path=attribute_path, value=1) + ] + + await hass.services.async_call( + "select", + "select_option", + {"entity_id": entity_id, "option": "auto"}, + blocking=True, + ) + assert matter_client.write_attribute.call_args_list[1] == call( + node_id=matter_node.node_id, attribute_path=attribute_path, value=2 + ) + assert matter_client.write_attribute.call_count == 2 + + # an unrecognized raw value should not be reported as a known state + set_node_attribute(matter_node, 2, 1361, 22, 253) + await trigger_subscription_callback( + hass, + matter_client, + data=253, + node_id=matter_node.node_id, + attribute_path=attribute_path, + ) + state = hass.states.get(entity_id) + assert state.state == "unknown" + + +@pytest.mark.parametrize("node_fixture", ["aqara_camera_hub_g350"]) +@pytest.mark.parametrize( + ("attributes", "night_vision_entity_expected"), + [ + pytest.param({}, True, id="night-vision-feature-set"), + pytest.param( + { + "2/1361/65532": 1055 + & ~int(clusters.CameraAvStreamManagement.Bitmaps.Feature.kNightVision) + }, + False, + id="night-vision-feature-unset", + ), + ], +) +async def test_camera_night_vision_discovery( + hass: HomeAssistant, + matter_node: MatterNode, + night_vision_entity_expected: bool, +) -> None: + """Test the night vision select is only discovered when its feature bit is set.""" + entity_id = "select.aqara_camera_hub_g350_night_vision" + assert (hass.states.get(entity_id) is not None) == night_vision_entity_expected + + @pytest.mark.parametrize("node_fixture", ["mock_microwave_oven"]) async def test_microwave_oven( hass: HomeAssistant,