From edaf75321e4eb727141b992e8e39c144376b06da Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 19 Jan 2022 13:29:24 +0100 Subject: [PATCH] Remove integrations from mypy ignored modules (part 4) (#64435) Co-authored-by: epenet --- .../components/ness_alarm/__init__.py | 3 +-- homeassistant/components/nightscout/sensor.py | 3 ++- homeassistant/components/nuki/lock.py | 4 +++- homeassistant/components/nws/__init__.py | 6 +++++- .../components/onboarding/__init__.py | 5 +++++ homeassistant/components/onboarding/views.py | 4 +++- homeassistant/components/ovo_energy/sensor.py | 6 +++--- mypy.ini | 18 ------------------ script/hassfest/mypy_config.py | 6 ------ 9 files changed, 22 insertions(+), 33 deletions(-) diff --git a/homeassistant/components/ness_alarm/__init__.py b/homeassistant/components/ness_alarm/__init__.py index 5eb33be7acb..d082f77d837 100644 --- a/homeassistant/components/ness_alarm/__init__.py +++ b/homeassistant/components/ness_alarm/__init__.py @@ -33,7 +33,6 @@ CONF_ZONE_NAME = "name" CONF_ZONE_TYPE = "type" CONF_ZONE_ID = "id" ATTR_OUTPUT_ID = "output_id" -DEFAULT_ZONES = [] DEFAULT_SCAN_INTERVAL = datetime.timedelta(minutes=1) DEFAULT_INFER_ARMING_STATE = False @@ -62,7 +61,7 @@ CONFIG_SCHEMA = vol.Schema( vol.Optional( CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL ): cv.positive_time_period, - vol.Optional(CONF_ZONES, default=DEFAULT_ZONES): vol.All( + vol.Optional(CONF_ZONES, default=[]): vol.All( cv.ensure_list, [ZONE_SCHEMA] ), vol.Optional( diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 1b37fa8da7c..4ee75f66959 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations from asyncio import TimeoutError as AsyncIOTimeoutError from datetime import timedelta import logging +from typing import Any from aiohttp import ClientError from py_nightscout import Api as NightscoutAPI @@ -42,7 +43,7 @@ class NightscoutSensor(SensorEntity): self._unique_id = unique_id self._name = name self._state = None - self._attributes = None + self._attributes: dict[str, Any] = {} self._unit_of_measurement = "mg/dL" self._icon = "mdi:cloud-question" self._available = False diff --git a/homeassistant/components/nuki/lock.py b/homeassistant/components/nuki/lock.py index 25ad5bdf042..e999c3911db 100644 --- a/homeassistant/components/nuki/lock.py +++ b/homeassistant/components/nuki/lock.py @@ -31,7 +31,9 @@ async def async_setup_entry( data = hass.data[NUKI_DOMAIN][entry.entry_id] coordinator = data[DATA_COORDINATOR] - entities = [NukiLockEntity(coordinator, lock) for lock in data[DATA_LOCKS]] + entities: list[NukiDeviceEntity] = [ + NukiLockEntity(coordinator, lock) for lock in data[DATA_LOCKS] + ] entities.extend( [NukiOpenerEntity(coordinator, opener) for opener in data[DATA_OPENERS]] ) diff --git a/homeassistant/components/nws/__init__.py b/homeassistant/components/nws/__init__.py index 3be70c95b7a..3667acf975e 100644 --- a/homeassistant/components/nws/__init__.py +++ b/homeassistant/components/nws/__init__.py @@ -4,6 +4,7 @@ from __future__ import annotations from collections.abc import Awaitable, Callable import datetime import logging +from typing import TYPE_CHECKING from pynws import SimpleNWS @@ -69,7 +70,7 @@ class NwsDataUpdateCoordinator(DataUpdateCoordinator): request_refresh_debouncer=request_refresh_debouncer, ) self.failed_update_interval = failed_update_interval - self.last_update_success_time = None + self.last_update_success_time: datetime.datetime | None = None @callback def _schedule_refresh(self) -> None: @@ -83,6 +84,9 @@ class NwsDataUpdateCoordinator(DataUpdateCoordinator): # That way we obtain a constant update frequency, # as long as the update process takes less than a second if self.last_update_success: + if TYPE_CHECKING: + # the base class allows None, but this one doesn't + assert self.update_interval is not None update_interval = self.update_interval self.last_update_success_time = utcnow() else: diff --git a/homeassistant/components/onboarding/__init__.py b/homeassistant/components/onboarding/__init__.py index 41bbbf44011..c36f19fd28d 100644 --- a/homeassistant/components/onboarding/__init__.py +++ b/homeassistant/components/onboarding/__init__.py @@ -1,4 +1,6 @@ """Support to help onboard new users.""" +from typing import TYPE_CHECKING + from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.storage import Store from homeassistant.helpers.typing import ConfigType @@ -54,6 +56,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if (data := await store.async_load()) is None: data = {"done": []} + if TYPE_CHECKING: + assert isinstance(data, dict) + if STEP_USER not in data["done"]: # Users can already have created an owner account via the command line # If so, mark the user step as done. diff --git a/homeassistant/components/onboarding/views.py b/homeassistant/components/onboarding/views.py index 44d239fdb6b..2fbeb5592f8 100644 --- a/homeassistant/components/onboarding/views.py +++ b/homeassistant/components/onboarding/views.py @@ -1,4 +1,6 @@ """Onboarding views.""" +from __future__ import annotations + import asyncio from http import HTTPStatus @@ -77,7 +79,7 @@ class InstallationTypeOnboardingView(HomeAssistantView): class _BaseOnboardingView(HomeAssistantView): """Base class for onboarding.""" - step = None + step: str | None = None def __init__(self, data, store): """Initialize the onboarding view.""" diff --git a/homeassistant/components/ovo_energy/sensor.py b/homeassistant/components/ovo_energy/sensor.py index 276705248b3..ba332a08a16 100644 --- a/homeassistant/components/ovo_energy/sensor.py +++ b/homeassistant/components/ovo_energy/sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Callable from dataclasses import dataclass -from datetime import timedelta +from datetime import datetime, timedelta from typing import Final from ovoenergy import OVODailyUsage @@ -37,7 +37,7 @@ KEY_LAST_GAS_COST: Final = "last_gas_cost" class OVOEnergySensorEntityDescription(SensorEntityDescription): """Class describing System Bridge sensor entities.""" - value: Callable[[OVODailyUsage], StateType] = round + value: Callable[[OVODailyUsage], StateType | datetime] = round SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( @@ -158,7 +158,7 @@ class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity): self.entity_description = description @property - def native_value(self) -> StateType: + def native_value(self) -> StateType | datetime: """Return the state.""" usage: OVODailyUsage = self.coordinator.data return self.entity_description.value(usage) diff --git a/mypy.ini b/mypy.ini index 34365c53edb..97ce2b7a35f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2120,42 +2120,24 @@ ignore_errors = true [mypy-homeassistant.components.mobile_app.*] ignore_errors = true -[mypy-homeassistant.components.ness_alarm.*] -ignore_errors = true - [mypy-homeassistant.components.nest.legacy.*] ignore_errors = true [mypy-homeassistant.components.netgear.*] ignore_errors = true -[mypy-homeassistant.components.nightscout.*] -ignore_errors = true - [mypy-homeassistant.components.nilu.*] ignore_errors = true -[mypy-homeassistant.components.nuki.*] -ignore_errors = true - -[mypy-homeassistant.components.nws.*] -ignore_errors = true - [mypy-homeassistant.components.nzbget.*] ignore_errors = true [mypy-homeassistant.components.omnilogic.*] ignore_errors = true -[mypy-homeassistant.components.onboarding.*] -ignore_errors = true - [mypy-homeassistant.components.onvif.*] ignore_errors = true -[mypy-homeassistant.components.ovo_energy.*] -ignore_errors = true - [mypy-homeassistant.components.ozw.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 06fe268d04e..c711e6ad094 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -52,18 +52,12 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.meteo_france.*", "homeassistant.components.minecraft_server.*", "homeassistant.components.mobile_app.*", - "homeassistant.components.ness_alarm.*", "homeassistant.components.nest.legacy.*", "homeassistant.components.netgear.*", - "homeassistant.components.nightscout.*", "homeassistant.components.nilu.*", - "homeassistant.components.nuki.*", - "homeassistant.components.nws.*", "homeassistant.components.nzbget.*", "homeassistant.components.omnilogic.*", - "homeassistant.components.onboarding.*", "homeassistant.components.onvif.*", - "homeassistant.components.ovo_energy.*", "homeassistant.components.ozw.*", "homeassistant.components.philips_js.*", "homeassistant.components.ping.*",