-
-
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.
Rympro integration code fixes (#86734)
* Address review comments * Add coordinator.py to coveragerc * Apply suggestions from code review Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> * Update homeassistant/components/rympro/coordinator.py Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> * Move SCAN_INTERVAL to coordinator.py --------- Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
87 additions
and
51 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
Validating CODEOWNERS rules …
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,42 @@ | ||
"""The Read Your Meter Pro integration.""" | ||
from __future__ import annotations | ||
|
||
from datetime import timedelta | ||
import logging | ||
|
||
from pyrympro import CannotConnectError, OperationError, RymPro, UnauthorizedError | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
|
||
from .const import DOMAIN | ||
|
||
SCAN_INTERVAL = 60 * 60 | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class RymProDataUpdateCoordinator(DataUpdateCoordinator[dict[int, dict]]): | ||
"""Class to manage fetching RYM Pro data.""" | ||
|
||
def __init__(self, hass: HomeAssistant, rympro: RymPro) -> None: | ||
"""Initialize global RymPro data updater.""" | ||
self.rympro = rympro | ||
interval = timedelta(seconds=SCAN_INTERVAL) | ||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name=DOMAIN, | ||
update_interval=interval, | ||
) | ||
|
||
async def _async_update_data(self) -> dict[int, dict]: | ||
"""Fetch data from Rym Pro.""" | ||
try: | ||
return await self.rympro.last_read() | ||
except UnauthorizedError as error: | ||
assert self.config_entry | ||
await self.hass.config_entries.async_reload(self.config_entry.entry_id) | ||
raise UpdateFailed(error) from error | ||
except (CannotConnectError, OperationError) as error: | ||
raise UpdateFailed(error) from error |
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