Enable strict typing for Fritz (#50668)

Co-authored-by: Ruslan Sayfutdinov <ruslan@sayfutdinov.com>
This commit is contained in:
Simone Chemelli 2021-07-06 15:06:32 +02:00 committed by GitHub
parent 12082736a8
commit a70dae0843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 17 deletions

View File

@ -36,6 +36,7 @@ homeassistant.components.fitbit.*
homeassistant.components.forecast_solar.*
homeassistant.components.fritzbox.*
homeassistant.components.frontend.*
homeassistant.components.fritz.*
homeassistant.components.geo_location.*
homeassistant.components.gios.*
homeassistant.components.group.*

View File

@ -111,6 +111,10 @@ class FritzBoxTools:
timeout=60.0,
)
if not self.connection:
_LOGGER.error("Unable to establish a connection with %s", self.host)
return
self.fritz_status = FritzStatus(fc=self.connection)
info = self.connection.call_action("DeviceInfo:1", "GetInfo")
if not self._unique_id:
@ -189,7 +193,7 @@ class FritzBoxTools:
def _update_info(self) -> list[HostInfo]:
"""Retrieve latest information from the FRITZ!Box."""
return self.fritz_hosts.get_hosts_info()
return self.fritz_hosts.get_hosts_info() # type: ignore [no-any-return]
def scan_devices(self, now: datetime | None = None) -> None:
"""Scan for new devices and return a list of found device ids."""

View File

@ -145,7 +145,7 @@ class FritzBoxTracker(ScannerEntity):
def ip_address(self) -> str | None:
"""Return the primary ip address of the device."""
if self._mac:
return self._router.devices[self._mac].ip_address
return self._router.devices[self._mac].ip_address # type: ignore[no-any-return]
return None
@property
@ -157,7 +157,7 @@ class FritzBoxTracker(ScannerEntity):
def hostname(self) -> str | None:
"""Return hostname of the device."""
if self._mac:
return self._router.devices[self._mac].hostname
return self._router.devices[self._mac].hostname # type: ignore[no-any-return]
return None
@property

View File

@ -39,37 +39,37 @@ def _retrieve_uptime_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_external_ip_state(status: FritzStatus, last_value: str) -> str:
"""Return external ip from device."""
return status.external_ip
return status.external_ip # type: ignore[no-any-return]
def _retrieve_kib_s_sent_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_kib_s_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload transmission rate."""
return round(status.transmission_rate[0] * 8 / 1024, 1)
return round(status.transmission_rate[0] * 8 / 1024, 1) # type: ignore[no-any-return]
def _retrieve_kib_s_received_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_kib_s_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download transmission rate."""
return round(status.transmission_rate[1] * 8 / 1024, 1)
return round(status.transmission_rate[1] * 8 / 1024, 1) # type: ignore[no-any-return]
def _retrieve_max_kib_s_sent_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_max_kib_s_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload max transmission rate."""
return round(status.max_bit_rate[0] / 1024, 1)
return round(status.max_bit_rate[0] / 1024, 1) # type: ignore[no-any-return]
def _retrieve_max_kib_s_received_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_max_kib_s_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download max transmission rate."""
return round(status.max_bit_rate[1] / 1024, 1)
return round(status.max_bit_rate[1] / 1024, 1) # type: ignore[no-any-return]
def _retrieve_gb_sent_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_gb_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload total data."""
return round(status.bytes_sent * 8 / 1024 / 1024 / 1024, 1)
return round(status.bytes_sent * 8 / 1024 / 1024 / 1024, 1) # type: ignore[no-any-return]
def _retrieve_gb_received_state(status: FritzStatus, last_value: str) -> str:
def _retrieve_gb_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download total data."""
return round(status.bytes_received * 8 / 1024 / 1024 / 1024, 1)
return round(status.bytes_received * 8 / 1024 / 1024 / 1024, 1) # type: ignore[no-any-return]
class SensorData(TypedDict, total=False):

View File

@ -69,7 +69,7 @@ def service_call_action(
return None
try:
return fritzbox_tools.connection.call_action(
return fritzbox_tools.connection.call_action( # type: ignore[no-any-return]
f"{service_name}:{service_suffix}",
action_name,
**kwargs,

View File

@ -407,6 +407,17 @@ no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.fritz.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.geo_location.*]
check_untyped_defs = true
disallow_incomplete_defs = true