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>
This commit is contained in:
parent
dfd3476cff
commit
d49a223a02
1 changed files with 6 additions and 4 deletions
|
@ -215,10 +215,12 @@ class AmcrestBinarySensor(BinarySensorEntity):
|
||||||
raise ValueError(f"Binary sensor {self.name} event codes not set")
|
raise ValueError(f"Binary sensor {self.name} event codes not set")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._attr_is_on = any( # type: ignore[arg-type]
|
for event_code in event_codes:
|
||||||
len(await self._api.async_event_channels_happened(event_code)) > 0
|
if await self._api.async_event_channels_happened(event_code):
|
||||||
for event_code in event_codes
|
self._attr_is_on = True
|
||||||
)
|
break
|
||||||
|
else:
|
||||||
|
self._attr_is_on = False
|
||||||
except AmcrestError as error:
|
except AmcrestError as error:
|
||||||
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
|
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue