mirror of
https://github.com/home-assistant/core
synced 2024-07-21 10:44:07 +00:00
Enable basic type checking for climacell (#55334)
This commit is contained in:
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."""
|
"""Set up ClimaCell API from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
params = {}
|
params: dict[str, Any] = {}
|
||||||
# If config entry options not set up, set them up
|
# If config entry options not set up, set them up
|
||||||
if not entry.options:
|
if not entry.options:
|
||||||
params["options"] = {
|
params["options"] = {
|
||||||
|
@ -206,7 +206,7 @@ class ClimaCellDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict[str, Any]:
|
async def _async_update_data(self) -> dict[str, Any]:
|
||||||
"""Update data via library."""
|
"""Update data via library."""
|
||||||
data = {FORECASTS: {}}
|
data: dict[str, Any] = {FORECASTS: {}}
|
||||||
try:
|
try:
|
||||||
if self._api_version == 3:
|
if self._api_version == 3:
|
||||||
data[CURRENT] = await self._api.realtime(
|
data[CURRENT] = await self._api.realtime(
|
||||||
|
|
|
@ -28,6 +28,8 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
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:
|
if (api_version := config_entry.data[CONF_API_VERSION]) == 3:
|
||||||
api_class = ClimaCellV3SensorEntity
|
api_class = ClimaCellV3SensorEntity
|
||||||
|
@ -81,6 +83,7 @@ class BaseClimaCellSensorEntity(ClimaCellEntity, SensorEntity):
|
||||||
state = self._state
|
state = self._state
|
||||||
if (
|
if (
|
||||||
state is not None
|
state is not None
|
||||||
|
and not isinstance(state, str)
|
||||||
and self.entity_description.unit_imperial is not None
|
and self.entity_description.unit_imperial is not None
|
||||||
and self.entity_description.metric_conversion != 1.0
|
and self.entity_description.metric_conversion != 1.0
|
||||||
and self.entity_description.is_metric_check is not None
|
and self.entity_description.is_metric_check is not None
|
||||||
|
@ -95,7 +98,8 @@ class BaseClimaCellSensorEntity(ClimaCellEntity, SensorEntity):
|
||||||
return round(state * conversion, 4)
|
return round(state * conversion, 4)
|
||||||
|
|
||||||
if self.entity_description.value_map is not None and state is not None:
|
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
|
return state
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
|
|
||||||
from pyclimacell.const import (
|
from pyclimacell.const import (
|
||||||
CURRENT,
|
CURRENT,
|
||||||
|
@ -136,7 +136,7 @@ class BaseClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _translate_condition(
|
def _translate_condition(
|
||||||
condition: int | None, sun_is_up: bool = True
|
condition: str | int | None, sun_is_up: bool = True
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Translate ClimaCell condition into an HA condition."""
|
"""Translate ClimaCell condition into an HA condition."""
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class BaseClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
|
||||||
self,
|
self,
|
||||||
forecast_dt: datetime,
|
forecast_dt: datetime,
|
||||||
use_datetime: bool,
|
use_datetime: bool,
|
||||||
condition: str,
|
condition: int | str,
|
||||||
precipitation: float | None,
|
precipitation: float | None,
|
||||||
precipitation_probability: float | None,
|
precipitation_probability: float | None,
|
||||||
temp: float | None,
|
temp: float | None,
|
||||||
|
@ -274,7 +274,7 @@ class ClimaCellWeatherEntity(BaseClimaCellWeatherEntity):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _translate_condition(
|
def _translate_condition(
|
||||||
condition: int | None, sun_is_up: bool = True
|
condition: int | str | None, sun_is_up: bool = True
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Translate ClimaCell condition into an HA condition."""
|
"""Translate ClimaCell condition into an HA condition."""
|
||||||
if condition is None:
|
if condition is None:
|
||||||
|
@ -422,11 +422,12 @@ class ClimaCellV3WeatherEntity(BaseClimaCellWeatherEntity):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _translate_condition(
|
def _translate_condition(
|
||||||
condition: str | None, sun_is_up: bool = True
|
condition: int | str | None, sun_is_up: bool = True
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Translate ClimaCell condition into an HA condition."""
|
"""Translate ClimaCell condition into an HA condition."""
|
||||||
if not condition:
|
if not condition:
|
||||||
return None
|
return None
|
||||||
|
condition = cast(str, condition)
|
||||||
if "clear" in condition.lower():
|
if "clear" in condition.lower():
|
||||||
if sun_is_up:
|
if sun_is_up:
|
||||||
return CLEAR_CONDITIONS["day"]
|
return CLEAR_CONDITIONS["day"]
|
||||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -1711,6 +1711,9 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.climacell.*]
|
[mypy-homeassistant.components.climacell.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.cloud.*]
|
||||||
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.config.*]
|
[mypy-homeassistant.components.config.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .model import Config, Integration
|
||||||
IGNORED_MODULES: Final[list[str]] = [
|
IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.blueprint.*",
|
"homeassistant.components.blueprint.*",
|
||||||
"homeassistant.components.climacell.*",
|
"homeassistant.components.climacell.*",
|
||||||
|
"homeassistant.components.cloud.*",
|
||||||
"homeassistant.components.config.*",
|
"homeassistant.components.config.*",
|
||||||
"homeassistant.components.conversation.*",
|
"homeassistant.components.conversation.*",
|
||||||
"homeassistant.components.deconz.*",
|
"homeassistant.components.deconz.*",
|
||||||
|
|
Loading…
Reference in a new issue