Improve type hints in mqtt (#74295)
parent
6f67ae1dfc
commit
64bfa20f6a
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import functools
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -754,29 +755,29 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
if self._config.get(CONF_TEMPERATURE_UNIT):
|
||||
return self._config.get(CONF_TEMPERATURE_UNIT)
|
||||
if unit := self._config.get(CONF_TEMPERATURE_UNIT):
|
||||
return unit
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
def current_temperature(self) -> float | None:
|
||||
"""Return the current temperature."""
|
||||
return self._current_temp
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
def target_temperature(self) -> float | None:
|
||||
"""Return the temperature we try to reach."""
|
||||
return self._target_temp
|
||||
|
||||
@property
|
||||
def target_temperature_low(self):
|
||||
def target_temperature_low(self) -> float | None:
|
||||
"""Return the low target temperature we try to reach."""
|
||||
return self._target_temp_low
|
||||
|
||||
@property
|
||||
def target_temperature_high(self):
|
||||
def target_temperature_high(self) -> float | None:
|
||||
"""Return the high target temperature we try to reach."""
|
||||
return self._target_temp_high
|
||||
|
||||
|
@ -796,7 +797,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
return self._config[CONF_MODE_LIST]
|
||||
|
||||
@property
|
||||
def target_temperature_step(self):
|
||||
def target_temperature_step(self) -> float:
|
||||
"""Return the supported step of target temperature."""
|
||||
return self._config[CONF_TEMP_STEP]
|
||||
|
||||
|
@ -813,7 +814,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
return PRESET_NONE
|
||||
|
||||
@property
|
||||
def preset_modes(self) -> list:
|
||||
def preset_modes(self) -> list[str]:
|
||||
"""Return preset modes."""
|
||||
presets = []
|
||||
presets.extend(self._preset_modes)
|
||||
|
@ -834,17 +835,17 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
return presets
|
||||
|
||||
@property
|
||||
def is_aux_heat(self):
|
||||
def is_aux_heat(self) -> bool | None:
|
||||
"""Return true if away mode is on."""
|
||||
return self._aux
|
||||
|
||||
@property
|
||||
def fan_mode(self):
|
||||
def fan_mode(self) -> str | None:
|
||||
"""Return the fan setting."""
|
||||
return self._current_fan_mode
|
||||
|
||||
@property
|
||||
def fan_modes(self):
|
||||
def fan_modes(self) -> list[str]:
|
||||
"""Return the list of available fan modes."""
|
||||
return self._config[CONF_FAN_MODE_LIST]
|
||||
|
||||
|
@ -871,10 +872,9 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
payload = self._command_templates[cmnd_template](temp)
|
||||
await self._publish(cmnd_topic, payload)
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperatures."""
|
||||
if kwargs.get(ATTR_HVAC_MODE) is not None:
|
||||
operation_mode = kwargs.get(ATTR_HVAC_MODE)
|
||||
if (operation_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
|
||||
await self.async_set_hvac_mode(operation_mode)
|
||||
|
||||
await self._set_temperature(
|
||||
|
@ -904,7 +904,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
# Always optimistic?
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_swing_mode(self, swing_mode):
|
||||
async def async_set_swing_mode(self, swing_mode: str) -> None:
|
||||
"""Set new swing mode."""
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if self._send_if_off or self._current_operation != HVACMode.OFF:
|
||||
|
@ -917,7 +917,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
self._current_swing_mode = swing_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode):
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set new target temperature."""
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if self._send_if_off or self._current_operation != HVACMode.OFF:
|
||||
|
@ -928,7 +928,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
self._current_fan_mode = fan_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set new operation mode."""
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
await self._publish(
|
||||
|
@ -945,12 +945,12 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def swing_mode(self):
|
||||
def swing_mode(self) -> str | None:
|
||||
"""Return the swing setting."""
|
||||
return self._current_swing_mode
|
||||
|
||||
@property
|
||||
def swing_modes(self):
|
||||
def swing_modes(self) -> list[str]:
|
||||
"""List of available swing modes."""
|
||||
return self._config[CONF_SWING_MODE_LIST]
|
||||
|
||||
|
@ -1027,16 +1027,16 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
self._aux = state
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_aux_heat_on(self):
|
||||
async def async_turn_aux_heat_on(self) -> None:
|
||||
"""Turn auxiliary heater on."""
|
||||
await self._set_aux_heat(True)
|
||||
|
||||
async def async_turn_aux_heat_off(self):
|
||||
async def async_turn_aux_heat_off(self) -> None:
|
||||
"""Turn auxiliary heater off."""
|
||||
await self._set_aux_heat(False)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
support = 0
|
||||
|
||||
|
@ -1083,18 +1083,18 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
return support
|
||||
|
||||
@property
|
||||
def min_temp(self):
|
||||
def min_temp(self) -> float:
|
||||
"""Return the minimum temperature."""
|
||||
return self._config[CONF_TEMP_MIN]
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
def max_temp(self) -> float:
|
||||
"""Return the maximum temperature."""
|
||||
return self._config[CONF_TEMP_MAX]
|
||||
|
||||
@property
|
||||
def precision(self):
|
||||
def precision(self) -> float:
|
||||
"""Return the precision of the system."""
|
||||
if self._config.get(CONF_PRECISION) is not None:
|
||||
return self._config.get(CONF_PRECISION)
|
||||
if (precision := self._config.get(CONF_PRECISION)) is not None:
|
||||
return precision
|
||||
return super().precision
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import functools
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -407,7 +408,7 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
|
|||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
||||
|
@ -431,10 +432,7 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
|
|||
"""Return the current mode."""
|
||||
return self._mode
|
||||
|
||||
async def async_turn_on(
|
||||
self,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on the entity.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -451,7 +449,7 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
|
|||
self._state = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off the entity.
|
||||
|
||||
This method is a coroutine.
|
||||
|
|
|
@ -355,7 +355,7 @@ class MqttAttributes(Entity):
|
|||
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""Initialize the JSON attributes mixin."""
|
||||
self._attributes: dict | None = None
|
||||
self._attributes: dict[str, Any] | None = None
|
||||
self._attributes_sub_state = None
|
||||
self._attributes_config = config
|
||||
|
||||
|
@ -426,7 +426,7 @@ class MqttAttributes(Entity):
|
|||
)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return the state attributes."""
|
||||
return self._attributes
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.number import (
|
|||
DEFAULT_MIN_VALUE,
|
||||
DEFAULT_STEP,
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
NumberDeviceClass,
|
||||
RestoreNumber,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -292,11 +293,11 @@ class MqttNumber(MqttEntity, RestoreNumber):
|
|||
)
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
def device_class(self) -> NumberDeviceClass | None:
|
||||
"""Return the device class of the sensor."""
|
||||
return self._config.get(CONF_DEVICE_CLASS)
|
||||
|
|
|
@ -211,6 +211,6 @@ class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
|
|
@ -347,7 +347,7 @@ class MqttSensor(MqttEntity, RestoreSensor):
|
|||
return self._config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
|
||||
@property
|
||||
def force_update(self):
|
||||
def force_update(self) -> bool:
|
||||
"""Force update."""
|
||||
return self._config[CONF_FORCE_UPDATE]
|
||||
|
||||
|
|
|
@ -309,12 +309,12 @@ class MqttSiren(MqttEntity, SirenEntity):
|
|||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the state attributes."""
|
||||
mqtt_attributes = super().extra_state_attributes
|
||||
attributes = (
|
||||
|
@ -353,7 +353,7 @@ class MqttSiren(MqttEntity, SirenEntity):
|
|||
self._config[CONF_ENCODING],
|
||||
)
|
||||
|
||||
async def async_turn_on(self, **kwargs) -> None:
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the siren on.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -371,7 +371,7 @@ class MqttSiren(MqttEntity, SirenEntity):
|
|||
self._update(kwargs)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the siren off.
|
||||
|
||||
This method is a coroutine.
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import switch
|
||||
from homeassistant.components.switch import DEVICE_CLASSES_SCHEMA, SwitchEntity
|
||||
from homeassistant.components.switch import (
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
SwitchDeviceClass,
|
||||
SwitchEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
|
@ -195,16 +200,16 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
|||
return self._state
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
def device_class(self) -> SwitchDeviceClass | None:
|
||||
"""Return the device class of the sensor."""
|
||||
return self._config.get(CONF_DEVICE_CLASS)
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -221,7 +226,7 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
|||
self._state = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off.
|
||||
|
||||
This method is a coroutine.
|
||||
|
|
Loading…
Reference in New Issue