From d49a223a0236e2335983798a17d063da192a720b Mon Sep 17 00:00:00 2001 From: Sean Vig Date: Mon, 17 Oct 2022 04:13:11 -0400 Subject: [PATCH] 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 Co-authored-by: Martin Hjelmare --- homeassistant/components/amcrest/binary_sensor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/amcrest/binary_sensor.py b/homeassistant/components/amcrest/binary_sensor.py index 4d438c7c3bf..e71a5cda538 100644 --- a/homeassistant/components/amcrest/binary_sensor.py +++ b/homeassistant/components/amcrest/binary_sensor.py @@ -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