Improve type hints in demo (#74236)
This commit is contained in:
parent
fdb7a23171
commit
57fd84e20c
6 changed files with 82 additions and 73 deletions
|
@ -73,7 +73,7 @@ class DemoBinarySensor(BinarySensorEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique id."""
|
||||
return self._unique_id
|
||||
|
||||
|
@ -83,16 +83,16 @@ class DemoBinarySensor(BinarySensorEntity):
|
|||
return self._sensor_type
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed for a demo binary sensor."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self._state
|
||||
|
|
|
@ -72,7 +72,12 @@ class DemoCalendar(CalendarEntity):
|
|||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
async def async_get_events(self, hass, start_date, end_date) -> list[CalendarEvent]:
|
||||
async def async_get_events(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
start_date: datetime.datetime,
|
||||
end_date: datetime.datetime,
|
||||
) -> list[CalendarEvent]:
|
||||
"""Return calendar events within a datetime range."""
|
||||
return [self._event]
|
||||
|
||||
|
@ -80,15 +85,15 @@ class DemoCalendar(CalendarEntity):
|
|||
class LegacyDemoCalendar(CalendarEventDevice):
|
||||
"""Calendar for exercising shim API."""
|
||||
|
||||
def __init__(self, name):
|
||||
def __init__(self, name: str) -> None:
|
||||
"""Initialize demo calendar."""
|
||||
self._name = name
|
||||
one_hour_from_now = dt_util.now() + dt_util.dt.timedelta(minutes=30)
|
||||
one_hour_from_now = dt_util.now() + datetime.timedelta(minutes=30)
|
||||
self._event = {
|
||||
"start": {"dateTime": one_hour_from_now.isoformat()},
|
||||
"end": {
|
||||
"dateTime": (
|
||||
one_hour_from_now + dt_util.dt.timedelta(minutes=60)
|
||||
one_hour_from_now + datetime.timedelta(minutes=60)
|
||||
).isoformat()
|
||||
},
|
||||
"summary": "Future Event",
|
||||
|
@ -102,7 +107,7 @@ class LegacyDemoCalendar(CalendarEventDevice):
|
|||
return self._event
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
|
|
|
@ -58,23 +58,23 @@ class DemoCamera(Camera):
|
|||
|
||||
return await self.hass.async_add_executor_job(image_path.read_bytes)
|
||||
|
||||
async def async_enable_motion_detection(self):
|
||||
async def async_enable_motion_detection(self) -> None:
|
||||
"""Enable the Motion detection in base station (Arm)."""
|
||||
self._attr_motion_detection_enabled = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_disable_motion_detection(self):
|
||||
async def async_disable_motion_detection(self) -> None:
|
||||
"""Disable the motion detection in base station (Disarm)."""
|
||||
self._attr_motion_detection_enabled = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self):
|
||||
async def async_turn_off(self) -> None:
|
||||
"""Turn off camera."""
|
||||
self._attr_is_streaming = False
|
||||
self._attr_is_on = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_on(self):
|
||||
async def async_turn_on(self) -> None:
|
||||
"""Turn on camera."""
|
||||
self._attr_is_streaming = True
|
||||
self._attr_is_on = True
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Demo platform that offers a fake climate device."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
|
@ -103,24 +105,24 @@ class DemoClimate(ClimateEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
unique_id,
|
||||
name,
|
||||
target_temperature,
|
||||
unit_of_measurement,
|
||||
preset,
|
||||
current_temperature,
|
||||
fan_mode,
|
||||
target_humidity,
|
||||
current_humidity,
|
||||
swing_mode,
|
||||
hvac_mode,
|
||||
hvac_action,
|
||||
aux,
|
||||
target_temp_high,
|
||||
target_temp_low,
|
||||
hvac_modes,
|
||||
preset_modes=None,
|
||||
):
|
||||
unique_id: str,
|
||||
name: str,
|
||||
target_temperature: float | None,
|
||||
unit_of_measurement: str,
|
||||
preset: str | None,
|
||||
current_temperature: float,
|
||||
fan_mode: str | None,
|
||||
target_humidity: int | None,
|
||||
current_humidity: int | None,
|
||||
swing_mode: str | None,
|
||||
hvac_mode: HVACMode,
|
||||
hvac_action: HVACAction | None,
|
||||
aux: bool | None,
|
||||
target_temp_high: float | None,
|
||||
target_temp_low: float | None,
|
||||
hvac_modes: list[HVACMode],
|
||||
preset_modes: list[str] | None = None,
|
||||
) -> None:
|
||||
"""Initialize the climate device."""
|
||||
self._unique_id = unique_id
|
||||
self._name = name
|
||||
|
@ -175,111 +177,111 @@ class DemoClimate(ClimateEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique id."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
return self._support_flags
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
def should_poll(self) -> bool:
|
||||
"""Return the polling state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the climate device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
def current_temperature(self) -> float:
|
||||
"""Return the current temperature."""
|
||||
return self._current_temperature
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
def target_temperature(self) -> float | None:
|
||||
"""Return the temperature we try to reach."""
|
||||
return self._target_temperature
|
||||
|
||||
@property
|
||||
def target_temperature_high(self):
|
||||
def target_temperature_high(self) -> float | None:
|
||||
"""Return the highbound target temperature we try to reach."""
|
||||
return self._target_temperature_high
|
||||
|
||||
@property
|
||||
def target_temperature_low(self):
|
||||
def target_temperature_low(self) -> float | None:
|
||||
"""Return the lowbound target temperature we try to reach."""
|
||||
return self._target_temperature_low
|
||||
|
||||
@property
|
||||
def current_humidity(self):
|
||||
def current_humidity(self) -> int | None:
|
||||
"""Return the current humidity."""
|
||||
return self._current_humidity
|
||||
|
||||
@property
|
||||
def target_humidity(self):
|
||||
def target_humidity(self) -> int | None:
|
||||
"""Return the humidity we try to reach."""
|
||||
return self._target_humidity
|
||||
|
||||
@property
|
||||
def hvac_action(self):
|
||||
def hvac_action(self) -> HVACAction | None:
|
||||
"""Return current operation ie. heat, cool, idle."""
|
||||
return self._hvac_action
|
||||
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""Return hvac target hvac state."""
|
||||
return self._hvac_mode
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
def hvac_modes(self) -> list[HVACMode]:
|
||||
"""Return the list of available operation modes."""
|
||||
return self._hvac_modes
|
||||
|
||||
@property
|
||||
def preset_mode(self):
|
||||
def preset_mode(self) -> str | None:
|
||||
"""Return preset mode."""
|
||||
return self._preset
|
||||
|
||||
@property
|
||||
def preset_modes(self):
|
||||
def preset_modes(self) -> list[str] | None:
|
||||
"""Return preset modes."""
|
||||
return self._preset_modes
|
||||
|
||||
@property
|
||||
def is_aux_heat(self):
|
||||
def is_aux_heat(self) -> bool | None:
|
||||
"""Return true if aux heat 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._fan_modes
|
||||
|
||||
@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._swing_modes
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperatures."""
|
||||
if kwargs.get(ATTR_TEMPERATURE) is not None:
|
||||
self._target_temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
|
@ -291,37 +293,37 @@ class DemoClimate(ClimateEntity):
|
|||
self._target_temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_humidity(self, humidity):
|
||||
async def async_set_humidity(self, humidity: int) -> None:
|
||||
"""Set new humidity level."""
|
||||
self._target_humidity = humidity
|
||||
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."""
|
||||
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 fan mode."""
|
||||
self._current_fan_mode = fan_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set new operation mode."""
|
||||
self._hvac_mode = hvac_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode):
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Update preset_mode on."""
|
||||
self._preset = preset_mode
|
||||
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."""
|
||||
self._aux = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_aux_heat_off(self):
|
||||
async def async_turn_aux_heat_off(self) -> None:
|
||||
"""Turn auxiliary heater off."""
|
||||
self._aux = False
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -5,6 +5,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from . import DOMAIN
|
||||
|
@ -29,7 +30,7 @@ class DemoConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Get the options flow for this handler."""
|
||||
return OptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_import(self, import_info):
|
||||
async def async_step_import(self, import_info) -> FlowResult:
|
||||
"""Set the config entry up from yaml."""
|
||||
return self.async_create_entry(title="Demo", data={})
|
||||
|
||||
|
@ -42,11 +43,11 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||
self.config_entry = config_entry
|
||||
self.options = dict(config_entry.options)
|
||||
|
||||
async def async_step_init(self, user_input=None):
|
||||
async def async_step_init(self, user_input=None) -> FlowResult:
|
||||
"""Manage the options."""
|
||||
return await self.async_step_options_1()
|
||||
|
||||
async def async_step_options_1(self, user_input=None):
|
||||
async def async_step_options_1(self, user_input=None) -> FlowResult:
|
||||
"""Manage the options."""
|
||||
if user_input is not None:
|
||||
self.options.update(user_input)
|
||||
|
@ -69,7 +70,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||
),
|
||||
)
|
||||
|
||||
async def async_step_options_2(self, user_input=None):
|
||||
async def async_step_options_2(self, user_input=None) -> FlowResult:
|
||||
"""Manage the options 2."""
|
||||
if user_input is not None:
|
||||
self.options.update(user_input)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
|
@ -107,18 +108,18 @@ class DemoLight(LightEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
unique_id,
|
||||
name,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
state,
|
||||
available=False,
|
||||
brightness=180,
|
||||
ct=None, # pylint: disable=invalid-name
|
||||
effect_list=None,
|
||||
effect_list: list[str] | None = None,
|
||||
effect=None,
|
||||
hs_color=None,
|
||||
rgbw_color=None,
|
||||
rgbww_color=None,
|
||||
supported_color_modes=None,
|
||||
supported_color_modes: set[ColorMode] | None = None,
|
||||
):
|
||||
"""Initialize the light."""
|
||||
self._available = True
|
||||
|
@ -169,7 +170,7 @@ class DemoLight(LightEntity):
|
|||
return self._name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return unique ID for light."""
|
||||
return self._unique_id
|
||||
|
||||
|
@ -211,7 +212,7 @@ class DemoLight(LightEntity):
|
|||
return self._ct
|
||||
|
||||
@property
|
||||
def effect_list(self) -> list:
|
||||
def effect_list(self) -> list[str] | None:
|
||||
"""Return the list of supported effects."""
|
||||
return self._effect_list
|
||||
|
||||
|
@ -231,11 +232,11 @@ class DemoLight(LightEntity):
|
|||
return self._features
|
||||
|
||||
@property
|
||||
def supported_color_modes(self) -> set | None:
|
||||
def supported_color_modes(self) -> set[ColorMode]:
|
||||
"""Flag supported color modes."""
|
||||
return self._color_modes
|
||||
|
||||
async def async_turn_on(self, **kwargs) -> None:
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the light on."""
|
||||
self._state = True
|
||||
|
||||
|
@ -269,7 +270,7 @@ class DemoLight(LightEntity):
|
|||
# Home Assistant about updates in our state ourselves.
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the light off."""
|
||||
self._state = False
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue