Set an appropriate SCAN_INTERVAL for Broadlink A1 sensor (#41309)

This commit is contained in:
Felipe Martins Diel 2020-11-10 06:02:37 -03:00 committed by GitHub
parent 1fba245ff1
commit 2b83af856f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,8 @@ class BroadlinkUpdateManager(ABC):
monitor device availability. monitor device availability.
""" """
SCAN_INTERVAL = timedelta(minutes=1)
def __init__(self, device): def __init__(self, device):
"""Initialize the update manager.""" """Initialize the update manager."""
self.device = device self.device = device
@ -52,7 +54,7 @@ class BroadlinkUpdateManager(ABC):
_LOGGER, _LOGGER,
name=f"{device.name} ({device.api.model} at {device.api.host[0]})", name=f"{device.name} ({device.api.model} at {device.api.host[0]})",
update_method=self.async_update, update_method=self.async_update,
update_interval=timedelta(minutes=1), update_interval=self.SCAN_INTERVAL,
) )
self.available = None self.available = None
self.last_update = None self.last_update = None
@ -64,7 +66,7 @@ class BroadlinkUpdateManager(ABC):
except (BroadlinkException, OSError) as err: except (BroadlinkException, OSError) as err:
if self.available and ( if self.available and (
dt.utcnow() - self.last_update > timedelta(minutes=3) dt.utcnow() - self.last_update > self.SCAN_INTERVAL * 3
or isinstance(err, (AuthorizationError, OSError)) or isinstance(err, (AuthorizationError, OSError))
): ):
self.available = False self.available = False
@ -96,6 +98,8 @@ class BroadlinkUpdateManager(ABC):
class BroadlinkA1UpdateManager(BroadlinkUpdateManager): class BroadlinkA1UpdateManager(BroadlinkUpdateManager):
"""Manages updates for Broadlink A1 devices.""" """Manages updates for Broadlink A1 devices."""
SCAN_INTERVAL = timedelta(seconds=10)
async def async_fetch_data(self): async def async_fetch_data(self):
"""Fetch data from the device.""" """Fetch data from the device."""
return await self.device.async_request(self.device.api.check_sensors_raw) return await self.device.async_request(self.device.api.check_sensors_raw)