Skip to content

Commit

Permalink
Fix number platform not having a consistent API (#66)
Browse files Browse the repository at this point in the history
* Rename `name` to `description`

* Implement `description` on the second number platform implementation

* Adjust unit test

* Test that `description` exists on other `number` entities
  • Loading branch information
puddly authored Jul 7, 2024
1 parent e03ef3b commit 101cbe6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions zha/application/platforms/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 101cbe6

Please sign in to comment.