1 """The Keenetic Client class."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from datetime
import timedelta
9 from ndms2_client
import Client, ConnectionException, Device, TelnetConnection
10 from ndms2_client.client
import RouterInfo
30 CONF_INCLUDE_ASSOCIATED,
36 _LOGGER = logging.getLogger(__name__)
40 """Keenetic client Object."""
42 def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) ->
None:
43 """Initialize the Client."""
48 self.
_connection_connection: TelnetConnection |
None =
None
49 self.
_client_client: Client |
None =
None
57 """Read-only accessor for the client connection."""
62 """Read-only accessor for last_devices."""
67 """Return the host of this hub."""
72 """Return the host of this hub."""
74 identifiers={(DOMAIN, f
"router-{self.config_entry.entry_id}")},
76 model=self.
modelmodel,
83 """Return the name of the hub."""
88 """Return the model of the hub."""
93 """Return the firmware of the hub."""
98 """Return the firmware of the hub."""
103 """Return if the hub is connected."""
108 """Config entry option defining number of seconds from last seen to away."""
113 """Tracked interfaces."""
118 """Event specific per router entry to signal updates."""
119 return f
"keenetic-update-{self.config_entry.entry_id}"
122 """Request an update."""
133 """Update devices information."""
138 """Set up the connection."""
149 except ConnectionException
as error:
150 raise ConfigEntryNotReady
from error
152 async
def async_update_data(_now):
156 self.
config_entryconfig_entry.options[CONF_SCAN_INTERVAL],
160 await async_update_data(dt_util.utcnow())
163 """Teardown up the connection."""
177 """Get ARP from keenetic router."""
178 _LOGGER.debug(
"Fetching devices from router")
181 _response = self.
_client_client.get_devices(
182 try_hotspot=self.
config_entryconfig_entry.options[CONF_TRY_HOTSPOT],
183 include_arp=self.
config_entryconfig_entry.options[CONF_INCLUDE_ARP],
184 include_associated=self.
config_entryconfig_entry.options[CONF_INCLUDE_ASSOCIATED],
191 _LOGGER.debug(
"Successfully fetched data from router: %s",
str(_response))
195 except ConnectionException:
196 _LOGGER.error(
"Error fetching data from router")
def tracked_interfaces(self)
def _update_router_info(self)
DeviceInfo device_info(self)
None __init__(self, HomeAssistant hass, ConfigEntry config_entry)
def consider_home_interval(self)
def _update_devices(self)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)
CALLBACK_TYPE async_call_later(HomeAssistant hass, float|timedelta delay, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action)