From 0b81550092ba40c54b26d2980ec095d1ad272501 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 28 Jun 2023 23:40:12 +0200 Subject: [PATCH] Fix Matter entity names (#95477) --- homeassistant/components/matter/binary_sensor.py | 4 ---- homeassistant/components/matter/cover.py | 12 ++++++++---- homeassistant/components/matter/light.py | 16 +++++++++++----- homeassistant/components/matter/lock.py | 2 +- homeassistant/components/matter/sensor.py | 8 +------- homeassistant/components/matter/strings.json | 7 +++++++ homeassistant/components/matter/switch.py | 2 +- tests/components/matter/test_binary_sensor.py | 4 ++-- 8 files changed, 31 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/matter/binary_sensor.py b/homeassistant/components/matter/binary_sensor.py index bd65b3a092577e..7c94c07c8cd87a 100644 --- a/homeassistant/components/matter/binary_sensor.py +++ b/homeassistant/components/matter/binary_sensor.py @@ -65,7 +65,6 @@ def _update_from_device(self) -> None: entity_description=MatterBinarySensorEntityDescription( key="HueMotionSensor", device_class=BinarySensorDeviceClass.MOTION, - name="Motion", measurement_to_ha=lambda x: (x & 1 == 1) if x is not None else None, ), entity_class=MatterBinarySensor, @@ -78,7 +77,6 @@ def _update_from_device(self) -> None: entity_description=MatterBinarySensorEntityDescription( key="ContactSensor", device_class=BinarySensorDeviceClass.DOOR, - name="Contact", # value is inverted on matter to what we expect measurement_to_ha=lambda x: not x, ), @@ -90,7 +88,6 @@ def _update_from_device(self) -> None: entity_description=MatterBinarySensorEntityDescription( key="OccupancySensor", device_class=BinarySensorDeviceClass.OCCUPANCY, - name="Occupancy", # The first bit = if occupied measurement_to_ha=lambda x: (x & 1 == 1) if x is not None else None, ), @@ -102,7 +99,6 @@ def _update_from_device(self) -> None: entity_description=MatterBinarySensorEntityDescription( key="BatteryChargeLevel", device_class=BinarySensorDeviceClass.BATTERY, - name="Battery Status", measurement_to_ha=lambda x: x != clusters.PowerSource.Enums.BatChargeLevelEnum.kOk, ), diff --git a/homeassistant/components/matter/cover.py b/homeassistant/components/matter/cover.py index 61c5d4cd2ff48e..590f325cf22960 100644 --- a/homeassistant/components/matter/cover.py +++ b/homeassistant/components/matter/cover.py @@ -199,7 +199,7 @@ def _update_from_device(self) -> None: DISCOVERY_SCHEMAS = [ MatterDiscoverySchema( platform=Platform.COVER, - entity_description=CoverEntityDescription(key="MatterCover"), + entity_description=CoverEntityDescription(key="MatterCover", name=None), entity_class=MatterCover, required_attributes=( clusters.WindowCovering.Attributes.OperationalStatus, @@ -212,7 +212,9 @@ def _update_from_device(self) -> None: ), MatterDiscoverySchema( platform=Platform.COVER, - entity_description=CoverEntityDescription(key="MatterCoverPositionAwareLift"), + entity_description=CoverEntityDescription( + key="MatterCoverPositionAwareLift", name=None + ), entity_class=MatterCover, required_attributes=( clusters.WindowCovering.Attributes.OperationalStatus, @@ -225,7 +227,9 @@ def _update_from_device(self) -> None: ), MatterDiscoverySchema( platform=Platform.COVER, - entity_description=CoverEntityDescription(key="MatterCoverPositionAwareTilt"), + entity_description=CoverEntityDescription( + key="MatterCoverPositionAwareTilt", name=None + ), entity_class=MatterCover, required_attributes=( clusters.WindowCovering.Attributes.OperationalStatus, @@ -239,7 +243,7 @@ def _update_from_device(self) -> None: MatterDiscoverySchema( platform=Platform.COVER, entity_description=CoverEntityDescription( - key="MatterCoverPositionAwareLiftAndTilt" + key="MatterCoverPositionAwareLiftAndTilt", name=None ), entity_class=MatterCover, required_attributes=( diff --git a/homeassistant/components/matter/light.py b/homeassistant/components/matter/light.py index 4c220ab85ea1a4..facdb6752d3b0a 100644 --- a/homeassistant/components/matter/light.py +++ b/homeassistant/components/matter/light.py @@ -358,7 +358,7 @@ def _update_from_device(self) -> None: DISCOVERY_SCHEMAS = [ MatterDiscoverySchema( platform=Platform.LIGHT, - entity_description=LightEntityDescription(key="MatterLight"), + entity_description=LightEntityDescription(key="MatterLight", name=None), entity_class=MatterLight, required_attributes=(clusters.OnOff.Attributes.OnOff,), optional_attributes=( @@ -380,7 +380,9 @@ def _update_from_device(self) -> None: # Additional schema to match (HS Color) lights with incorrect/missing device type MatterDiscoverySchema( platform=Platform.LIGHT, - entity_description=LightEntityDescription(key="MatterHSColorLightFallback"), + entity_description=LightEntityDescription( + key="MatterHSColorLightFallback", name=None + ), entity_class=MatterLight, required_attributes=( clusters.OnOff.Attributes.OnOff, @@ -398,7 +400,9 @@ def _update_from_device(self) -> None: # Additional schema to match (XY Color) lights with incorrect/missing device type MatterDiscoverySchema( platform=Platform.LIGHT, - entity_description=LightEntityDescription(key="MatterXYColorLightFallback"), + entity_description=LightEntityDescription( + key="MatterXYColorLightFallback", name=None + ), entity_class=MatterLight, required_attributes=( clusters.OnOff.Attributes.OnOff, @@ -417,7 +421,7 @@ def _update_from_device(self) -> None: MatterDiscoverySchema( platform=Platform.LIGHT, entity_description=LightEntityDescription( - key="MatterColorTemperatureLightFallback" + key="MatterColorTemperatureLightFallback", name=None ), entity_class=MatterLight, required_attributes=( @@ -430,7 +434,9 @@ def _update_from_device(self) -> None: # Additional schema to match generic dimmable lights with incorrect/missing device type MatterDiscoverySchema( platform=Platform.LIGHT, - entity_description=LightEntityDescription(key="MatterDimmableLightFallback"), + entity_description=LightEntityDescription( + key="MatterDimmableLightFallback", name=None + ), entity_class=MatterLight, required_attributes=( clusters.OnOff.Attributes.OnOff, diff --git a/homeassistant/components/matter/lock.py b/homeassistant/components/matter/lock.py index f78529b72684e1..7df6d84c79471c 100644 --- a/homeassistant/components/matter/lock.py +++ b/homeassistant/components/matter/lock.py @@ -147,7 +147,7 @@ class DoorLockFeature(IntFlag): DISCOVERY_SCHEMAS = [ MatterDiscoverySchema( platform=Platform.LOCK, - entity_description=LockEntityDescription(key="MatterLock"), + entity_description=LockEntityDescription(key="MatterLock", name=None), entity_class=MatterLock, required_attributes=(clusters.DoorLock.Attributes.LockState,), optional_attributes=(clusters.DoorLock.Attributes.DoorState,), diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index 84e68695d639e0..027dcda65a7985 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -68,7 +68,6 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="TemperatureSensor", - name="Temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, measurement_to_ha=lambda x: x / 100, @@ -80,7 +79,6 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="PressureSensor", - name="Pressure", native_unit_of_measurement=UnitOfPressure.KPA, device_class=SensorDeviceClass.PRESSURE, measurement_to_ha=lambda x: x / 10, @@ -92,9 +90,8 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="FlowSensor", - name="Flow", native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, - device_class=SensorDeviceClass.WATER, # what is the device class here ? + translation_key="flow", measurement_to_ha=lambda x: x / 10, ), entity_class=MatterSensor, @@ -104,7 +101,6 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="HumiditySensor", - name="Humidity", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.HUMIDITY, measurement_to_ha=lambda x: x / 100, @@ -118,7 +114,6 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="LightSensor", - name="Illuminance", native_unit_of_measurement=LIGHT_LUX, device_class=SensorDeviceClass.ILLUMINANCE, measurement_to_ha=lambda x: round(pow(10, ((x - 1) / 10000)), 1), @@ -130,7 +125,6 @@ def _update_from_device(self) -> None: platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="PowerSource", - name="Battery", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.BATTERY, # value has double precision diff --git a/homeassistant/components/matter/strings.json b/homeassistant/components/matter/strings.json index 594998c236f2df..dc5eb30df51a33 100644 --- a/homeassistant/components/matter/strings.json +++ b/homeassistant/components/matter/strings.json @@ -43,5 +43,12 @@ "install_addon": "Please wait while the Matter Server add-on installation finishes. This can take several minutes.", "start_addon": "Please wait while the Matter Server add-on starts. This add-on is what powers Matter in Home Assistant. This may take some seconds." } + }, + "entity": { + "sensor": { + "flow": { + "name": "Flow" + } + } } } diff --git a/homeassistant/components/matter/switch.py b/homeassistant/components/matter/switch.py index 2eb3c22c1f7a72..56c51d144d8a91 100644 --- a/homeassistant/components/matter/switch.py +++ b/homeassistant/components/matter/switch.py @@ -63,7 +63,7 @@ def _update_from_device(self) -> None: MatterDiscoverySchema( platform=Platform.SWITCH, entity_description=SwitchEntityDescription( - key="MatterPlug", device_class=SwitchDeviceClass.OUTLET + key="MatterPlug", device_class=SwitchDeviceClass.OUTLET, name=None ), entity_class=MatterSwitch, required_attributes=(clusters.OnOff.Attributes.OnOff,), diff --git a/tests/components/matter/test_binary_sensor.py b/tests/components/matter/test_binary_sensor.py index 743619ddde9aae..d7982e1d5aedd4 100644 --- a/tests/components/matter/test_binary_sensor.py +++ b/tests/components/matter/test_binary_sensor.py @@ -31,7 +31,7 @@ async def test_contact_sensor( contact_sensor_node: MatterNode, ) -> None: """Test contact sensor.""" - state = hass.states.get("binary_sensor.mock_contact_sensor_contact") + state = hass.states.get("binary_sensor.mock_contact_sensor_door") assert state assert state.state == "off" @@ -40,7 +40,7 @@ async def test_contact_sensor( hass, matter_client, data=(contact_sensor_node.node_id, "1/69/0", False) ) - state = hass.states.get("binary_sensor.mock_contact_sensor_contact") + state = hass.states.get("binary_sensor.mock_contact_sensor_door") assert state assert state.state == "on"