mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Clean up vera typings (#40143)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
a2cf09fb54
commit
00093faae2
@ -2,7 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import logging
|
import logging
|
||||||
from typing import Type
|
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar
|
||||||
|
|
||||||
import pyvera as veraApi
|
import pyvera as veraApi
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
@ -168,7 +168,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def map_vera_device(vera_device, remap):
|
def map_vera_device(vera_device: veraApi.VeraDevice, remap: List[int]) -> str:
|
||||||
"""Map vera classes to Home Assistant types."""
|
"""Map vera classes to Home Assistant types."""
|
||||||
|
|
||||||
type_map = {
|
type_map = {
|
||||||
@ -198,10 +198,13 @@ def map_vera_device(vera_device, remap):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraDevice(Entity):
|
DeviceType = TypeVar("DeviceType", bound=veraApi.VeraDevice)
|
||||||
|
|
||||||
|
|
||||||
|
class VeraDevice(Generic[DeviceType], Entity):
|
||||||
"""Representation of a Vera device entity."""
|
"""Representation of a Vera device entity."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(self, vera_device: DeviceType, controller_data: ControllerData):
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
self.vera_device = vera_device
|
self.vera_device = vera_device
|
||||||
self.controller = controller_data.controller
|
self.controller = controller_data.controller
|
||||||
@ -217,26 +220,26 @@ class VeraDevice(Entity):
|
|||||||
else:
|
else:
|
||||||
self._unique_id = f"vera_{controller_data.config_entry.unique_id}_{self.vera_device.vera_device_id}"
|
self._unique_id = f"vera_{controller_data.config_entry.unique_id}_{self.vera_device.vera_device_id}"
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to updates."""
|
"""Subscribe to updates."""
|
||||||
self.controller.register(self.vera_device, self._update_callback)
|
self.controller.register(self.vera_device, self._update_callback)
|
||||||
|
|
||||||
def _update_callback(self, _device):
|
def _update_callback(self, _device: DeviceType) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
self.schedule_update_ha_state(True)
|
self.schedule_update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self) -> bool:
|
||||||
"""Get polling requirement from vera device."""
|
"""Get polling requirement from vera device."""
|
||||||
return self.vera_device.should_poll
|
return self.vera_device.should_poll
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Return the state attributes of the device."""
|
"""Return the state attributes of the device."""
|
||||||
attr = {}
|
attr = {}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera binary sensors."""
|
"""Support for Vera binary sensors."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Callable, List, Optional
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as PLATFORM_DOMAIN,
|
||||||
@ -32,20 +34,22 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraBinarySensor(VeraDevice, BinarySensorEntity):
|
class VeraBinarySensor(VeraDevice[veraApi.VeraBinarySensor], BinarySensorEntity):
|
||||||
"""Representation of a Vera Binary Sensor."""
|
"""Representation of a Vera Binary Sensor."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraBinarySensor, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the binary_sensor."""
|
"""Initialize the binary_sensor."""
|
||||||
self._state = False
|
self._state = False
|
||||||
VeraDevice.__init__(self, vera_device, controller_data)
|
VeraDevice.__init__(self, vera_device, controller_data)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> Optional[bool]:
|
||||||
"""Return true if sensor is on."""
|
"""Return true if sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Get the latest data and update the state."""
|
"""Get the latest data and update the state."""
|
||||||
self._state = self.vera_device.is_tripped
|
self._state = self.vera_device.is_tripped
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera thermostats."""
|
"""Support for Vera thermostats."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Any, Callable, List, Optional
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as PLATFORM_DOMAIN,
|
||||||
@ -49,21 +51,23 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraThermostat(VeraDevice, ClimateEntity):
|
class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity):
|
||||||
"""Representation of a Vera Thermostat."""
|
"""Representation of a Vera Thermostat."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraThermostat, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
VeraDevice.__init__(self, vera_device, controller_data)
|
VeraDevice.__init__(self, vera_device, controller_data)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self) -> Optional[int]:
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
return SUPPORT_FLAGS
|
return SUPPORT_FLAGS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> str:
|
||||||
"""Return hvac operation ie. heat, cool mode.
|
"""Return hvac operation ie. heat, cool mode.
|
||||||
|
|
||||||
Need to be one of HVAC_MODE_*.
|
Need to be one of HVAC_MODE_*.
|
||||||
@ -78,7 +82,7 @@ class VeraThermostat(VeraDevice, ClimateEntity):
|
|||||||
return HVAC_MODE_OFF
|
return HVAC_MODE_OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_modes(self) -> List[str]:
|
||||||
"""Return the list of available hvac operation modes.
|
"""Return the list of available hvac operation modes.
|
||||||
|
|
||||||
Need to be a subset of HVAC_MODES.
|
Need to be a subset of HVAC_MODES.
|
||||||
@ -86,7 +90,7 @@ class VeraThermostat(VeraDevice, ClimateEntity):
|
|||||||
return SUPPORT_HVAC
|
return SUPPORT_HVAC
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self) -> Optional[str]:
|
||||||
"""Return the fan setting."""
|
"""Return the fan setting."""
|
||||||
mode = self.vera_device.get_fan_mode()
|
mode = self.vera_device.get_fan_mode()
|
||||||
if mode == "ContinuousOn":
|
if mode == "ContinuousOn":
|
||||||
@ -94,11 +98,11 @@ class VeraThermostat(VeraDevice, ClimateEntity):
|
|||||||
return FAN_AUTO
|
return FAN_AUTO
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_modes(self):
|
def fan_modes(self) -> Optional[List[str]]:
|
||||||
"""Return a list of available fan modes."""
|
"""Return a list of available fan modes."""
|
||||||
return FAN_OPERATION_LIST
|
return FAN_OPERATION_LIST
|
||||||
|
|
||||||
def set_fan_mode(self, fan_mode):
|
def set_fan_mode(self, fan_mode) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
if fan_mode == FAN_ON:
|
if fan_mode == FAN_ON:
|
||||||
self.vera_device.fan_on()
|
self.vera_device.fan_on()
|
||||||
@ -108,14 +112,14 @@ class VeraThermostat(VeraDevice, ClimateEntity):
|
|||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_w(self):
|
def current_power_w(self) -> Optional[float]:
|
||||||
"""Return the current power usage in W."""
|
"""Return the current power usage in W."""
|
||||||
power = self.vera_device.power
|
power = self.vera_device.power
|
||||||
if power:
|
if power:
|
||||||
return convert(power, float, 0.0)
|
return convert(power, float, 0.0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self) -> str:
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
vera_temp_units = self.vera_device.vera_controller.temperature_units
|
vera_temp_units = self.vera_device.vera_controller.temperature_units
|
||||||
|
|
||||||
@ -125,28 +129,28 @@ class VeraThermostat(VeraDevice, ClimateEntity):
|
|||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self) -> Optional[float]:
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
return self.vera_device.get_current_temperature()
|
return self.vera_device.get_current_temperature()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operation(self):
|
def operation(self) -> str:
|
||||||
"""Return current operation ie. heat, cool, idle."""
|
"""Return current operation ie. heat, cool, idle."""
|
||||||
return self.vera_device.get_hvac_mode()
|
return self.vera_device.get_hvac_mode()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self) -> Optional[float]:
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
return self.vera_device.get_current_goal_temperature()
|
return self.vera_device.get_current_goal_temperature()
|
||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperatures."""
|
"""Set new target temperatures."""
|
||||||
if kwargs.get(ATTR_TEMPERATURE) is not None:
|
if kwargs.get(ATTR_TEMPERATURE) is not None:
|
||||||
self.vera_device.set_temperature(kwargs.get(ATTR_TEMPERATURE))
|
self.vera_device.set_temperature(kwargs.get(ATTR_TEMPERATURE))
|
||||||
|
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode):
|
def set_hvac_mode(self, hvac_mode) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVAC_MODE_OFF:
|
||||||
self.vera_device.turn_off()
|
self.vera_device.turn_off()
|
||||||
|
@ -8,6 +8,7 @@ from requests.exceptions import RequestException
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
|
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||||
@ -68,11 +69,11 @@ def options_data(user_input: dict) -> dict:
|
|||||||
class OptionsFlowHandler(config_entries.OptionsFlow):
|
class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Options for the component."""
|
"""Options for the component."""
|
||||||
|
|
||||||
def __init__(self, config_entry: config_entries.ConfigEntry):
|
def __init__(self, config_entry: ConfigEntry):
|
||||||
"""Init object."""
|
"""Init object."""
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input: dict = None):
|
||||||
"""Manage the options."""
|
"""Manage the options."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
@ -91,7 +92,7 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config_entry) -> OptionsFlowHandler:
|
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlowHandler:
|
||||||
"""Get the options flow."""
|
"""Get the options flow."""
|
||||||
return OptionsFlowHandler(config_entry)
|
return OptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera cover - curtains, rollershutters etc."""
|
"""Support for Vera cover - curtains, rollershutters etc."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Any, Callable, List
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
@ -33,16 +35,18 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraCover(VeraDevice, CoverEntity):
|
class VeraCover(VeraDevice[veraApi.VeraCurtain], CoverEntity):
|
||||||
"""Representation a Vera Cover."""
|
"""Representation a Vera Cover."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraCurtain, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
VeraDevice.__init__(self, vera_device, controller_data)
|
VeraDevice.__init__(self, vera_device, controller_data)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self) -> int:
|
||||||
"""
|
"""
|
||||||
Return current position of cover.
|
Return current position of cover.
|
||||||
|
|
||||||
@ -55,28 +59,28 @@ class VeraCover(VeraDevice, CoverEntity):
|
|||||||
return 100
|
return 100
|
||||||
return position
|
return position
|
||||||
|
|
||||||
def set_cover_position(self, **kwargs):
|
def set_cover_position(self, **kwargs) -> None:
|
||||||
"""Move the cover to a specific position."""
|
"""Move the cover to a specific position."""
|
||||||
self.vera_device.set_level(kwargs.get(ATTR_POSITION))
|
self.vera_device.set_level(kwargs.get(ATTR_POSITION))
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self) -> bool:
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
if self.current_cover_position is not None:
|
if self.current_cover_position is not None:
|
||||||
return self.current_cover_position == 0
|
return self.current_cover_position == 0
|
||||||
|
|
||||||
def open_cover(self, **kwargs):
|
def open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
self.vera_device.open()
|
self.vera_device.open()
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def close_cover(self, **kwargs):
|
def close_cover(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover."""
|
"""Close the cover."""
|
||||||
self.vera_device.close()
|
self.vera_device.close()
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def stop_cover(self, **kwargs):
|
def stop_cover(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
self.vera_device.stop()
|
self.vera_device.stop()
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera lights."""
|
"""Support for Vera lights."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Any, Callable, List, Optional, Tuple
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
@ -37,10 +39,12 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraLight(VeraDevice, LightEntity):
|
class VeraLight(VeraDevice[veraApi.VeraDimmer], LightEntity):
|
||||||
"""Representation of a Vera Light, including dimmable."""
|
"""Representation of a Vera Light, including dimmable."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraDimmer, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._state = False
|
self._state = False
|
||||||
self._color = None
|
self._color = None
|
||||||
@ -49,23 +53,23 @@ class VeraLight(VeraDevice, LightEntity):
|
|||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self) -> Optional[int]:
|
||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light."""
|
||||||
return self._brightness
|
return self._brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hs_color(self):
|
def hs_color(self) -> Optional[Tuple[float, float]]:
|
||||||
"""Return the color of the light."""
|
"""Return the color of the light."""
|
||||||
return self._color
|
return self._color
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
if self._color:
|
if self._color:
|
||||||
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
|
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
|
||||||
return SUPPORT_BRIGHTNESS
|
return SUPPORT_BRIGHTNESS
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
if ATTR_HS_COLOR in kwargs and self._color:
|
if ATTR_HS_COLOR in kwargs and self._color:
|
||||||
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
|
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
|
||||||
@ -78,18 +82,18 @@ class VeraLight(VeraDevice, LightEntity):
|
|||||||
self._state = True
|
self._state = True
|
||||||
self.schedule_update_ha_state(True)
|
self.schedule_update_ha_state(True)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
self.vera_device.switch_off()
|
self.vera_device.switch_off()
|
||||||
self._state = False
|
self._state = False
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Call to update state."""
|
"""Call to update state."""
|
||||||
self._state = self.vera_device.is_switched_on()
|
self._state = self.vera_device.is_switched_on()
|
||||||
if self.vera_device.is_dimmable:
|
if self.vera_device.is_dimmable:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera locks."""
|
"""Support for Vera locks."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.lock import (
|
from homeassistant.components.lock import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as PLATFORM_DOMAIN,
|
||||||
@ -36,32 +38,32 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraLock(VeraDevice, LockEntity):
|
class VeraLock(VeraDevice[veraApi.VeraLock], LockEntity):
|
||||||
"""Representation of a Vera lock."""
|
"""Representation of a Vera lock."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(self, vera_device: veraApi.VeraLock, controller_data: ControllerData):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
self._state = None
|
self._state = None
|
||||||
VeraDevice.__init__(self, vera_device, controller_data)
|
VeraDevice.__init__(self, vera_device, controller_data)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
def lock(self, **kwargs):
|
def lock(self, **kwargs: Any) -> None:
|
||||||
"""Lock the device."""
|
"""Lock the device."""
|
||||||
self.vera_device.lock()
|
self.vera_device.lock()
|
||||||
self._state = STATE_LOCKED
|
self._state = STATE_LOCKED
|
||||||
|
|
||||||
def unlock(self, **kwargs):
|
def unlock(self, **kwargs: Any) -> None:
|
||||||
"""Unlock the device."""
|
"""Unlock the device."""
|
||||||
self.vera_device.unlock()
|
self.vera_device.unlock()
|
||||||
self._state = STATE_UNLOCKED
|
self._state = STATE_UNLOCKED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_locked(self):
|
def is_locked(self) -> Optional[bool]:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state == STATE_LOCKED
|
return self._state == STATE_LOCKED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Who unlocked the lock and did a low battery alert fire.
|
"""Who unlocked the lock and did a low battery alert fire.
|
||||||
|
|
||||||
Reports on the previous poll cycle.
|
Reports on the previous poll cycle.
|
||||||
@ -78,7 +80,7 @@ class VeraLock(VeraDevice, LockEntity):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def changed_by(self):
|
def changed_by(self) -> Optional[str]:
|
||||||
"""Who unlocked the lock.
|
"""Who unlocked the lock.
|
||||||
|
|
||||||
Reports on the previous poll cycle.
|
Reports on the previous poll cycle.
|
||||||
@ -89,7 +91,7 @@ class VeraLock(VeraDevice, LockEntity):
|
|||||||
return last_user[0]
|
return last_user[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Update state by the Vera device callback."""
|
"""Update state by the Vera device callback."""
|
||||||
self._state = (
|
self._state = (
|
||||||
STATE_LOCKED if self.vera_device.is_locked(True) else STATE_UNLOCKED
|
STATE_LOCKED if self.vera_device.is_locked(True) else STATE_UNLOCKED
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera scenes."""
|
"""Support for Vera scenes."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, List
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.scene import Scene
|
from homeassistant.components.scene import Scene
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -29,7 +31,7 @@ async def async_setup_entry(
|
|||||||
class VeraScene(Scene):
|
class VeraScene(Scene):
|
||||||
"""Representation of a Vera scene entity."""
|
"""Representation of a Vera scene entity."""
|
||||||
|
|
||||||
def __init__(self, vera_scene, controller_data: ControllerData):
|
def __init__(self, vera_scene: veraApi.VeraScene, controller_data: ControllerData):
|
||||||
"""Initialize the scene."""
|
"""Initialize the scene."""
|
||||||
self.vera_scene = vera_scene
|
self.vera_scene = vera_scene
|
||||||
self.controller = controller_data.controller
|
self.controller = controller_data.controller
|
||||||
@ -40,7 +42,7 @@ class VeraScene(Scene):
|
|||||||
slugify(vera_scene.name), vera_scene.scene_id
|
slugify(vera_scene.name), vera_scene.scene_id
|
||||||
)
|
)
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Update the scene status."""
|
"""Update the scene status."""
|
||||||
self.vera_scene.refresh()
|
self.vera_scene.refresh()
|
||||||
|
|
||||||
@ -49,11 +51,11 @@ class VeraScene(Scene):
|
|||||||
self.vera_scene.activate()
|
self.vera_scene.activate()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the scene."""
|
"""Return the name of the scene."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Return the state attributes of the scene."""
|
"""Return the state attributes of the scene."""
|
||||||
return {"vera_scene_id": self.vera_scene.vera_scene_id}
|
return {"vera_scene_id": self.vera_scene.vera_scene_id}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Support for Vera sensors."""
|
"""Support for Vera sensors."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Callable, List, Optional, cast
|
||||||
|
|
||||||
import pyvera as veraApi
|
import pyvera as veraApi
|
||||||
|
|
||||||
@ -35,10 +35,12 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraSensor(VeraDevice, Entity):
|
class VeraSensor(VeraDevice[veraApi.VeraSensor], Entity):
|
||||||
"""Representation of a Vera Sensor."""
|
"""Representation of a Vera Sensor."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraSensor, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.current_value = None
|
self.current_value = None
|
||||||
self._temperature_units = None
|
self._temperature_units = None
|
||||||
@ -47,12 +49,12 @@ class VeraSensor(VeraDevice, Entity):
|
|||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self.current_value
|
return self.current_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self) -> Optional[str]:
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
|
|
||||||
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
|
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
|
||||||
@ -66,7 +68,7 @@ class VeraSensor(VeraDevice, Entity):
|
|||||||
if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
|
if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
|
||||||
return "watts"
|
return "watts"
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
|
|
||||||
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
|
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
|
||||||
@ -86,8 +88,9 @@ class VeraSensor(VeraDevice, Entity):
|
|||||||
elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
|
elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
|
||||||
self.current_value = self.vera_device.humidity
|
self.current_value = self.vera_device.humidity
|
||||||
elif self.vera_device.category == veraApi.CATEGORY_SCENE_CONTROLLER:
|
elif self.vera_device.category == veraApi.CATEGORY_SCENE_CONTROLLER:
|
||||||
value = self.vera_device.get_last_scene_id(True)
|
controller = cast(veraApi.VeraSceneController, self.vera_device)
|
||||||
time = self.vera_device.get_last_scene_time(True)
|
value = controller.get_last_scene_id(True)
|
||||||
|
time = controller.get_last_scene_time(True)
|
||||||
if time == self.last_changed_time:
|
if time == self.last_changed_time:
|
||||||
self.current_value = None
|
self.current_value = None
|
||||||
else:
|
else:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Support for Vera switches."""
|
"""Support for Vera switches."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Any, Callable, List, Optional
|
||||||
|
|
||||||
|
import pyvera as veraApi
|
||||||
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as PLATFORM_DOMAIN,
|
||||||
@ -33,39 +35,41 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VeraSwitch(VeraDevice, SwitchEntity):
|
class VeraSwitch(VeraDevice[veraApi.VeraSwitch], SwitchEntity):
|
||||||
"""Representation of a Vera Switch."""
|
"""Representation of a Vera Switch."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller_data: ControllerData):
|
def __init__(
|
||||||
|
self, vera_device: veraApi.VeraSwitch, controller_data: ControllerData
|
||||||
|
):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
self._state = False
|
self._state = False
|
||||||
VeraDevice.__init__(self, vera_device, controller_data)
|
VeraDevice.__init__(self, vera_device, controller_data)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn device on."""
|
"""Turn device on."""
|
||||||
self.vera_device.switch_on()
|
self.vera_device.switch_on()
|
||||||
self._state = True
|
self._state = True
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn device off."""
|
"""Turn device off."""
|
||||||
self.vera_device.switch_off()
|
self.vera_device.switch_off()
|
||||||
self._state = False
|
self._state = False
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_w(self):
|
def current_power_w(self) -> Optional[float]:
|
||||||
"""Return the current power usage in W."""
|
"""Return the current power usage in W."""
|
||||||
power = self.vera_device.power
|
power = self.vera_device.power
|
||||||
if power:
|
if power:
|
||||||
return convert(power, float, 0.0)
|
return convert(power, float, 0.0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
self._state = self.vera_device.is_switched_on()
|
self._state = self.vera_device.is_switched_on()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user