mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use coordinator setup method in yale_smart_alarm (#123819)
This commit is contained in:
parent
1ddc723274
commit
dc2886d9b1
@ -6,7 +6,6 @@ from homeassistant.components.lock import CONF_DEFAULT_CODE, DOMAIN as LOCK_DOMA
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_CODE
|
from homeassistant.const import CONF_CODE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .const import LOGGER, PLATFORMS
|
from .const import LOGGER, PLATFORMS
|
||||||
@ -19,9 +18,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool
|
|||||||
"""Set up Yale from a config entry."""
|
"""Set up Yale from a config entry."""
|
||||||
|
|
||||||
coordinator = YaleDataUpdateCoordinator(hass, entry)
|
coordinator = YaleDataUpdateCoordinator(hass, entry)
|
||||||
if not await hass.async_add_executor_job(coordinator.get_updates):
|
|
||||||
raise ConfigEntryAuthFailed
|
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
|
@ -20,10 +20,11 @@ from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, LOGGER, YALE_BASE_ERRORS
|
|||||||
class YaleDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class YaleDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""A Yale Data Update Coordinator."""
|
"""A Yale Data Update Coordinator."""
|
||||||
|
|
||||||
|
yale: YaleSmartAlarmClient
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Initialize the Yale hub."""
|
"""Initialize the Yale hub."""
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
self.yale: YaleSmartAlarmClient | None = None
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
@ -32,6 +33,17 @@ class YaleDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
always_update=False,
|
always_update=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def _async_setup(self) -> None:
|
||||||
|
"""Set up connection to Yale."""
|
||||||
|
try:
|
||||||
|
self.yale = YaleSmartAlarmClient(
|
||||||
|
self.entry.data[CONF_USERNAME], self.entry.data[CONF_PASSWORD]
|
||||||
|
)
|
||||||
|
except AuthenticationError as error:
|
||||||
|
raise ConfigEntryAuthFailed from error
|
||||||
|
except YALE_BASE_ERRORS as error:
|
||||||
|
raise UpdateFailed from error
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict[str, Any]:
|
async def _async_update_data(self) -> dict[str, Any]:
|
||||||
"""Fetch data from Yale."""
|
"""Fetch data from Yale."""
|
||||||
|
|
||||||
@ -132,17 +144,6 @@ class YaleDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
|
|
||||||
def get_updates(self) -> dict[str, Any]:
|
def get_updates(self) -> dict[str, Any]:
|
||||||
"""Fetch data from Yale."""
|
"""Fetch data from Yale."""
|
||||||
|
|
||||||
if self.yale is None:
|
|
||||||
try:
|
|
||||||
self.yale = YaleSmartAlarmClient(
|
|
||||||
self.entry.data[CONF_USERNAME], self.entry.data[CONF_PASSWORD]
|
|
||||||
)
|
|
||||||
except AuthenticationError as error:
|
|
||||||
raise ConfigEntryAuthFailed from error
|
|
||||||
except YALE_BASE_ERRORS as error:
|
|
||||||
raise UpdateFailed from error
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
arm_status = self.yale.get_armed_status()
|
arm_status = self.yale.get_armed_status()
|
||||||
data = self.yale.get_all()
|
data = self.yale.get_all()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user