From 101cbe66c93ce3bb5a7aec8175601c3a2b782447 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:52:30 -0400 Subject: [PATCH] Fix `number` platform not having a consistent API (#66) * Rename `name` to `description` * Implement `description` on the second number platform implementation * Adjust unit test * Test that `description` exists on other `number` entities --- tests/test_number.py | 3 ++- zha/application/platforms/number/__init__.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_number.py b/tests/test_number.py index ff3a5b5f6..87b3fac98 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -102,7 +102,7 @@ async def test_number( assert cluster.read_attributes.call_count == 3 - assert entity.name == "PWM1" + assert entity.description == "PWM1" # test that the state is 15.0 assert entity.state["state"] == 15.0 @@ -224,6 +224,7 @@ async def test_level_control_number( assert entity._attr_entity_category == EntityCategory.CONFIG assert entity.icon is None + assert entity.description is None assert entity.native_unit_of_measurement is None assert entity.mode == NumberMode.AUTO assert entity.native_min_value == 0 diff --git a/zha/application/platforms/number/__init__.py b/zha/application/platforms/number/__init__.py index 8ef3a1f1f..7759d01d5 100644 --- a/zha/application/platforms/number/__init__.py +++ b/zha/application/platforms/number/__init__.py @@ -142,8 +142,8 @@ def native_step(self) -> float | None: return self._analog_output_cluster_handler.resolution @functools.cached_property - def name(self) -> str | None: - """Return the name of the number entity.""" + def description(self) -> str | None: + """Return the description of the number entity.""" description = self._analog_output_cluster_handler.description if not description: return None @@ -311,6 +311,12 @@ def native_step(self) -> float | None: """Return the value step.""" return self._attr_native_step + @functools.cached_property + def description(self) -> str | None: + """Return the description of the number entity.""" + # To maintain parity with `Number` + return None + @functools.cached_property def native_unit_of_measurement(self) -> str | None: """Return the unit the value is expressed in."""