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:
parent
ea6504dfa2
commit
a852b6df66
4 changed files with 57 additions and 44 deletions
|
@ -1,11 +1,18 @@
|
||||||
"""Support for Velbus Binary Sensors."""
|
"""Support for Velbus Binary Sensors."""
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
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 . import VelbusEntity
|
||||||
from .const import DOMAIN
|
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."""
|
"""Set up Velbus switch based on config_entry."""
|
||||||
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
||||||
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
||||||
|
|
|
@ -7,13 +7,20 @@ from homeassistant.components.climate.const import (
|
||||||
SUPPORT_PRESET_MODE,
|
SUPPORT_PRESET_MODE,
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
from . import VelbusEntity
|
||||||
from .const import DOMAIN, PRESET_MODES
|
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."""
|
"""Set up Velbus switch based on config_entry."""
|
||||||
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
||||||
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
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):
|
class VelbusClimate(VelbusEntity, ClimateEntity):
|
||||||
"""Representation of a Velbus thermostat."""
|
"""Representation of a Velbus thermostat."""
|
||||||
|
|
||||||
@property
|
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||||
def supported_features(self) -> int:
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
"""Return the list off supported features."""
|
_attr_hvac_mode = HVAC_MODE_HEAT
|
||||||
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
_attr_hvac_modes = [HVAC_MODE_HEAT]
|
||||||
|
_attr_preset_modes = list(PRESET_MODES)
|
||||||
@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]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self) -> int | None:
|
def target_temperature(self) -> int | None:
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
return self._channel.get_climate_target()
|
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
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
"""Return the current Preset for this channel."""
|
"""Return the current Preset for this channel."""
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
"""Support for Velbus covers."""
|
"""Support for Velbus covers."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from velbusaio.channels import Channel as VelbusChannel
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
SUPPORT_CLOSE,
|
SUPPORT_CLOSE,
|
||||||
|
@ -7,12 +13,19 @@ from homeassistant.components.cover import (
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
from . import VelbusEntity
|
||||||
from .const import DOMAIN
|
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."""
|
"""Set up Velbus switch based on config_entry."""
|
||||||
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
||||||
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
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):
|
class VelbusCover(VelbusEntity, CoverEntity):
|
||||||
"""Representation a Velbus cover."""
|
"""Representation a Velbus cover."""
|
||||||
|
|
||||||
@property
|
def __init__(self, channel: VelbusChannel) -> None:
|
||||||
def supported_features(self):
|
"""Initialize the dimmer."""
|
||||||
"""Flag supported features."""
|
super().__init__(channel)
|
||||||
if self._channel.support_position():
|
if self._channel.support_position():
|
||||||
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
|
self._attr_supported_features = (
|
||||||
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self) -> bool | None:
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
return self._channel.is_closed()
|
return self._channel.is_closed()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self) -> int | None:
|
||||||
"""Return current position of cover.
|
"""Return current position of cover.
|
||||||
|
|
||||||
None is unknown, 0 is closed, 100 is fully open
|
None is unknown, 0 is closed, 100 is fully open
|
||||||
|
@ -47,18 +63,18 @@ class VelbusCover(VelbusEntity, CoverEntity):
|
||||||
pos = self._channel.get_position()
|
pos = self._channel.get_position()
|
||||||
return 100 - pos
|
return 100 - pos
|
||||||
|
|
||||||
async def async_open_cover(self, **kwargs):
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
await self._channel.open()
|
await self._channel.open()
|
||||||
|
|
||||||
async def async_close_cover(self, **kwargs):
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover."""
|
"""Close the cover."""
|
||||||
await self._channel.close()
|
await self._channel.close()
|
||||||
|
|
||||||
async def async_stop_cover(self, **kwargs):
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
await self._channel.stop()
|
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."""
|
"""Move the cover to a specific position."""
|
||||||
self._channel.set_position(100 - kwargs[ATTR_POSITION])
|
self._channel.set_position(100 - kwargs[ATTR_POSITION])
|
||||||
|
|
|
@ -2,12 +2,19 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
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 . import VelbusEntity
|
||||||
from .const import DOMAIN
|
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."""
|
"""Set up Velbus switch based on config_entry."""
|
||||||
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
||||||
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue