Skip to content

Commit 3479ce8

Browse files
committed
update sensor test
1 parent 35e0c85 commit 3479ce8

File tree

2 files changed

+33
-48
lines changed

2 files changed

+33
-48
lines changed

tests/test_sensor.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,42 @@ async def async_test_metering(
143143
assert entity.state["status"] == "NO_ALARMS"
144144
assert entity.state["device_type"] == "Electric Metering"
145145

146-
# these tests change the device type of the device... this is not possible in the real world
147-
# there is no way to currently send info_object changes to the client side so this is not
148-
# possible to test for now
149-
if not isinstance(entity, sensor.WebSocketClientSensorEntity):
150-
await send_attributes_report(
151-
zha_gateway, cluster, {1024: 12346, "status": 64 + 8}
152-
)
153-
assert_state(entity, 12346.0, None)
154-
assert entity.state["status"] in (
155-
"SERVICE_DISCONNECT|POWER_FAILURE",
156-
"POWER_FAILURE|SERVICE_DISCONNECT",
157-
)
146+
await send_attributes_report(zha_gateway, cluster, {1024: 12346, "status": 64 + 8})
147+
assert_state(entity, 12346.0, None)
148+
assert entity.state["status"] in (
149+
"SERVICE_DISCONNECT|POWER_FAILURE",
150+
"POWER_FAILURE|SERVICE_DISCONNECT",
151+
)
158152

159-
await send_attributes_report(
160-
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 1}
161-
)
162-
assert entity.state["status"] in (
163-
"SERVICE_DISCONNECT|NOT_DEFINED",
164-
"NOT_DEFINED|SERVICE_DISCONNECT",
165-
)
153+
await send_attributes_report(
154+
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 1}
155+
)
156+
assert entity.state["status"] in (
157+
"SERVICE_DISCONNECT|NOT_DEFINED",
158+
"NOT_DEFINED|SERVICE_DISCONNECT",
159+
)
166160

167-
await send_attributes_report(
168-
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 2}
169-
)
170-
assert entity.state["status"] in (
171-
"SERVICE_DISCONNECT|PIPE_EMPTY",
172-
"PIPE_EMPTY|SERVICE_DISCONNECT",
173-
)
161+
await send_attributes_report(
162+
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 2}
163+
)
164+
assert entity.state["status"] in (
165+
"SERVICE_DISCONNECT|PIPE_EMPTY",
166+
"PIPE_EMPTY|SERVICE_DISCONNECT",
167+
)
174168

175-
await send_attributes_report(
176-
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 5}
177-
)
178-
assert entity.state["status"] in (
179-
"SERVICE_DISCONNECT|TEMPERATURE_SENSOR",
180-
"TEMPERATURE_SENSOR|SERVICE_DISCONNECT",
181-
)
169+
await send_attributes_report(
170+
zha_gateway, cluster, {"status": 64 + 8, "metering_device_type": 5}
171+
)
172+
assert entity.state["status"] in (
173+
"SERVICE_DISCONNECT|TEMPERATURE_SENSOR",
174+
"TEMPERATURE_SENSOR|SERVICE_DISCONNECT",
175+
)
182176

183-
# Status for other meter types
184-
await send_attributes_report(
185-
zha_gateway, cluster, {"status": 32, "metering_device_type": 4}
186-
)
187-
assert entity.state["status"] in ("<bitmap8.32: 32>", "32")
177+
# Status for other meter types
178+
await send_attributes_report(
179+
zha_gateway, cluster, {"status": 32, "metering_device_type": 4}
180+
)
181+
assert entity.state["status"] in ("<bitmap8.32: 32>", "32")
188182

189183

190184
async def async_test_smart_energy_summation_delivered(

zha/application/platforms/sensor/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,7 @@ def handle_cluster_handler_attribute_updated(
246246
event: ClusterAttributeUpdatedEvent, # pylint: disable=unused-argument
247247
) -> None:
248248
"""Handle attribute updates from the cluster handler."""
249-
if (
250-
event.attribute_name == self._attribute_name
251-
or (
252-
hasattr(self, "_attr_extra_state_attribute_names")
253-
and event.attribute_name
254-
in getattr(self, "_attr_extra_state_attribute_names")
255-
)
256-
or self._attribute_name is None
257-
):
258-
self.maybe_emit_state_changed_event()
249+
self.maybe_emit_state_changed_event()
259250

260251
def formatter(
261252
self, value: int | enum.IntEnum

0 commit comments

Comments
 (0)