2023-09-02 19:00:33 +00:00
|
|
|
"""Utility functions for the Reolink component."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
|
|
from . import ReolinkData
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
2023-09-11 16:03:22 +00:00
|
|
|
def is_connected(hass: HomeAssistant, config_entry: config_entries.ConfigEntry) -> bool:
|
|
|
|
"""Check if an existing entry has a proper connection."""
|
2023-09-02 19:00:33 +00:00
|
|
|
reolink_data: ReolinkData | None = hass.data.get(DOMAIN, {}).get(
|
|
|
|
config_entry.entry_id
|
|
|
|
)
|
2023-09-11 16:03:22 +00:00
|
|
|
return (
|
2023-09-02 19:00:33 +00:00
|
|
|
reolink_data is not None
|
|
|
|
and config_entry.state == config_entries.ConfigEntryState.LOADED
|
|
|
|
and reolink_data.device_coordinator.last_update_success
|
|
|
|
)
|