1 """The Vilfo Router integration."""
3 from datetime
import timedelta
6 from vilfo
import Client
as VilfoClient
7 from vilfo.exceptions
import VilfoException
15 from .const
import ATTR_BOOT_TIME, ATTR_LOAD, DOMAIN, ROUTER_DEFAULT_HOST
17 PLATFORMS = [Platform.SENSOR]
21 _LOGGER = logging.getLogger(__name__)
25 """Set up Vilfo Router from a config entry."""
26 host = entry.data[CONF_HOST]
27 access_token = entry.data[CONF_ACCESS_TOKEN]
31 await vilfo_router.async_update()
33 if not vilfo_router.available:
34 raise ConfigEntryNotReady
36 hass.data.setdefault(DOMAIN, {})
37 hass.data[DOMAIN][entry.entry_id] = vilfo_router
39 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
45 """Unload a config entry."""
46 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
48 hass.data[DOMAIN].pop(entry.entry_id)
54 """Define an object to hold sensor data."""
58 self.
_vilfo_vilfo = VilfoClient(host, access_token)
69 """Get the unique_id for the Vilfo Router."""
73 if self.
hosthost == ROUTER_DEFAULT_HOST:
79 board_information = self.
_vilfo_vilfo.get_board_information()
80 load = self.
_vilfo_vilfo.get_load()
83 "board_information": board_information,
87 @Throttle(DEFAULT_SCAN_INTERVAL)
89 """Update data using calls to VilfoClient library."""
91 data = await self.
hasshass.async_add_executor_job(self.
_fetch_data_fetch_data)
94 self.
datadata[ATTR_BOOT_TIME] = data[
"board_information"][
"bootTime"]
95 self.
datadata[ATTR_LOAD] = data[
"load"]
98 except VilfoException
as error:
101 "Could not fetch data from %s, error: %s", self.
hosthost, error
108 _LOGGER.warning(
"Vilfo Router %s is available again", self.
hosthost)
def __init__(self, hass, host, access_token)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)