22
33from __future__ import annotations
44
5- import logging
65from collections .abc import Callable
76from datetime import datetime , timedelta
7+ import logging
88from typing import Any
99
1010from aiosysbus import AIOSysbus
1111from aiosysbus .exceptions import AiosysbusException
12+
1213from homeassistant .config_entries import ConfigEntry
1314from homeassistant .const import CONF_HOST , CONF_PASSWORD , CONF_PORT , CONF_USERNAME
1415from homeassistant .core import HomeAssistant
3637class LiveboxDataUpdateCoordinator (DataUpdateCoordinator ):
3738 """Define an object to fetch data."""
3839
40+ unique_id : str
41+ model : int | float
42+
3943 def __init__ (
4044 self ,
4145 hass : HomeAssistant ,
@@ -44,16 +48,17 @@ def __init__(
4448 """Class to manage fetching data API."""
4549 super ().__init__ (hass , _LOGGER , name = DOMAIN , update_interval = SCAN_INTERVAL )
4650 self .config_entry = config_entry
51+
52+ async def _async_setup (self ) -> None :
53+ """Coordinator setup."""
4754 self .api = AIOSysbus (
48- username = config_entry .data [CONF_USERNAME ],
49- password = config_entry .data [CONF_PASSWORD ],
50- session = async_create_clientsession (hass ),
51- host = config_entry .data [CONF_HOST ],
52- port = config_entry .data [CONF_PORT ],
53- use_tls = config_entry .data .get (CONF_USE_TLS , False ),
55+ username = self . config_entry .data [CONF_USERNAME ],
56+ password = self . config_entry .data [CONF_PASSWORD ],
57+ session = async_create_clientsession (self . hass ),
58+ host = self . config_entry .data [CONF_HOST ],
59+ port = self . config_entry .data [CONF_PORT ],
60+ use_tls = self . config_entry .data .get (CONF_USE_TLS , False ),
5461 )
55- self .unique_id : str | None = None
56- self .model : int | float | None = None
5762
5863 async def _async_update_data (self ) -> dict [str , Any ]:
5964 """Fetch data."""
@@ -122,8 +127,7 @@ async def _async_update_data(self) -> dict[str, Any]:
122127
123128 async def async_get_infos (self ) -> dict [str , Any ]:
124129 """Get router infos."""
125- infos = (await self .api .deviceinfo .async_get_deviceinfo ()).get ("status" , {})
126- return infos
130+ return (await self .api .deviceinfo .async_get_deviceinfo ()).get ("status" , {})
127131
128132 async def async_get_devices (
129133 self , lan_tracking = False , wifi_tracking = True
@@ -166,7 +170,9 @@ async def async_get_devices(
166170
167171 return devices_tracker , device_counters
168172
169- async def async_get_callers (self ) -> tuple (list [dict [str , Any ] | None ]):
173+ async def async_get_callers (
174+ self ,
175+ ) -> tuple [list [dict [str , Any ] | None ], list [dict [str , Any ] | None ]]:
170176 """Get caller missed."""
171177 callers = []
172178 cmisseds = []
@@ -235,9 +241,9 @@ async def async_get_lan(self, lan_devices):
235241 ).get ("status" , {})
236242
237243 devices = []
238- for type , items in self_devices .items ():
244+ for mode , items in self_devices .items ():
239245 for item in items :
240- if type == "wifi" :
246+ if mode == "wifi" :
241247 intf = item .get ("Name" , "Unknown" )
242248 band = item .get ("OperatingFrequencyBand" , intf )
243249 ess_identifier = item .get ("EssIdentifier" , "guest" ).lower ()
@@ -255,7 +261,7 @@ async def async_get_lan(self, lan_devices):
255261 },
256262 }
257263 )
258- if type == "eth" :
264+ if mode == "eth" :
259265 devices .append (
260266 {
261267 "name" : item .get ("Name" , "Unknown" ),
@@ -272,10 +278,9 @@ async def async_get_lan(self, lan_devices):
272278
273279 async def async_get_wifi_stats (self ) -> bool :
274280 """Get wifi stats."""
275- stats = (await self ._make_request (self .api .nmc .async_get_wifi_stats )).get (
281+ return (await self ._make_request (self .api .nmc .async_get_wifi_stats )).get (
276282 "data" , {}
277283 )
278- return stats
279284
280285 async def async_get_fiber_stats (self ) -> bool :
281286 """Get fiber stats."""
@@ -285,22 +290,19 @@ async def async_get_fiber_stats(self) -> bool:
285290 intf = "bridge_vmulti"
286291 else :
287292 intf = "veip0"
288- stats = (
293+ return (
289294 await self ._make_request (self .api .nemo .async_get_net_dev_stats , intf )
290295 ).get ("status" , {})
291- return stats
292296
293297 async def async_get_wan_status (self ) -> dict [str , Any ]:
294298 """Get status."""
295- wan_status = (await self ._make_request (self .api .nmc .async_get_wan_status )).get (
299+ return (await self ._make_request (self .api .nmc .async_get_wan_status )).get (
296300 "data" , {}
297301 )
298- return wan_status
299302
300303 async def async_get_nmc (self ) -> dict [str , Any ]:
301304 """Get dsl status."""
302- nmc = (await self ._make_request (self .api .nmc .async_get )).get ("status" , {})
303- return nmc
305+ return (await self ._make_request (self .api .nmc .async_get )).get ("status" , {})
304306
305307 async def async_is_wifi (self ) -> bool :
306308 """Get wireless status."""
@@ -373,19 +375,17 @@ async def async_get_dhcp_leases(
373375 data = (
374376 await self ._make_request (self .api .dhcp .async_get_dhcp_leases , None , domain )
375377 ).get ("status" , {})
376- leases = []
377- for item in data .get (domain , {}).values ():
378- leases .append (
379- {
380- "IP Address" : item .get ("IPAddress" ),
381- "Mac Address" : item .get ("MACAddress" ),
382- "Name" : item .get ("FriendlyName" , "No name" ),
383- "Time (s)" : item .get ("LeaseTime" ),
384- "Enable" : item .get ("Active" ),
385- "Reserved" : item .get ("Reserved" ),
386- }
387- )
388- return leases
378+ return [
379+ {
380+ "IP Address" : item .get ("IPAddress" ),
381+ "Mac Address" : item .get ("MACAddress" ),
382+ "Name" : item .get ("FriendlyName" , "No name" ),
383+ "Time (s)" : item .get ("LeaseTime" ),
384+ "Enable" : item .get ("Active" ),
385+ "Reserved" : item .get ("Reserved" ),
386+ }
387+ for item in data .get (domain , {}).values ()
388+ ]
389389
390390 async def async_get_results (self ) -> dict [str , Any ]:
391391 """Get interfaces."""
0 commit comments