Fix updating Amcrest binary sensors (#80365)
* Fix updating Amcrest binary sensors As detailed in https://bugs.python.org/issue32113, a generator expression cannot be used with asynchronous components, even that the resulting elements of the generator are normal objects. Manually iterate over the event codes and check if the events have happened. Escape early on the first event that is triggered such that this is functionally equivalent to using `any`. * Update homeassistant/components/amcrest/binary_sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/80691/head
parent
a0eade7632
commit
df75346dca
|
@ -215,10 +215,12 @@ class AmcrestBinarySensor(BinarySensorEntity):
|
|||
raise ValueError(f"Binary sensor {self.name} event codes not set")
|
||||
|
||||
try:
|
||||
self._attr_is_on = any( # type: ignore[arg-type]
|
||||
len(await self._api.async_event_channels_happened(event_code)) > 0
|
||||
for event_code in event_codes
|
||||
)
|
||||
for event_code in event_codes:
|
||||
if await self._api.async_event_channels_happened(event_code):
|
||||
self._attr_is_on = True
|
||||
break
|
||||
else:
|
||||
self._attr_is_on = False
|
||||
except AmcrestError as error:
|
||||
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue