Skip to content

Commit aa99cdb

Browse files
committed
Fix unit tests
1 parent 2a828db commit aa99cdb

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

tests/test_number.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,19 @@ async def test_number(
120120

121121
assert cluster.read_attributes.call_count == 3
122122

123-
assert entity.description == "PWM1"
123+
assert entity.fallback_name == "PWM1"
124124

125125
# test that the state is 15.0
126126
assert entity.state["state"] == 15.0
127127

128128
# test attributes
129-
assert entity.info_object.min_value == 1.0
130-
assert entity.info_object.max_value == 100.0
131-
assert entity.info_object.step == 1.1
129+
assert entity.info_object.native_min_value == 1.0
130+
assert entity.info_object.native_max_value == 100.0
131+
assert entity.info_object.native_step == 1.1
132+
assert entity.info_object.mode == NumberMode.AUTO
132133

133134
assert entity.icon == "mdi:percent"
134135
assert entity.native_unit_of_measurement == "%"
135-
assert entity.mode == NumberMode.AUTO
136136
assert entity.native_min_value == 1.0
137137
assert entity.native_max_value == 100.0
138138
assert entity.native_step == 1.1
@@ -149,7 +149,7 @@ async def test_number(
149149
assert entity.state["state"] == 20.0
150150

151151
# change value from client
152-
await entity.async_set_value(30.0)
152+
await entity.async_set_native_value(30.0)
153153
await zha_gateway.async_block_till_done()
154154

155155
assert len(cluster.write_attributes.mock_calls) == 1
@@ -241,7 +241,7 @@ async def test_level_control_number(
241241
assert entity._attr_entity_category == EntityCategory.CONFIG
242242

243243
assert entity.icon is None
244-
assert entity.description is None
244+
assert entity.fallback_name is None
245245
assert entity.native_unit_of_measurement is None
246246
assert entity.mode == NumberMode.AUTO
247247
assert entity.native_min_value == 0

zha/application/platforms/__init__.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ class BaseEntity(LogMixin, EventBase):
114114

115115
PLATFORM: Platform = Platform.UNKNOWN
116116

117-
_attr_fallback_name: str | None
118-
_attr_translation_key: str | None
119-
_attr_entity_category: EntityCategory | None
117+
_attr_fallback_name: str | None = None
118+
_attr_icon: str | None = None
119+
_attr_translation_key: str | None = None
120+
_attr_entity_category: EntityCategory | None = None
120121
_attr_entity_registry_enabled_default: bool = True
121-
_attr_device_class: str | None
122-
_attr_state_class: str | None
122+
_attr_device_class: str | None = None
123+
_attr_state_class: str | None = None
123124
_attr_enabled: bool = True
124125
_attr_always_supported: bool = False
125126
_attr_primary: bool = False
@@ -187,14 +188,12 @@ def primary_weight(self) -> int:
187188
@property
188189
def fallback_name(self) -> str | None:
189190
"""Return the entity fallback name for when a translation key is unavailable."""
190-
if hasattr(self, "_attr_fallback_name"):
191-
return self._attr_fallback_name
192-
return None
191+
return self._attr_fallback_name
193192

194193
@property
195194
def icon(self) -> str | None:
196195
"""Return the entity icon."""
197-
return None
196+
return self._attr_icon
198197

199198
@property
200199
def translation_key(self) -> str | None:
@@ -218,16 +217,12 @@ def entity_registry_enabled_default(self) -> bool:
218217
@property
219218
def device_class(self) -> str | None:
220219
"""Return the device class."""
221-
if hasattr(self, "_attr_device_class"):
222-
return self._attr_device_class
223-
return None
220+
return self._attr_device_class
224221

225222
@property
226223
def state_class(self) -> str | None:
227224
"""Return the state class."""
228-
if hasattr(self, "_attr_state_class"):
229-
return self._attr_state_class
230-
return None
225+
return self._attr_state_class
231226

232227
@final
233228
@property

0 commit comments

Comments
 (0)