From a852b6df6679e66d905f87eac40b4032d725f4f1 Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Thu, 4 Nov 2021 14:37:44 +0100 Subject: [PATCH] Add typing info to velbus (part 1) (#59041) * Add typing info to velbus (part 1) * Fix pylint * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/velbus/cover.py Co-authored-by: Martin Hjelmare Co-authored-by: Martin Hjelmare --- .../components/velbus/binary_sensor.py | 9 +++- homeassistant/components/velbus/climate.py | 43 ++++++------------- homeassistant/components/velbus/cover.py | 40 +++++++++++------ homeassistant/components/velbus/switch.py | 9 +++- 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/homeassistant/components/velbus/binary_sensor.py b/homeassistant/components/velbus/binary_sensor.py index be5d8d24698..014b1410fdc 100644 --- a/homeassistant/components/velbus/binary_sensor.py +++ b/homeassistant/components/velbus/binary_sensor.py @@ -1,11 +1,18 @@ """Support for Velbus Binary Sensors.""" from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import VelbusEntity from .const import DOMAIN -async def async_setup_entry(hass, entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"] diff --git a/homeassistant/components/velbus/climate.py b/homeassistant/components/velbus/climate.py index 6bc848a92ab..a065679c4e5 100644 --- a/homeassistant/components/velbus/climate.py +++ b/homeassistant/components/velbus/climate.py @@ -7,13 +7,20 @@ from homeassistant.components.climate.const import ( SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, ) +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import VelbusEntity from .const import DOMAIN, PRESET_MODES -async def async_setup_entry(hass, entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"] @@ -26,41 +33,17 @@ async def async_setup_entry(hass, entry, async_add_entities): class VelbusClimate(VelbusEntity, ClimateEntity): """Representation of a Velbus thermostat.""" - @property - def supported_features(self) -> int: - """Return the list off supported features.""" - return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - - @property - def temperature_unit(self) -> str: - """Return the unit.""" - return TEMP_CELSIUS - - @property - def current_temperature(self) -> int | None: - """Return the current temperature.""" - return self._channel.get_state() - - @property - def hvac_mode(self) -> str: - """Return hvac operation ie. heat, cool mode.""" - return HVAC_MODE_HEAT - - @property - def hvac_modes(self) -> list[str]: - """Return the list of available hvac operation modes.""" - return [HVAC_MODE_HEAT] + _attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE + _attr_temperature_unit = TEMP_CELSIUS + _attr_hvac_mode = HVAC_MODE_HEAT + _attr_hvac_modes = [HVAC_MODE_HEAT] + _attr_preset_modes = list(PRESET_MODES) @property def target_temperature(self) -> int | None: """Return the temperature we try to reach.""" return self._channel.get_climate_target() - @property - def preset_modes(self) -> list[str] | None: - """Return a list of all possible presets.""" - return list(PRESET_MODES) - @property def preset_mode(self) -> str | None: """Return the current Preset for this channel.""" diff --git a/homeassistant/components/velbus/cover.py b/homeassistant/components/velbus/cover.py index 53fd32fad34..43cec0adb24 100644 --- a/homeassistant/components/velbus/cover.py +++ b/homeassistant/components/velbus/cover.py @@ -1,4 +1,10 @@ """Support for Velbus covers.""" +from __future__ import annotations + +from typing import Any + +from velbusaio.channels import Channel as VelbusChannel + from homeassistant.components.cover import ( ATTR_POSITION, SUPPORT_CLOSE, @@ -7,12 +13,19 @@ from homeassistant.components.cover import ( SUPPORT_STOP, CoverEntity, ) +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import VelbusEntity from .const import DOMAIN -async def async_setup_entry(hass, entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"] @@ -25,20 +38,23 @@ async def async_setup_entry(hass, entry, async_add_entities): class VelbusCover(VelbusEntity, CoverEntity): """Representation a Velbus cover.""" - @property - def supported_features(self): - """Flag supported features.""" + def __init__(self, channel: VelbusChannel) -> None: + """Initialize the dimmer.""" + super().__init__(channel) if self._channel.support_position(): - return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION - return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP + self._attr_supported_features = ( + SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION + ) + else: + self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP @property - def is_closed(self): + def is_closed(self) -> bool | None: """Return if the cover is closed.""" return self._channel.is_closed() @property - def current_cover_position(self): + def current_cover_position(self) -> int | None: """Return current position of cover. None is unknown, 0 is closed, 100 is fully open @@ -47,18 +63,18 @@ class VelbusCover(VelbusEntity, CoverEntity): pos = self._channel.get_position() return 100 - pos - async def async_open_cover(self, **kwargs): + async def async_open_cover(self, **kwargs: Any) -> None: """Open the cover.""" await self._channel.open() - async def async_close_cover(self, **kwargs): + async def async_close_cover(self, **kwargs: Any) -> None: """Close the cover.""" await self._channel.close() - async def async_stop_cover(self, **kwargs): + async def async_stop_cover(self, **kwargs: Any) -> None: """Stop the cover.""" await self._channel.stop() - async def async_set_cover_position(self, **kwargs): + async def async_set_cover_position(self, **kwargs: Any) -> None: """Move the cover to a specific position.""" self._channel.set_position(100 - kwargs[ATTR_POSITION]) diff --git a/homeassistant/components/velbus/switch.py b/homeassistant/components/velbus/switch.py index 70c7e1eb457..c7b4a80f196 100644 --- a/homeassistant/components/velbus/switch.py +++ b/homeassistant/components/velbus/switch.py @@ -2,12 +2,19 @@ from typing import Any from homeassistant.components.switch import SwitchEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import VelbusEntity from .const import DOMAIN -async def async_setup_entry(hass, entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]