mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix netgear typing (#67287)
This commit is contained in:
parent
7f4faafe38
commit
d299915c1a
@ -1,6 +1,9 @@
|
|||||||
"""Support for Netgear routers."""
|
"""Support for Netgear routers."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL
|
||||||
@ -51,6 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
|
assert entry.unique_id
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
@ -67,7 +71,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
"""Fetch data from the router."""
|
"""Fetch data from the router."""
|
||||||
return await router.async_update_device_trackers()
|
return await router.async_update_device_trackers()
|
||||||
|
|
||||||
async def async_update_traffic_meter() -> dict:
|
async def async_update_traffic_meter() -> dict[str, Any] | None:
|
||||||
"""Fetch data from the router."""
|
"""Fetch data from the router."""
|
||||||
return await router.async_get_traffic_meter()
|
return await router.async_get_traffic_meter()
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
"""Config flow to configure the Netgear integration."""
|
"""Config flow to configure the Netgear integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pynetgear import DEFAULT_HOST, DEFAULT_PORT, DEFAULT_USER
|
from pynetgear import DEFAULT_HOST, DEFAULT_PORT, DEFAULT_USER
|
||||||
@ -119,11 +122,12 @@ class NetgearFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Initialize flow from ssdp."""
|
"""Initialize flow from ssdp."""
|
||||||
updated_data = {}
|
updated_data: dict[str, str | int | bool] = {}
|
||||||
|
|
||||||
device_url = urlparse(discovery_info.ssdp_location)
|
device_url = urlparse(discovery_info.ssdp_location)
|
||||||
if device_url.hostname:
|
if hostname := device_url.hostname:
|
||||||
updated_data[CONF_HOST] = device_url.hostname
|
hostname = cast(str, hostname)
|
||||||
|
updated_data[CONF_HOST] = hostname
|
||||||
|
|
||||||
_LOGGER.debug("Netgear ssdp discovery info: %s", discovery_info)
|
_LOGGER.debug("Netgear ssdp discovery info: %s", discovery_info)
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class NetgearScannerEntity(NetgearBaseEntity, ScannerEntity):
|
|||||||
self._hostname = self.get_hostname()
|
self._hostname = self.get_hostname()
|
||||||
self._icon = DEVICE_ICONS.get(device["device_type"], "mdi:help-network")
|
self._icon = DEVICE_ICONS.get(device["device_type"], "mdi:help-network")
|
||||||
|
|
||||||
def get_hostname(self):
|
def get_hostname(self) -> str | None:
|
||||||
"""Return the hostname of the given device or None if we don't know."""
|
"""Return the hostname of the given device or None if we don't know."""
|
||||||
if (hostname := self._device["name"]) == "--":
|
if (hostname := self._device["name"]) == "--":
|
||||||
return None
|
return None
|
||||||
@ -74,7 +74,7 @@ class NetgearScannerEntity(NetgearBaseEntity, ScannerEntity):
|
|||||||
self._icon = DEVICE_ICONS.get(self._device["device_type"], "mdi:help-network")
|
self._icon = DEVICE_ICONS.get(self._device["device_type"], "mdi:help-network")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self):
|
def is_connected(self) -> bool:
|
||||||
"""Return true if the device is connected to the router."""
|
"""Return true if the device is connected to the router."""
|
||||||
return self._active
|
return self._active
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class NetgearScannerEntity(NetgearBaseEntity, ScannerEntity):
|
|||||||
return self._mac
|
return self._mac
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hostname(self) -> str:
|
def hostname(self) -> str | None:
|
||||||
"""Return the hostname."""
|
"""Return the hostname."""
|
||||||
return self._hostname
|
return self._hostname
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from abc import abstractmethod
|
|||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pynetgear import Netgear
|
from pynetgear import Netgear
|
||||||
|
|
||||||
@ -59,13 +60,14 @@ class NetgearRouter:
|
|||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Initialize a Netgear router."""
|
"""Initialize a Netgear router."""
|
||||||
|
assert entry.unique_id
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
self.entry_id = entry.entry_id
|
self.entry_id = entry.entry_id
|
||||||
self.unique_id = entry.unique_id
|
self.unique_id = entry.unique_id
|
||||||
self._host = entry.data.get(CONF_HOST)
|
self._host: str = entry.data[CONF_HOST]
|
||||||
self._port = entry.data.get(CONF_PORT)
|
self._port: int = entry.data[CONF_PORT]
|
||||||
self._ssl = entry.data.get(CONF_SSL)
|
self._ssl: bool = entry.data[CONF_SSL]
|
||||||
self._username = entry.data.get(CONF_USERNAME)
|
self._username = entry.data.get(CONF_USERNAME)
|
||||||
self._password = entry.data[CONF_PASSWORD]
|
self._password = entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
@ -85,9 +87,9 @@ class NetgearRouter:
|
|||||||
self._api: Netgear = None
|
self._api: Netgear = None
|
||||||
self._api_lock = asyncio.Lock()
|
self._api_lock = asyncio.Lock()
|
||||||
|
|
||||||
self.devices = {}
|
self.devices: dict[str, Any] = {}
|
||||||
|
|
||||||
def _setup(self) -> None:
|
def _setup(self) -> bool:
|
||||||
"""Set up a Netgear router sync portion."""
|
"""Set up a Netgear router sync portion."""
|
||||||
self._api = get_api(
|
self._api = get_api(
|
||||||
self._password,
|
self._password,
|
||||||
@ -134,7 +136,7 @@ class NetgearRouter:
|
|||||||
if device_entry.via_device_id is None:
|
if device_entry.via_device_id is None:
|
||||||
continue # do not add the router itself
|
continue # do not add the router itself
|
||||||
|
|
||||||
device_mac = dict(device_entry.connections).get(dr.CONNECTION_NETWORK_MAC)
|
device_mac = dict(device_entry.connections)[dr.CONNECTION_NETWORK_MAC]
|
||||||
self.devices[device_mac] = {
|
self.devices[device_mac] = {
|
||||||
"mac": device_mac,
|
"mac": device_mac,
|
||||||
"name": device_entry.name,
|
"name": device_entry.name,
|
||||||
@ -166,14 +168,14 @@ class NetgearRouter:
|
|||||||
self._api.get_attached_devices_2
|
self._api.get_attached_devices_2
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_update_device_trackers(self, now=None) -> None:
|
async def async_update_device_trackers(self, now=None) -> bool:
|
||||||
"""Update Netgear devices."""
|
"""Update Netgear devices."""
|
||||||
new_device = False
|
new_device = False
|
||||||
ntg_devices = await self.async_get_attached_devices()
|
ntg_devices = await self.async_get_attached_devices()
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
if ntg_devices is None:
|
if ntg_devices is None:
|
||||||
return
|
return new_device
|
||||||
|
|
||||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
_LOGGER.debug("Netgear scan result: \n%s", ntg_devices)
|
_LOGGER.debug("Netgear scan result: \n%s", ntg_devices)
|
||||||
@ -197,7 +199,7 @@ class NetgearRouter:
|
|||||||
|
|
||||||
return new_device
|
return new_device
|
||||||
|
|
||||||
async def async_get_traffic_meter(self) -> None:
|
async def async_get_traffic_meter(self) -> dict[str, Any] | None:
|
||||||
"""Get the traffic meter data of the router."""
|
"""Get the traffic meter data of the router."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
return await self.hass.async_add_executor_job(self._api.get_traffic_meter)
|
return await self.hass.async_add_executor_job(self._api.get_traffic_meter)
|
||||||
|
12
mypy.ini
12
mypy.ini
@ -2480,18 +2480,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.minecraft_server.sensor]
|
[mypy-homeassistant.components.minecraft_server.sensor]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.netgear]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.netgear.config_flow]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.netgear.device_tracker]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.netgear.router]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.nilu.air_quality]
|
[mypy-homeassistant.components.nilu.air_quality]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -94,10 +94,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.minecraft_server",
|
"homeassistant.components.minecraft_server",
|
||||||
"homeassistant.components.minecraft_server.helpers",
|
"homeassistant.components.minecraft_server.helpers",
|
||||||
"homeassistant.components.minecraft_server.sensor",
|
"homeassistant.components.minecraft_server.sensor",
|
||||||
"homeassistant.components.netgear",
|
|
||||||
"homeassistant.components.netgear.config_flow",
|
|
||||||
"homeassistant.components.netgear.device_tracker",
|
|
||||||
"homeassistant.components.netgear.router",
|
|
||||||
"homeassistant.components.nilu.air_quality",
|
"homeassistant.components.nilu.air_quality",
|
||||||
"homeassistant.components.nzbget",
|
"homeassistant.components.nzbget",
|
||||||
"homeassistant.components.nzbget.config_flow",
|
"homeassistant.components.nzbget.config_flow",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user