diff --git a/tests/test_number.py b/tests/test_number.py index 658cc0d5..4f82930f 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -121,6 +121,8 @@ async def test_number( assert cluster.read_attributes.call_count == 3 assert entity.description == "PWM1" + assert entity.fallback_name == "PWM1" + assert entity.translation_key is None # test that the state is 15.0 assert entity.state["state"] == 15.0 @@ -179,6 +181,35 @@ async def test_number( assert entity.state["state"] == 30.0 +async def test_number_missing_description_attr( + zigpy_analog_output_device: ZigpyDevice, # pylint: disable=redefined-outer-name + device_joined: Callable[[ZigpyDevice], Awaitable[Device]], + zha_gateway: Gateway, +) -> None: + """Test zha number platform - missing description attribute.""" + cluster: general.AnalogOutput = zigpy_analog_output_device.endpoints.get( + 1 + ).analog_output + cluster.PLUGGED_ATTR_READS = { + "max_present_value": 100.0, + "min_present_value": 1.0, + "relinquish_default": 50.0, + "resolution": 1.1, + "engineering_units": 98, + "application_type": 4 * 0x10000, + } + update_attribute_cache(cluster) + + zha_device = await device_joined(zigpy_analog_output_device) + + entity: PlatformEntity = get_entity(zha_device, platform=Platform.NUMBER) + assert isinstance(entity, PlatformEntity) + + assert entity.description is None + assert entity.fallback_name is None + assert entity.translation_key == "number" + + @pytest.mark.parametrize( ("attr", "initial_value", "new_value", "max_value"), ( diff --git a/zha/application/platforms/binary_sensor/__init__.py b/zha/application/platforms/binary_sensor/__init__.py index c35b2b62..3e2fa333 100644 --- a/zha/application/platforms/binary_sensor/__init__.py +++ b/zha/application/platforms/binary_sensor/__init__.py @@ -77,6 +77,12 @@ def __init__( CLUSTER_HANDLER_ATTRIBUTE_UPDATED, self.handle_cluster_handler_attribute_updated, ) + if ( + hasattr(self._cluster_handler, "description") + and self._cluster_handler.description is not None + ): + self._attr_translation_key = None + self._attr_fallback_name: str = self._cluster_handler.description def _init_from_quirks_metadata(self, entity_metadata: BinarySensorMetadata) -> None: """Init this entity from the quirks metadata.""" diff --git a/zha/application/platforms/number/__init__.py b/zha/application/platforms/number/__init__.py index 6c3edec6..0cd27411 100644 --- a/zha/application/platforms/number/__init__.py +++ b/zha/application/platforms/number/__init__.py @@ -95,6 +95,14 @@ def __init__( CLUSTER_HANDLER_ATTRIBUTE_UPDATED, self.handle_cluster_handler_attribute_updated, ) + if ( + hasattr(self._analog_output_cluster_handler, "description") + and self._analog_output_cluster_handler.description is not None + ): + self._attr_translation_key = None + self._attr_fallback_name: str = ( + self._analog_output_cluster_handler.description + ) @functools.cached_property def info_object(self) -> NumberEntityInfo: diff --git a/zha/application/platforms/sensor/__init__.py b/zha/application/platforms/sensor/__init__.py index 2c807208..4e0efe9f 100644 --- a/zha/application/platforms/sensor/__init__.py +++ b/zha/application/platforms/sensor/__init__.py @@ -193,6 +193,12 @@ def __init__( CLUSTER_HANDLER_ATTRIBUTE_UPDATED, self.handle_cluster_handler_attribute_updated, ) + if ( + hasattr(self._cluster_handler, "description") + and self._cluster_handler.description is not None + ): + self._attr_translation_key = None + self._attr_fallback_name: str = self._cluster_handler.description def _init_from_quirks_metadata(self, entity_metadata: ZCLSensorMetadata) -> None: """Init this entity from the quirks metadata."""