Enable basic type checking for climacell (#55334)
parent
cbf2bf2e1f
commit
e50a47621f
|
@ -112,7 +112,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
"""Set up ClimaCell API from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
params = {}
|
||||
params: dict[str, Any] = {}
|
||||
# If config entry options not set up, set them up
|
||||
if not entry.options:
|
||||
params["options"] = {
|
||||
|
@ -206,7 +206,7 @@ class ClimaCellDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
|
||||
async def _async_update_data(self) -> dict[str, Any]:
|
||||
"""Update data via library."""
|
||||
data = {FORECASTS: {}}
|
||||
data: dict[str, Any] = {FORECASTS: {}}
|
||||
try:
|
||||
if self._api_version == 3:
|
||||
data[CURRENT] = await self._api.realtime(
|
||||
|
|
|
@ -28,6 +28,8 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up a config entry."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
api_class: type[BaseClimaCellSensorEntity]
|
||||
sensor_types: tuple[ClimaCellSensorEntityDescription, ...]
|
||||
|
||||
if (api_version := config_entry.data[CONF_API_VERSION]) == 3:
|
||||
api_class = ClimaCellV3SensorEntity
|
||||
|
@ -81,6 +83,7 @@ class BaseClimaCellSensorEntity(ClimaCellEntity, SensorEntity):
|
|||
state = self._state
|
||||
if (
|
||||
state is not None
|
||||
and not isinstance(state, str)
|
||||
and self.entity_description.unit_imperial is not None
|
||||
and self.entity_description.metric_conversion != 1.0
|
||||
and self.entity_description.is_metric_check is not None
|
||||
|
@ -95,7 +98,8 @@ class BaseClimaCellSensorEntity(ClimaCellEntity, SensorEntity):
|
|||
return round(state * conversion, 4)
|
||||
|
||||
if self.entity_description.value_map is not None and state is not None:
|
||||
return self.entity_description.value_map(state).name.lower()
|
||||
# mypy bug: "Literal[IntEnum.value]" not callable
|
||||
return self.entity_description.value_map(state).name.lower() # type: ignore[misc]
|
||||
|
||||
return state
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
from abc import abstractmethod
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from pyclimacell.const import (
|
||||
CURRENT,
|
||||
|
@ -136,7 +136,7 @@ class BaseClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
|
|||
@staticmethod
|
||||
@abstractmethod
|
||||
def _translate_condition(
|
||||
condition: int | None, sun_is_up: bool = True
|
||||
condition: str | int | None, sun_is_up: bool = True
|
||||
) -> str | None:
|
||||
"""Translate ClimaCell condition into an HA condition."""
|
||||
|
||||
|
@ -144,7 +144,7 @@ class BaseClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
|
|||
self,
|
||||
forecast_dt: datetime,
|
||||
use_datetime: bool,
|
||||
condition: str,
|
||||
condition: int | str,
|
||||
precipitation: float | None,
|
||||
precipitation_probability: float | None,
|
||||
temp: float | None,
|
||||
|
@ -274,7 +274,7 @@ class ClimaCellWeatherEntity(BaseClimaCellWeatherEntity):
|
|||
|
||||
@staticmethod
|
||||
def _translate_condition(
|
||||
condition: int | None, sun_is_up: bool = True
|
||||
condition: int | str | None, sun_is_up: bool = True
|
||||
) -> str | None:
|
||||
"""Translate ClimaCell condition into an HA condition."""
|
||||
if condition is None:
|
||||
|
@ -422,11 +422,12 @@ class ClimaCellV3WeatherEntity(BaseClimaCellWeatherEntity):
|
|||
|
||||
@staticmethod
|
||||
def _translate_condition(
|
||||
condition: str | None, sun_is_up: bool = True
|
||||
condition: int | str | None, sun_is_up: bool = True
|
||||
) -> str | None:
|
||||
"""Translate ClimaCell condition into an HA condition."""
|
||||
if not condition:
|
||||
return None
|
||||
condition = cast(str, condition)
|
||||
if "clear" in condition.lower():
|
||||
if sun_is_up:
|
||||
return CLEAR_CONDITIONS["day"]
|
||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -1711,6 +1711,9 @@ ignore_errors = true
|
|||
[mypy-homeassistant.components.climacell.*]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.cloud.*]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.config.*]
|
||||
ignore_errors = true
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ from .model import Config, Integration
|
|||
IGNORED_MODULES: Final[list[str]] = [
|
||||
"homeassistant.components.blueprint.*",
|
||||
"homeassistant.components.climacell.*",
|
||||
"homeassistant.components.cloud.*",
|
||||
"homeassistant.components.config.*",
|
||||
"homeassistant.components.conversation.*",
|
||||
"homeassistant.components.deconz.*",
|
||||
|
|
Loading…
Reference in New Issue