Add type annotations to init and coordinator. Minor cleanups. (#52506)

This commit is contained in:
RenierM26 2021-07-06 14:55:34 +02:00 committed by GitHub
parent 4d32e1ed01
commit 12082736a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 19 deletions

View file

@ -3,8 +3,10 @@ from datetime import timedelta
import logging
from async_timeout import timeout
from pyezviz.client import EzvizClient
from pyezviz.exceptions import HTTPError, InvalidURL, PyEzvizError
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DOMAIN
@ -15,23 +17,24 @@ _LOGGER = logging.getLogger(__name__)
class EzvizDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching Ezviz data."""
def __init__(self, hass, *, api):
def __init__(
self, hass: HomeAssistant, *, api: EzvizClient, api_timeout: int
) -> None:
"""Initialize global Ezviz data updater."""
self.ezviz_client = api
self._api_timeout = api_timeout
update_interval = timedelta(seconds=30)
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)
def _update_data(self):
def _update_data(self) -> dict:
"""Fetch data from Ezviz via camera load function."""
cameras = self.ezviz_client.load_cameras()
return self.ezviz_client.load_cameras()
return cameras
async def _async_update_data(self):
async def _async_update_data(self) -> dict:
"""Fetch data from Ezviz."""
try:
async with timeout(35):
async with timeout(self._api_timeout):
return await self.hass.async_add_executor_job(self._update_data)
except (InvalidURL, HTTPError, PyEzvizError) as error: