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 <marhje52@gmail.com>

* Update homeassistant/components/velbus/cover.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/velbus/cover.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/velbus/cover.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/velbus/cover.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/velbus/cover.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Maikel Punie 2021-11-04 14:37:44 +01:00 committed by GitHub
parent ea6504dfa2
commit a852b6df66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 44 deletions

View file

@ -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"]

View file

@ -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."""

View file

@ -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])

View file

@ -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"]