mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove kostal_plenticore from mypy ignore list (#74433)
This commit is contained in:
parent
d04e77ef7f
commit
36bb34f391
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -122,17 +122,20 @@ class Plenticore:
|
|||||||
class DataUpdateCoordinatorMixin:
|
class DataUpdateCoordinatorMixin:
|
||||||
"""Base implementation for read and write data."""
|
"""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."""
|
"""Read data from Plenticore."""
|
||||||
if (client := self._plenticore.client) is None:
|
if (client := self._plenticore.client) is None:
|
||||||
return False
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
val = await client.get_setting_values(module_id, data_id)
|
return await client.get_setting_values(module_id, data_id)
|
||||||
except PlenticoreApiException:
|
except PlenticoreApiException:
|
||||||
return False
|
return None
|
||||||
else:
|
|
||||||
return val
|
|
||||||
|
|
||||||
async def async_write_data(self, module_id: str, value: dict[str, str]) -> bool:
|
async def async_write_data(self, module_id: str, value: dict[str, str]) -> bool:
|
||||||
"""Write settings back to Plenticore."""
|
"""Write settings back to Plenticore."""
|
||||||
@ -170,7 +173,7 @@ class PlenticoreUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
update_interval=update_inverval,
|
update_interval=update_inverval,
|
||||||
)
|
)
|
||||||
# data ids to poll
|
# data ids to poll
|
||||||
self._fetch = defaultdict(list)
|
self._fetch: dict[str, list[str]] = defaultdict(list)
|
||||||
self._plenticore = plenticore
|
self._plenticore = plenticore
|
||||||
|
|
||||||
def start_fetch_data(self, module_id: str, data_id: str) -> None:
|
def start_fetch_data(self, module_id: str, data_id: str) -> None:
|
||||||
@ -246,7 +249,7 @@ class PlenticoreSelectUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
update_interval=update_inverval,
|
update_interval=update_inverval,
|
||||||
)
|
)
|
||||||
# data ids to poll
|
# data ids to poll
|
||||||
self._fetch = defaultdict(list)
|
self._fetch: dict[str, list[str]] = defaultdict(list)
|
||||||
self._plenticore = plenticore
|
self._plenticore = plenticore
|
||||||
|
|
||||||
def start_fetch_data(self, module_id: str, data_id: str, all_options: str) -> None:
|
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(
|
async def _async_get_current_option(
|
||||||
self,
|
self,
|
||||||
module_id: str | dict[str, Iterable[str]],
|
module_id: dict[str, list[str]],
|
||||||
) -> dict[str, dict[str, str]]:
|
) -> dict[str, dict[str, str]]:
|
||||||
"""Get current option."""
|
"""Get current option."""
|
||||||
for mid, pids in module_id.items():
|
for mid, pids in module_id.items():
|
||||||
all_options = pids[1]
|
all_options = pids[1]
|
||||||
for all_option in all_options:
|
for all_option in all_options:
|
||||||
if all_option != "None":
|
if all_option == "None" or not (
|
||||||
val = await self.async_read_data(mid, all_option)
|
val := await self.async_read_data(mid, all_option)
|
||||||
for option in val.values():
|
):
|
||||||
if option[all_option] == "1":
|
continue
|
||||||
fetched = {mid: {pids[0]: all_option}}
|
for option in val.values():
|
||||||
return fetched
|
if option[all_option] == "1":
|
||||||
|
fetched = {mid: {pids[0]: all_option}}
|
||||||
|
return fetched
|
||||||
|
|
||||||
return {mid: {pids[0]: "None"}}
|
return {mid: {pids[0]: "None"}}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class PlenticoreDataFormatter:
|
class PlenticoreDataFormatter:
|
||||||
@ -361,7 +367,7 @@ class PlenticoreDataFormatter:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
@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."""
|
"""Return the given state value as float rounded to three decimal places."""
|
||||||
try:
|
try:
|
||||||
return round(float(state), 3)
|
return round(float(state), 3)
|
||||||
@ -377,7 +383,7 @@ class PlenticoreDataFormatter:
|
|||||||
return state
|
return state
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_inverter_state(state: str) -> str:
|
def format_inverter_state(state: str) -> str | None:
|
||||||
"""Return a readable string of the inverter state."""
|
"""Return a readable string of the inverter state."""
|
||||||
try:
|
try:
|
||||||
value = int(state)
|
value = int(state)
|
||||||
@ -387,7 +393,7 @@ class PlenticoreDataFormatter:
|
|||||||
return PlenticoreDataFormatter.INVERTER_STATES.get(value)
|
return PlenticoreDataFormatter.INVERTER_STATES.get(value)
|
||||||
|
|
||||||
@staticmethod
|
@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."""
|
"""Return a readable state of the energy manager."""
|
||||||
try:
|
try:
|
||||||
value = int(state)
|
value = int(state)
|
||||||
|
@ -36,7 +36,18 @@ async def async_setup_entry(
|
|||||||
timedelta(seconds=10),
|
timedelta(seconds=10),
|
||||||
plenticore,
|
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 (
|
if (
|
||||||
module_id not in available_process_data
|
module_id not in available_process_data
|
||||||
or data_id not in available_process_data[module_id]
|
or data_id not in available_process_data[module_id]
|
||||||
@ -78,7 +89,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity):
|
|||||||
sensor_data: dict[str, Any],
|
sensor_data: dict[str, Any],
|
||||||
formatter: Callable[[str], Any],
|
formatter: Callable[[str], Any],
|
||||||
device_info: DeviceInfo,
|
device_info: DeviceInfo,
|
||||||
entity_category: EntityCategory,
|
entity_category: EntityCategory | None,
|
||||||
):
|
):
|
||||||
"""Create a new Sensor Entity for Plenticore process data."""
|
"""Create a new Sensor Entity for Plenticore process data."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
12
mypy.ini
12
mypy.ini
@ -2696,18 +2696,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.konnected.config_flow]
|
[mypy-homeassistant.components.konnected.config_flow]
|
||||||
ignore_errors = true
|
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]
|
[mypy-homeassistant.components.lovelace]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -33,10 +33,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.izone.climate",
|
"homeassistant.components.izone.climate",
|
||||||
"homeassistant.components.konnected",
|
"homeassistant.components.konnected",
|
||||||
"homeassistant.components.konnected.config_flow",
|
"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",
|
||||||
"homeassistant.components.lovelace.dashboard",
|
"homeassistant.components.lovelace.dashboard",
|
||||||
"homeassistant.components.lovelace.resources",
|
"homeassistant.components.lovelace.resources",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user