mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add NightVision select for Matter camera (#189492)
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
6449759b21
commit
c236dd4fa8
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)"
|
||||
},
|
||||
|
||||
@@ -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({
|
||||
<SelectEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'off',
|
||||
'on',
|
||||
'auto',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': None,
|
||||
'device_class': None,
|
||||
'device_id': <DeviceEntry identifiers=[('matter', 'deviceid_00000000000004D2-00000000000000BB-MatterNodeDevice'), ('matter', 'serial_serial_187')]>,
|
||||
'disabled_by': None,
|
||||
'domain': 'select',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'select.aqara_camera_hub_g350_night_vision',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'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({
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Aqara Camera Hub G350 Night vision',
|
||||
<SelectEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'off',
|
||||
'on',
|
||||
'auto',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'select.aqara_camera_hub_g350_night_vision',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'auto',
|
||||
})
|
||||
# ---
|
||||
# name: test_selects[aqara_led_strip_t2][select.aqara_led_strip_t2_music_sync_effect-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user