-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved data coordinator to separate class
- Loading branch information
Showing
2 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Representation of VeSync data coordinator.""" | ||
|
||
from __future__ import annotations | ||
|
||
from datetime import timedelta | ||
import logging | ||
from typing import Any | ||
|
||
from pyvesync import VeSync | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class VeSyncDataCoordinator(DataUpdateCoordinator): | ||
"""Class representing data coordinator for VeSync devices.""" | ||
|
||
def __init__(self, hass: HomeAssistant, manager: VeSync) -> None: | ||
"""Initialize.""" | ||
self._manager = manager | ||
|
||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name="VeSyncDataCoordinator", | ||
update_interval=timedelta(seconds=30), | ||
) | ||
|
||
async def _async_update_data(self) -> dict[str, Any]: | ||
"""Fetch data from API endpoint.""" | ||
|
||
try: | ||
return await self.hass.async_add_executor_job(self._manager.update) | ||
except Exception as error: | ||
raise UpdateFailed(error) from error | ||