From 2f8d99bf5d9e5ed0c9eab14b35aa05168ce6c019 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 19 Jan 2022 09:00:09 +0100 Subject: [PATCH] Remove integrations from mypy ignored modules (part 2) (#64367) * Adjust dhcp * Adjust growatt_server * Adjust habitica * Adjust home_connect * Adjust iaqualink * Adjust incomfort * Adjust input_number * Adjust ipp * Adjust mypy_config * Unindent input-number * Fix type hint in home_connect Co-authored-by: epenet --- homeassistant/components/dhcp/__init__.py | 2 +- .../components/growatt_server/sensor.py | 2 +- homeassistant/components/habitica/sensor.py | 42 ++++++++++++------- homeassistant/components/home_connect/api.py | 5 ++- .../components/iaqualink/binary_sensor.py | 4 +- homeassistant/components/iaqualink/sensor.py | 7 ++-- homeassistant/components/iaqualink/switch.py | 5 ++- .../components/incomfort/__init__.py | 3 +- .../components/input_number/__init__.py | 4 +- homeassistant/components/ipp/sensor.py | 2 +- mypy.ini | 24 ----------- script/hassfest/mypy_config.py | 8 ---- 12 files changed, 47 insertions(+), 61 deletions(-) diff --git a/homeassistant/components/dhcp/__init__.py b/homeassistant/components/dhcp/__init__.py index 28204943606..4310f8f2caf 100644 --- a/homeassistant/components/dhcp/__init__.py +++ b/homeassistant/components/dhcp/__init__.py @@ -272,7 +272,7 @@ class DeviceTrackerWatcher(WatcherBase): @callback def _async_process_device_event(self, event: Event): """Process a device tracker state change event.""" - self._async_process_device_state(event.data.get("new_state")) + self._async_process_device_state(event.data["new_state"]) @callback def _async_process_device_state(self, state: State): diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index d9c384c69c5..71c1c69e08a 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -89,7 +89,7 @@ async def async_setup_entry( probe = GrowattData( api, username, password, device["deviceSn"], device["deviceType"] ) - sensor_descriptions = () + sensor_descriptions: tuple[GrowattSensorEntityDescription, ...] = () if device["deviceType"] == "inverter": sensor_descriptions = INVERTER_SENSOR_TYPES elif device["deviceType"] == "tlx": diff --git a/homeassistant/components/habitica/sensor.py b/homeassistant/components/habitica/sensor.py index f77fff06530..3547c8ca6f9 100644 --- a/homeassistant/components/habitica/sensor.py +++ b/homeassistant/components/habitica/sensor.py @@ -1,4 +1,6 @@ """Support for Habitica sensors.""" +from __future__ import annotations + from collections import namedtuple from datetime import timedelta from http import HTTPStatus @@ -19,26 +21,34 @@ _LOGGER = logging.getLogger(__name__) MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15) -ST = SensorType = namedtuple("SensorType", ["name", "icon", "unit", "path"]) +SensorType = namedtuple("SensorType", ["name", "icon", "unit", "path"]) SENSORS_TYPES = { - "name": ST("Name", None, "", ["profile", "name"]), - "hp": ST("HP", "mdi:heart", "HP", ["stats", "hp"]), - "maxHealth": ST("max HP", "mdi:heart", "HP", ["stats", "maxHealth"]), - "mp": ST("Mana", "mdi:auto-fix", "MP", ["stats", "mp"]), - "maxMP": ST("max Mana", "mdi:auto-fix", "MP", ["stats", "maxMP"]), - "exp": ST("EXP", "mdi:star", "EXP", ["stats", "exp"]), - "toNextLevel": ST("Next Lvl", "mdi:star", "EXP", ["stats", "toNextLevel"]), - "lvl": ST("Lvl", "mdi:arrow-up-bold-circle-outline", "Lvl", ["stats", "lvl"]), - "gp": ST("Gold", "mdi:circle-multiple", "Gold", ["stats", "gp"]), - "class": ST("Class", "mdi:sword", "", ["stats", "class"]), + "name": SensorType("Name", None, "", ["profile", "name"]), + "hp": SensorType("HP", "mdi:heart", "HP", ["stats", "hp"]), + "maxHealth": SensorType("max HP", "mdi:heart", "HP", ["stats", "maxHealth"]), + "mp": SensorType("Mana", "mdi:auto-fix", "MP", ["stats", "mp"]), + "maxMP": SensorType("max Mana", "mdi:auto-fix", "MP", ["stats", "maxMP"]), + "exp": SensorType("EXP", "mdi:star", "EXP", ["stats", "exp"]), + "toNextLevel": SensorType("Next Lvl", "mdi:star", "EXP", ["stats", "toNextLevel"]), + "lvl": SensorType( + "Lvl", "mdi:arrow-up-bold-circle-outline", "Lvl", ["stats", "lvl"] + ), + "gp": SensorType("Gold", "mdi:circle-multiple", "Gold", ["stats", "gp"]), + "class": SensorType("Class", "mdi:sword", "", ["stats", "class"]), } TASKS_TYPES = { - "habits": ST("Habits", "mdi:clipboard-list-outline", "n_of_tasks", ["habits"]), - "dailys": ST("Dailys", "mdi:clipboard-list-outline", "n_of_tasks", ["dailys"]), - "todos": ST("TODOs", "mdi:clipboard-list-outline", "n_of_tasks", ["todos"]), - "rewards": ST("Rewards", "mdi:clipboard-list-outline", "n_of_tasks", ["rewards"]), + "habits": SensorType( + "Habits", "mdi:clipboard-list-outline", "n_of_tasks", ["habits"] + ), + "dailys": SensorType( + "Dailys", "mdi:clipboard-list-outline", "n_of_tasks", ["dailys"] + ), + "todos": SensorType("TODOs", "mdi:clipboard-list-outline", "n_of_tasks", ["todos"]), + "rewards": SensorType( + "Rewards", "mdi:clipboard-list-outline", "n_of_tasks", ["rewards"] + ), } TASKS_MAP_ID = "id" @@ -76,7 +86,7 @@ async def async_setup_entry( ) -> None: """Set up the habitica sensors.""" - entities = [] + entities: list[SensorEntity] = [] name = config_entry.data[CONF_NAME] sensor_data = HabitipyData(hass.data[DOMAIN][config_entry.entry_id]) await sensor_data.update() diff --git a/homeassistant/components/home_connect/api.py b/homeassistant/components/home_connect/api.py index b73d5416830..6054dfd3cc7 100644 --- a/homeassistant/components/home_connect/api.py +++ b/homeassistant/components/home_connect/api.py @@ -2,6 +2,7 @@ from asyncio import run_coroutine_threadsafe import logging +from typing import Any import homeconnect from homeconnect.api import HomeConnectError @@ -54,7 +55,7 @@ class ConfigEntryAuth(homeconnect.HomeConnectAPI): hass, config_entry, implementation ) super().__init__(self.session.token) - self.devices = [] + self.devices: list[dict[str, Any]] = [] def refresh_tokens(self) -> dict: """Refresh and return new Home Connect tokens using Home Assistant OAuth2 session.""" @@ -142,7 +143,7 @@ class HomeConnectDevice: class DeviceWithPrograms(HomeConnectDevice): """Device with programs.""" - PROGRAMS = [] + PROGRAMS: list[dict[str, str]] = [] def get_programs_available(self): """Get the available programs.""" diff --git a/homeassistant/components/iaqualink/binary_sensor.py b/homeassistant/components/iaqualink/binary_sensor.py index 36fa81951a9..7513a15272c 100644 --- a/homeassistant/components/iaqualink/binary_sensor.py +++ b/homeassistant/components/iaqualink/binary_sensor.py @@ -1,4 +1,6 @@ """Support for Aqualink temperature sensors.""" +from __future__ import annotations + from homeassistant.components.binary_sensor import ( DOMAIN, BinarySensorDeviceClass, @@ -40,7 +42,7 @@ class HassAqualinkBinarySensor(AqualinkEntity, BinarySensorEntity): return self.dev.is_on @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass | None: """Return the class of the binary sensor.""" if self.name == "Freeze Protection": return BinarySensorDeviceClass.COLD diff --git a/homeassistant/components/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index c9d9beafba2..1c567b04a7f 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -43,16 +43,15 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity): return None @property - def native_value(self) -> str | None: + def native_value(self) -> int | float | None: """Return the state of the sensor.""" if self.dev.state == "": return None try: - state = int(self.dev.state) + return int(self.dev.state) except ValueError: - state = float(self.dev.state) - return state + return float(self.dev.state) @property def device_class(self) -> str | None: diff --git a/homeassistant/components/iaqualink/switch.py b/homeassistant/components/iaqualink/switch.py index afad682445f..146d30e2d04 100644 --- a/homeassistant/components/iaqualink/switch.py +++ b/homeassistant/components/iaqualink/switch.py @@ -1,4 +1,6 @@ """Support for Aqualink pool feature switches.""" +from __future__ import annotations + from homeassistant.components.switch import DOMAIN, SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -32,7 +34,7 @@ class HassAqualinkSwitch(AqualinkEntity, SwitchEntity): return self.dev.label @property - def icon(self) -> str: + def icon(self) -> str | None: """Return an icon based on the switch type.""" if self.name == "Cleaner": return "mdi:robot-vacuum" @@ -42,6 +44,7 @@ class HassAqualinkSwitch(AqualinkEntity, SwitchEntity): return "mdi:fan" if self.name.endswith("Heater"): return "mdi:radiator" + return None @property def is_on(self) -> bool: diff --git a/homeassistant/components/incomfort/__init__.py b/homeassistant/components/incomfort/__init__.py index 8a40c279c2a..9b2f0d88b3f 100644 --- a/homeassistant/components/incomfort/__init__.py +++ b/homeassistant/components/incomfort/__init__.py @@ -74,7 +74,8 @@ class IncomfortEntity(Entity): def __init__(self) -> None: """Initialize the class.""" - self._unique_id = self._name = None + self._name: str | None = None + self._unique_id: str | None = None @property def unique_id(self) -> str | None: diff --git a/homeassistant/components/input_number/__init__.py b/homeassistant/components/input_number/__init__.py index 89a487d630f..491b9abc024 100644 --- a/homeassistant/components/input_number/__init__.py +++ b/homeassistant/components/input_number/__init__.py @@ -200,7 +200,7 @@ class InputNumber(RestoreEntity): """Initialize an input number.""" self._config = config self.editable = True - self._current_value = config.get(CONF_INITIAL) + self._current_value: float | None = config.get(CONF_INITIAL) @classmethod def from_yaml(cls, config: dict) -> InputNumber: @@ -306,6 +306,8 @@ class InputNumber(RestoreEntity): """Handle when the config is updated.""" self._config = config # just in case min/max values changed + if self._current_value is None: + return self._current_value = min(self._current_value, self._maximum) self._current_value = max(self._current_value, self._minimum) self.async_write_ha_state() diff --git a/homeassistant/components/ipp/sensor.py b/homeassistant/components/ipp/sensor.py index 6e6cee696bc..718b35dbc6a 100644 --- a/homeassistant/components/ipp/sensor.py +++ b/homeassistant/components/ipp/sensor.py @@ -39,7 +39,7 @@ async def async_setup_entry( if (unique_id := entry.unique_id) is None: unique_id = entry.entry_id - sensors = [] + sensors: list[SensorEntity] = [] sensors.append(IPPPrinterSensor(entry.entry_id, unique_id, coordinator)) sensors.append(IPPUptimeSensor(entry.entry_id, unique_id, coordinator)) diff --git a/mypy.ini b/mypy.ini index 9f76bfa9739..84a9472f9c8 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2033,9 +2033,6 @@ ignore_errors = true [mypy-homeassistant.components.denonavr.*] ignore_errors = true -[mypy-homeassistant.components.dhcp.*] -ignore_errors = true - [mypy-homeassistant.components.evohome.*] ignore_errors = true @@ -2057,12 +2054,6 @@ ignore_errors = true [mypy-homeassistant.components.gree.*] ignore_errors = true -[mypy-homeassistant.components.growatt_server.*] -ignore_errors = true - -[mypy-homeassistant.components.habitica.*] -ignore_errors = true - [mypy-homeassistant.components.harmony.*] ignore_errors = true @@ -2072,9 +2063,6 @@ ignore_errors = true [mypy-homeassistant.components.here_travel_time.*] ignore_errors = true -[mypy-homeassistant.components.home_connect.*] -ignore_errors = true - [mypy-homeassistant.components.home_plus_control.*] ignore_errors = true @@ -2087,27 +2075,15 @@ ignore_errors = true [mypy-homeassistant.components.honeywell.*] ignore_errors = true -[mypy-homeassistant.components.iaqualink.*] -ignore_errors = true - [mypy-homeassistant.components.icloud.*] ignore_errors = true -[mypy-homeassistant.components.incomfort.*] -ignore_errors = true - [mypy-homeassistant.components.influxdb.*] ignore_errors = true [mypy-homeassistant.components.input_datetime.*] ignore_errors = true -[mypy-homeassistant.components.input_number.*] -ignore_errors = true - -[mypy-homeassistant.components.ipp.*] -ignore_errors = true - [mypy-homeassistant.components.isy994.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index bf1d008a059..0d83af52e9e 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -23,7 +23,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.deconz.*", "homeassistant.components.demo.*", "homeassistant.components.denonavr.*", - "homeassistant.components.dhcp.*", "homeassistant.components.evohome.*", "homeassistant.components.fireservicerota.*", "homeassistant.components.firmata.*", @@ -31,23 +30,16 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.geniushub.*", "homeassistant.components.google_assistant.*", "homeassistant.components.gree.*", - "homeassistant.components.growatt_server.*", - "homeassistant.components.habitica.*", "homeassistant.components.harmony.*", "homeassistant.components.hassio.*", "homeassistant.components.here_travel_time.*", - "homeassistant.components.home_connect.*", "homeassistant.components.home_plus_control.*", "homeassistant.components.homekit.*", "homeassistant.components.homekit_controller.*", "homeassistant.components.honeywell.*", - "homeassistant.components.iaqualink.*", "homeassistant.components.icloud.*", - "homeassistant.components.incomfort.*", "homeassistant.components.influxdb.*", "homeassistant.components.input_datetime.*", - "homeassistant.components.input_number.*", - "homeassistant.components.ipp.*", "homeassistant.components.isy994.*", "homeassistant.components.izone.*", "homeassistant.components.kaiterra.*",