Skip to content

Commit ecb2b9b

Browse files
authored
Remove redundant "number" translation key and description (#444)
* Remove `hasattr` check in `AnalogOutputNumber` * Move `description` in `on_add` to `AnalogInputSensor` Also removes `hasattr` check * Remove redundant "number" translation key * Adjust number to be similar to sensor platform * Remove redundant code from `on_add` * Expect number platform having no default translation key * Regenerate diagnostics
1 parent 758d8b1 commit ecb2b9b

File tree

6 files changed

+7
-24
lines changed

6 files changed

+7
-24
lines changed

tests/data/devices/isilentllc-dog-feeder.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@
11251125
"migrate_unique_ids": [],
11261126
"platform": "number",
11271127
"class_name": "AnalogOutputNumber",
1128-
"translation_key": "number",
1128+
"translation_key": null,
11291129
"device_class": null,
11301130
"state_class": null,
11311131
"entity_category": null,

tests/data/devices/isilentllc-masterbed-light-controller.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@
16531653
"migrate_unique_ids": [],
16541654
"platform": "number",
16551655
"class_name": "AnalogOutputNumber",
1656-
"translation_key": "number",
1656+
"translation_key": null,
16571657
"device_class": null,
16581658
"state_class": null,
16591659
"entity_category": null,
@@ -1708,7 +1708,7 @@
17081708
"migrate_unique_ids": [],
17091709
"platform": "number",
17101710
"class_name": "AnalogOutputNumber",
1711-
"translation_key": "number",
1711+
"translation_key": null,
17121712
"device_class": null,
17131713
"state_class": null,
17141714
"entity_category": null,

tests/test_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def test_number_missing_description_attr(
204204
assert isinstance(entity, PlatformEntity)
205205

206206
assert entity.fallback_name is None
207-
assert entity.translation_key == "number"
207+
assert entity.translation_key is None
208208

209209

210210
@pytest.mark.parametrize(

tests/test_registries.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from zha.application.const import ATTR_QUIRK_ID
1414
from zha.application.platforms import PlatformEntity
1515
from zha.application.platforms.binary_sensor import BinaryInputWithDescription, IASZone
16+
from zha.application.platforms.number import AnalogOutputNumber
1617
from zha.application.platforms.sensor import AnalogInputSensor
1718
from zha.application.registries import (
1819
PLATFORM_ENTITIES,
@@ -578,4 +579,5 @@ def test_entity_names() -> None:
578579
IASZone,
579580
BinaryInputWithDescription,
580581
AnalogInputSensor,
582+
AnalogOutputNumber,
581583
)

zha/application/platforms/number/__init__.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ async def async_set_native_value(self, value: float) -> None:
126126
class AnalogOutputNumber(BaseNumber):
127127
"""Representation of a ZHA Number entity."""
128128

129-
_attr_translation_key: str = "number"
130-
131129
def __init__(
132130
self,
133131
cluster_handlers: list[ClusterHandler],
@@ -158,10 +156,7 @@ def recompute_capabilities(self) -> None:
158156
else:
159157
self._attr_icon = None
160158

161-
if analog_output.description is not None:
162-
self._attr_fallback_name = analog_output.description
163-
else:
164-
self._attr_fallback_name = None
159+
self._attr_fallback_name = analog_output.description
165160

166161
def on_add(self) -> None:
167162
"""Run when entity is added."""
@@ -172,14 +167,6 @@ def on_add(self) -> None:
172167
self.handle_cluster_handler_attribute_updated,
173168
)
174169
)
175-
if (
176-
hasattr(self._analog_output_cluster_handler, "description")
177-
and self._analog_output_cluster_handler.description is not None
178-
):
179-
self._attr_translation_key = None
180-
self._attr_fallback_name: str = (
181-
self._analog_output_cluster_handler.description
182-
)
183170

184171
@property
185172
def native_value(self) -> float | None:

zha/application/platforms/sensor/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ def on_add(self) -> None:
202202
self.handle_cluster_handler_attribute_updated,
203203
)
204204
)
205-
if (
206-
hasattr(self._cluster_handler, "description")
207-
and self._cluster_handler.description is not None
208-
):
209-
self._attr_translation_key = None
210-
self._attr_fallback_name: str = self._cluster_handler.description
211205

212206
def _is_supported(self) -> bool:
213207
if (

0 commit comments

Comments
 (0)