Enable basic type checking for climate (#52470)
* Enable basic type checking for climate * Tweak
This commit is contained in:
parent
f52d838b7a
commit
44b44b5bd6
4 changed files with 10 additions and 14 deletions
|
@ -19,7 +19,7 @@ from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import ( # noqa: F401
|
from homeassistant.helpers.config_validation import ( # noqa: F401
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
@ -29,7 +29,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.temperature import display_temp as show_temp
|
from homeassistant.helpers.temperature import display_temp as show_temp
|
||||||
from homeassistant.helpers.typing import ConfigType, ServiceDataType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -248,7 +248,7 @@ class ClimateEntity(Entity):
|
||||||
def state_attributes(self) -> dict[str, Any]:
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the optional state attributes."""
|
"""Return the optional state attributes."""
|
||||||
supported_features = self.supported_features
|
supported_features = self.supported_features
|
||||||
data = {
|
data: dict[str, str | float | None] = {
|
||||||
ATTR_CURRENT_TEMPERATURE: show_temp(
|
ATTR_CURRENT_TEMPERATURE: show_temp(
|
||||||
self.hass,
|
self.hass,
|
||||||
self.current_temperature,
|
self.current_temperature,
|
||||||
|
@ -498,7 +498,7 @@ class ClimateEntity(Entity):
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
if hasattr(self, "turn_on"):
|
if hasattr(self, "turn_on"):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
await self.hass.async_add_executor_job(self.turn_on)
|
await self.hass.async_add_executor_job(self.turn_on) # type: ignore[attr-defined]
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fake turn on
|
# Fake turn on
|
||||||
|
@ -512,7 +512,7 @@ class ClimateEntity(Entity):
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
if hasattr(self, "turn_off"):
|
if hasattr(self, "turn_off"):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
await self.hass.async_add_executor_job(self.turn_off)
|
await self.hass.async_add_executor_job(self.turn_off) # type: ignore[attr-defined]
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fake turn off
|
# Fake turn off
|
||||||
|
@ -554,23 +554,23 @@ class ClimateEntity(Entity):
|
||||||
|
|
||||||
|
|
||||||
async def async_service_aux_heat(
|
async def async_service_aux_heat(
|
||||||
entity: ClimateEntity, service: ServiceDataType
|
entity: ClimateEntity, service_call: ServiceCall
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle aux heat service."""
|
"""Handle aux heat service."""
|
||||||
if service.data[ATTR_AUX_HEAT]:
|
if service_call.data[ATTR_AUX_HEAT]:
|
||||||
await entity.async_turn_aux_heat_on()
|
await entity.async_turn_aux_heat_on()
|
||||||
else:
|
else:
|
||||||
await entity.async_turn_aux_heat_off()
|
await entity.async_turn_aux_heat_off()
|
||||||
|
|
||||||
|
|
||||||
async def async_service_temperature_set(
|
async def async_service_temperature_set(
|
||||||
entity: ClimateEntity, service: ServiceDataType
|
entity: ClimateEntity, service_call: ServiceCall
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle set temperature service."""
|
"""Handle set temperature service."""
|
||||||
hass = entity.hass
|
hass = entity.hass
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
for value, temp in service.data.items():
|
for value, temp in service_call.data.items():
|
||||||
if value in CONVERTIBLE_ATTRIBUTE:
|
if value in CONVERTIBLE_ATTRIBUTE:
|
||||||
kwargs[value] = convert_temperature(
|
kwargs[value] = convert_temperature(
|
||||||
temp, hass.config.units.temperature_unit, entity.temperature_unit
|
temp, hass.config.units.temperature_unit, entity.temperature_unit
|
||||||
|
|
|
@ -85,7 +85,7 @@ def async_condition_from_config(
|
||||||
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
|
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
|
||||||
"""Test if an entity is a certain state."""
|
"""Test if an entity is a certain state."""
|
||||||
state = hass.states.get(config[ATTR_ENTITY_ID])
|
state = hass.states.get(config[ATTR_ENTITY_ID])
|
||||||
return state and state.attributes.get(attribute) == config[attribute]
|
return state.attributes.get(attribute) == config[attribute] if state else False
|
||||||
|
|
||||||
return test_is_state
|
return test_is_state
|
||||||
|
|
||||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -1058,9 +1058,6 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.climacell.*]
|
[mypy-homeassistant.components.climacell.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.climate.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.cloud.*]
|
[mypy-homeassistant.components.cloud.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.cast.*",
|
"homeassistant.components.cast.*",
|
||||||
"homeassistant.components.cert_expiry.*",
|
"homeassistant.components.cert_expiry.*",
|
||||||
"homeassistant.components.climacell.*",
|
"homeassistant.components.climacell.*",
|
||||||
"homeassistant.components.climate.*",
|
|
||||||
"homeassistant.components.cloud.*",
|
"homeassistant.components.cloud.*",
|
||||||
"homeassistant.components.cloudflare.*",
|
"homeassistant.components.cloudflare.*",
|
||||||
"homeassistant.components.config.*",
|
"homeassistant.components.config.*",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue