From 36bb34f39117ce7beab2d1cfffa3b9043d9b2c29 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 9 Jul 2022 23:18:53 +0200 Subject: [PATCH] Remove kostal_plenticore from mypy ignore list (#74433) --- .../components/kostal_plenticore/helper.py | 44 +++++++++++-------- .../components/kostal_plenticore/sensor.py | 15 ++++++- mypy.ini | 12 ----- script/hassfest/mypy_config.py | 4 -- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/kostal_plenticore/helper.py b/homeassistant/components/kostal_plenticore/helper.py index c87d96161a4..ee684b68974 100644 --- a/homeassistant/components/kostal_plenticore/helper.py +++ b/homeassistant/components/kostal_plenticore/helper.py @@ -3,7 +3,7 @@ from __future__ import annotations import asyncio from collections import defaultdict -from collections.abc import Callable, Iterable +from collections.abc import Callable from datetime import datetime, timedelta import logging from typing import Any @@ -122,17 +122,20 @@ class Plenticore: class DataUpdateCoordinatorMixin: """Base implementation for read and write data.""" - async def async_read_data(self, module_id: str, data_id: str) -> list[str, bool]: + _plenticore: Plenticore + name: str + + async def async_read_data( + self, module_id: str, data_id: str + ) -> dict[str, dict[str, str]] | None: """Read data from Plenticore.""" if (client := self._plenticore.client) is None: - return False + return None try: - val = await client.get_setting_values(module_id, data_id) + return await client.get_setting_values(module_id, data_id) except PlenticoreApiException: - return False - else: - return val + return None async def async_write_data(self, module_id: str, value: dict[str, str]) -> bool: """Write settings back to Plenticore.""" @@ -170,7 +173,7 @@ class PlenticoreUpdateCoordinator(DataUpdateCoordinator): update_interval=update_inverval, ) # data ids to poll - self._fetch = defaultdict(list) + self._fetch: dict[str, list[str]] = defaultdict(list) self._plenticore = plenticore def start_fetch_data(self, module_id: str, data_id: str) -> None: @@ -246,7 +249,7 @@ class PlenticoreSelectUpdateCoordinator(DataUpdateCoordinator): update_interval=update_inverval, ) # data ids to poll - self._fetch = defaultdict(list) + self._fetch: dict[str, list[str]] = defaultdict(list) self._plenticore = plenticore def start_fetch_data(self, module_id: str, data_id: str, all_options: str) -> None: @@ -284,20 +287,23 @@ class SelectDataUpdateCoordinator( async def _async_get_current_option( self, - module_id: str | dict[str, Iterable[str]], + module_id: dict[str, list[str]], ) -> dict[str, dict[str, str]]: """Get current option.""" for mid, pids in module_id.items(): all_options = pids[1] for all_option in all_options: - if all_option != "None": - val = await self.async_read_data(mid, all_option) - for option in val.values(): - if option[all_option] == "1": - fetched = {mid: {pids[0]: all_option}} - return fetched + if all_option == "None" or not ( + val := await self.async_read_data(mid, all_option) + ): + continue + for option in val.values(): + if option[all_option] == "1": + fetched = {mid: {pids[0]: all_option}} + return fetched return {mid: {pids[0]: "None"}} + return {} class PlenticoreDataFormatter: @@ -361,7 +367,7 @@ class PlenticoreDataFormatter: return "" @staticmethod - def format_float(state: str) -> int | str: + def format_float(state: str) -> float | str: """Return the given state value as float rounded to three decimal places.""" try: return round(float(state), 3) @@ -377,7 +383,7 @@ class PlenticoreDataFormatter: return state @staticmethod - def format_inverter_state(state: str) -> str: + def format_inverter_state(state: str) -> str | None: """Return a readable string of the inverter state.""" try: value = int(state) @@ -387,7 +393,7 @@ class PlenticoreDataFormatter: return PlenticoreDataFormatter.INVERTER_STATES.get(value) @staticmethod - def format_em_manager_state(state: str) -> str: + def format_em_manager_state(state: str) -> str | None: """Return a readable state of the energy manager.""" try: value = int(state) diff --git a/homeassistant/components/kostal_plenticore/sensor.py b/homeassistant/components/kostal_plenticore/sensor.py index 5f8fb47e85a..f66264e1d7a 100644 --- a/homeassistant/components/kostal_plenticore/sensor.py +++ b/homeassistant/components/kostal_plenticore/sensor.py @@ -36,7 +36,18 @@ async def async_setup_entry( timedelta(seconds=10), plenticore, ) - for module_id, data_id, name, sensor_data, fmt in SENSOR_PROCESS_DATA: + module_id: str + data_id: str + name: str + sensor_data: dict[str, Any] + fmt: str + for ( # type: ignore[assignment] + module_id, + data_id, + name, + sensor_data, + fmt, + ) in SENSOR_PROCESS_DATA: if ( module_id not in available_process_data or data_id not in available_process_data[module_id] @@ -78,7 +89,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): sensor_data: dict[str, Any], formatter: Callable[[str], Any], device_info: DeviceInfo, - entity_category: EntityCategory, + entity_category: EntityCategory | None, ): """Create a new Sensor Entity for Plenticore process data.""" super().__init__(coordinator) diff --git a/mypy.ini b/mypy.ini index 06dec7d4897..e6f82ba957e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2696,18 +2696,6 @@ ignore_errors = true [mypy-homeassistant.components.konnected.config_flow] ignore_errors = true -[mypy-homeassistant.components.kostal_plenticore.helper] -ignore_errors = true - -[mypy-homeassistant.components.kostal_plenticore.select] -ignore_errors = true - -[mypy-homeassistant.components.kostal_plenticore.sensor] -ignore_errors = true - -[mypy-homeassistant.components.kostal_plenticore.switch] -ignore_errors = true - [mypy-homeassistant.components.lovelace] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 4ca5b3509d4..f86fd447722 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -33,10 +33,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.izone.climate", "homeassistant.components.konnected", "homeassistant.components.konnected.config_flow", - "homeassistant.components.kostal_plenticore.helper", - "homeassistant.components.kostal_plenticore.select", - "homeassistant.components.kostal_plenticore.sensor", - "homeassistant.components.kostal_plenticore.switch", "homeassistant.components.lovelace", "homeassistant.components.lovelace.dashboard", "homeassistant.components.lovelace.resources",