Enable basic type checking for climate (#52470)

* Enable basic type checking for climate

* Tweak
pull/52484/head
Erik Montnemery 2021-07-03 17:06:12 +02:00 committed by GitHub
parent f52d838b7a
commit 44b44b5bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View File

@ -19,7 +19,7 @@ from homeassistant.const import (
STATE_ON,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import ( # noqa: F401
PLATFORM_SCHEMA,
@ -29,7 +29,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent
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 .const import (
@ -248,7 +248,7 @@ class ClimateEntity(Entity):
def state_attributes(self) -> dict[str, Any]:
"""Return the optional state attributes."""
supported_features = self.supported_features
data = {
data: dict[str, str | float | None] = {
ATTR_CURRENT_TEMPERATURE: show_temp(
self.hass,
self.current_temperature,
@ -498,7 +498,7 @@ class ClimateEntity(Entity):
"""Turn the entity on."""
if hasattr(self, "turn_on"):
# 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
# Fake turn on
@ -512,7 +512,7 @@ class ClimateEntity(Entity):
"""Turn the entity off."""
if hasattr(self, "turn_off"):
# 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
# Fake turn off
@ -554,23 +554,23 @@ class ClimateEntity(Entity):
async def async_service_aux_heat(
entity: ClimateEntity, service: ServiceDataType
entity: ClimateEntity, service_call: ServiceCall
) -> None:
"""Handle aux heat service."""
if service.data[ATTR_AUX_HEAT]:
if service_call.data[ATTR_AUX_HEAT]:
await entity.async_turn_aux_heat_on()
else:
await entity.async_turn_aux_heat_off()
async def async_service_temperature_set(
entity: ClimateEntity, service: ServiceDataType
entity: ClimateEntity, service_call: ServiceCall
) -> None:
"""Handle set temperature service."""
hass = entity.hass
kwargs = {}
for value, temp in service.data.items():
for value, temp in service_call.data.items():
if value in CONVERTIBLE_ATTRIBUTE:
kwargs[value] = convert_temperature(
temp, hass.config.units.temperature_unit, entity.temperature_unit

View File

@ -85,7 +85,7 @@ def async_condition_from_config(
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
"""Test if an entity is a certain state."""
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

View File

@ -1058,9 +1058,6 @@ ignore_errors = true
[mypy-homeassistant.components.climacell.*]
ignore_errors = true
[mypy-homeassistant.components.climate.*]
ignore_errors = true
[mypy-homeassistant.components.cloud.*]
ignore_errors = true

View File

@ -33,7 +33,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.cast.*",
"homeassistant.components.cert_expiry.*",
"homeassistant.components.climacell.*",
"homeassistant.components.climate.*",
"homeassistant.components.cloud.*",
"homeassistant.components.cloudflare.*",
"homeassistant.components.config.*",