Skip to content

Commit bde095d

Browse files
committed
Fix lint
1 parent 5110737 commit bde095d

File tree

10 files changed

+2128
-114
lines changed

10 files changed

+2128
-114
lines changed

custom_components/livebox/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44

55
import voluptuous as vol
6-
76
from homeassistant.config_entries import ConfigEntry
87
from homeassistant.core import HomeAssistant
98
from homeassistant.helpers import device_registry as dr
@@ -51,9 +50,7 @@ async def _async_update_listener(hass: HomeAssistant, entry: LiveboxConfigEntry)
5150

5251

5352
async def async_remove_config_entry_device(
54-
hass: HomeAssistant, # pylint: disable=unused-argument
55-
config_entry: ConfigEntry, # pylint: disable=unused-argument
56-
device_entry: dr.DeviceEntry, # pylint: disable=unused-argument
53+
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
5754
) -> bool:
5855
"""Remove config entry from a device."""
5956
return True

custom_components/livebox/binary_sensor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import logging
65
from collections.abc import Callable
76
from dataclasses import dataclass
87
from datetime import datetime, timedelta
@@ -13,8 +12,8 @@
1312
BinarySensorEntity,
1413
BinarySensorEntityDescription,
1514
)
15+
from homeassistant.const import EntityCategory
1616
from homeassistant.core import HomeAssistant
17-
from homeassistant.helpers.entity import EntityCategory
1817
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1918

2019
from . import LiveboxConfigEntry
@@ -23,15 +22,13 @@
2322
from .entity import LiveboxEntity
2423
from .helpers import find_item
2524

26-
_LOGGER = logging.getLogger(__name__)
2725

28-
29-
@dataclass(frozen=True)
26+
@dataclass(frozen=True, kw_only=True)
3027
class LiveboxBinarySensorEntityDescription(BinarySensorEntityDescription):
3128
"""Represents an Flow Sensor."""
3229

33-
value_fn: Callable[..., Any] | None = None
34-
attrs: dict[str, Callable[..., Any]] | None = None
30+
value_fn: Callable[..., Any]
31+
attrs: dict[str, Callable[..., Any]]
3532
index: int | None = None
3633

3734

@@ -111,6 +108,8 @@ async def async_setup_entry(
111108
class LiveboxBinarySensor(LiveboxEntity, BinarySensorEntity):
112109
"""Livebox binary sensor."""
113110

111+
entity_description: LiveboxBinarySensorEntityDescription
112+
114113
def __init__(
115114
self,
116115
coordinator: LiveboxDataUpdateCoordinator,

custom_components/livebox/button.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import logging
65
from collections.abc import Callable
76
from dataclasses import dataclass
87
from typing import Any, Final
@@ -16,14 +15,12 @@
1615
from .coordinator import LiveboxDataUpdateCoordinator
1716
from .entity import LiveboxEntity
1817

19-
_LOGGER = logging.getLogger(__name__)
2018

21-
22-
@dataclass(frozen=True)
19+
@dataclass(frozen=True, kw_only=True)
2320
class LiveboxButtonEntityDescription(ButtonEntityDescription):
2421
"""Class describing Livebox button entities."""
2522

26-
value_fn: Callable[..., Any] | None = None
23+
value_fn: Callable[..., Any]
2724

2825

2926
BUTTON_TYPES: Final[tuple[ButtonEntityDescription, ...]] = (
@@ -32,21 +29,21 @@ class LiveboxButtonEntityDescription(ButtonEntityDescription):
3229
name="Livebox restart",
3330
icon=RESTART_ICON,
3431
translation_key="restart_btn",
35-
value_fn=lambda x: getattr(getattr(x, "nmc"), "async_reboot"),
32+
value_fn=lambda x: x.nmc.async_reboot,
3633
),
3734
LiveboxButtonEntityDescription(
3835
key="ring",
3936
name="Ring your phone",
4037
icon=RING_ICON,
4138
translation_key="ring_btn",
42-
value_fn=lambda x: getattr(getattr(x, "voiceservice"), "async_ring"),
39+
value_fn=lambda x: x.voiceservice.async_ring,
4340
),
4441
LiveboxButtonEntityDescription(
4542
key="clear_calls",
4643
name="Clear calls",
4744
icon=CLEARCALLS_ICON,
4845
translation_key="cmissed_clear_btn",
49-
value_fn=lambda x: getattr(getattr(x, "voiceservice"), "async_clear_calllist"),
46+
value_fn=lambda x: x.voiceservice.async_clear_calllist,
5047
),
5148
)
5249

@@ -66,14 +63,15 @@ class Button(LiveboxEntity, ButtonEntity):
6663
"""Representation of a livebox button."""
6764

6865
_attr_should_poll = False
66+
entity_description: LiveboxButtonEntityDescription
6967

7068
def __init__(
7169
self,
7270
coordinator: LiveboxDataUpdateCoordinator,
73-
entity_description: LiveboxButtonEntityDescription,
71+
description: LiveboxButtonEntityDescription,
7472
) -> None:
7573
"""Initialize."""
76-
super().__init__(coordinator, entity_description)
74+
super().__init__(coordinator, description)
7775

7876
async def async_press(self) -> None:
7977
"""Triggers the button press service."""

custom_components/livebox/config_flow.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
from __future__ import annotations
44

5-
import logging
65
from collections.abc import Mapping
6+
import logging
77
from typing import Any
88

9-
import voluptuous as vol
109
from aiosysbus import AIOSysbus
1110
from aiosysbus.exceptions import (
1211
AiosysbusException,
@@ -15,11 +14,12 @@
1514
InsufficientPermissionsError,
1615
RetrieveFailed,
1716
)
17+
import voluptuous as vol
18+
1819
from homeassistant import config_entries
19-
from homeassistant.config_entries import ConfigEntry
20+
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
2021
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
2122
from homeassistant.core import callback
22-
from homeassistant.data_entry_flow import FlowResult
2323
from homeassistant.helpers import config_validation as cv
2424
from homeassistant.helpers.aiohttp_client import async_create_clientsession
2525
from homeassistant.helpers.service_info.ssdp import ATTR_UPNP_SERIAL, SsdpServiceInfo
@@ -66,13 +66,13 @@ def async_get_options_flow(config_entry: ConfigEntry):
6666
"""Get option flow."""
6767
return LiveboxOptionsFlowHandler()
6868

69-
async def async_step_import(self, import_config) -> FlowResult:
69+
async def async_step_import(self, import_config) -> ConfigFlowResult:
7070
"""Import a config entry from configuration.yaml."""
7171
return await self.async_step_user(import_config)
7272

7373
async def async_step_user(
7474
self, user_input: Mapping[str, Any] | None = None
75-
) -> FlowResult:
75+
) -> ConfigFlowResult:
7676
"""Handle a flow initialized by the user."""
7777
errors = {}
7878
if user_input:
@@ -122,7 +122,9 @@ async def async_step_user(
122122
step_id="user", data_schema=DATA_SCHEMA, errors=errors
123123
)
124124

125-
async def async_step_ssdp(self, discovery_info: SsdpServiceInfo) -> FlowResult:
125+
async def async_step_ssdp(
126+
self, discovery_info: SsdpServiceInfo
127+
) -> ConfigFlowResult:
126128
"""Handle a discovered device."""
127129
unique_id = discovery_info.upnp[ATTR_UPNP_SERIAL]
128130
await self.async_set_unique_id(unique_id)
@@ -135,7 +137,7 @@ class LiveboxOptionsFlowHandler(config_entries.OptionsFlow):
135137

136138
async def async_step_init(
137139
self, user_input: Mapping[str, Any] | None = None
138-
) -> FlowResult:
140+
) -> ConfigFlowResult:
139141
"""Handle a flow initialized by the user."""
140142
if user_input:
141143
return self.async_create_entry(title="", data=user_input)

custom_components/livebox/coordinator.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from __future__ import annotations
44

5-
import logging
65
from collections.abc import Callable
76
from datetime import datetime, timedelta
7+
import logging
88
from typing import Any
99

1010
from aiosysbus import AIOSysbus
1111
from aiosysbus.exceptions import AiosysbusException
12+
1213
from homeassistant.config_entries import ConfigEntry
1314
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
1415
from homeassistant.core import HomeAssistant
@@ -36,6 +37,9 @@
3637
class 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

Comments
 (0)