Complete typing on AdGuard Home integration (#47477)

This commit is contained in:
Franck Nijhof 2021-03-06 23:19:03 +01:00 committed by GitHub
parent d944bbbc52
commit b01a6367cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 57 deletions

View file

@ -1,25 +1,28 @@
"""Support for AdGuard Home sensors."""
from __future__ import annotations
from datetime import timedelta
from typing import Callable
from adguardhome import AdGuardHomeConnectionError
from adguardhome import AdGuardHome, AdGuardHomeConnectionError
from homeassistant.components.adguard import AdGuardHomeDeviceEntity
from homeassistant.components.adguard.const import (
DATA_ADGUARD_CLIENT,
DATA_ADGUARD_VERION,
DOMAIN,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TIME_MILLISECONDS
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.entity import Entity
from . import AdGuardHomeDeviceEntity
from .const import DATA_ADGUARD_CLIENT, DATA_ADGUARD_VERION, DOMAIN
SCAN_INTERVAL = timedelta(seconds=300)
PARALLEL_UPDATES = 4
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: Callable[[list[Entity], bool], None],
) -> None:
"""Set up AdGuard Home sensor based on a config entry."""
adguard = hass.data[DOMAIN][DATA_ADGUARD_CLIENT]
@ -50,7 +53,7 @@ class AdGuardHomeSensor(AdGuardHomeDeviceEntity):
def __init__(
self,
adguard,
adguard: AdGuardHome,
name: str,
icon: str,
measurement: str,
@ -78,12 +81,12 @@ class AdGuardHomeSensor(AdGuardHomeDeviceEntity):
)
@property
def state(self):
def state(self) -> str | None:
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self) -> str:
def unit_of_measurement(self) -> str | None:
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@ -91,7 +94,7 @@ class AdGuardHomeSensor(AdGuardHomeDeviceEntity):
class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home DNS Queries sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard, "AdGuard DNS Queries", "mdi:magnify", "dns_queries", "queries"
@ -105,7 +108,7 @@ class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home blocked by filtering sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -124,7 +127,7 @@ class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home blocked percentage sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -143,7 +146,7 @@ class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by parental control sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -161,7 +164,7 @@ class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by safe browsing sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -179,7 +182,7 @@ class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by safe search sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -197,7 +200,7 @@ class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home average processing time sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,
@ -216,7 +219,7 @@ class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
class AdGuardHomeRulesCountSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home rules count sensor."""
def __init__(self, adguard):
def __init__(self, adguard: AdGuardHome) -> None:
"""Initialize AdGuard Home sensor."""
super().__init__(
adguard,