forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move venstar coordinator to separate module (home-assistant#117500)
- Loading branch information
Showing
7 changed files
with
85 additions
and
74 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
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,75 @@ | ||
"""Coordinator for the venstar component.""" | ||
|
||
from __future__ import annotations | ||
|
||
import asyncio | ||
from datetime import timedelta | ||
|
||
from requests import RequestException | ||
from venstarcolortouch import VenstarColorTouch | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import update_coordinator | ||
|
||
from .const import _LOGGER, DOMAIN, VENSTAR_SLEEP | ||
|
||
|
||
class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator[None]): | ||
"""Class to manage fetching Venstar data.""" | ||
|
||
def __init__( | ||
self, | ||
hass: HomeAssistant, | ||
*, | ||
venstar_connection: VenstarColorTouch, | ||
) -> None: | ||
"""Initialize global Venstar data updater.""" | ||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name=DOMAIN, | ||
update_interval=timedelta(seconds=60), | ||
) | ||
self.client = venstar_connection | ||
self.runtimes: list[dict[str, int]] = [] | ||
|
||
async def _async_update_data(self) -> None: | ||
"""Update the state.""" | ||
try: | ||
await self.hass.async_add_executor_job(self.client.update_info) | ||
except (OSError, RequestException) as ex: | ||
raise update_coordinator.UpdateFailed( | ||
f"Exception during Venstar info update: {ex}" | ||
) from ex | ||
|
||
# older venstars sometimes cannot handle rapid sequential connections | ||
await asyncio.sleep(VENSTAR_SLEEP) | ||
|
||
try: | ||
await self.hass.async_add_executor_job(self.client.update_sensors) | ||
except (OSError, RequestException) as ex: | ||
raise update_coordinator.UpdateFailed( | ||
f"Exception during Venstar sensor update: {ex}" | ||
) from ex | ||
|
||
# older venstars sometimes cannot handle rapid sequential connections | ||
await asyncio.sleep(VENSTAR_SLEEP) | ||
|
||
try: | ||
await self.hass.async_add_executor_job(self.client.update_alerts) | ||
except (OSError, RequestException) as ex: | ||
raise update_coordinator.UpdateFailed( | ||
f"Exception during Venstar alert update: {ex}" | ||
) from ex | ||
|
||
# older venstars sometimes cannot handle rapid sequential connections | ||
await asyncio.sleep(VENSTAR_SLEEP) | ||
|
||
try: | ||
self.runtimes = await self.hass.async_add_executor_job( | ||
self.client.get_runtimes | ||
) | ||
except (OSError, RequestException) as ex: | ||
raise update_coordinator.UpdateFailed( | ||
f"Exception during Venstar runtime update: {ex}" | ||
) from ex |
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
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