2019-02-14 15:01:46 +00:00
|
|
|
"""Support for HomematicIP Cloud sensors."""
|
2018-03-18 15:57:53 +00:00
|
|
|
import logging
|
2019-11-25 13:17:14 +00:00
|
|
|
from typing import Any, Dict
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-04-23 23:47:31 +00:00
|
|
|
from homematicip.aio.device import (
|
2019-07-31 19:25:30 +00:00
|
|
|
AsyncBrandSwitchMeasuring,
|
|
|
|
AsyncFullFlushSwitchMeasuring,
|
|
|
|
AsyncHeatingThermostat,
|
|
|
|
AsyncHeatingThermostatCompact,
|
|
|
|
AsyncLightSensor,
|
|
|
|
AsyncMotionDetectorIndoor,
|
|
|
|
AsyncMotionDetectorOutdoor,
|
|
|
|
AsyncMotionDetectorPushButton,
|
2019-09-09 20:02:53 +00:00
|
|
|
AsyncPassageDetector,
|
2019-07-31 19:25:30 +00:00
|
|
|
AsyncPlugableSwitchMeasuring,
|
|
|
|
AsyncPresenceDetectorIndoor,
|
2020-02-19 09:43:12 +00:00
|
|
|
AsyncRoomControlDeviceAnalog,
|
2019-07-31 19:25:30 +00:00
|
|
|
AsyncTemperatureHumiditySensorDisplay,
|
2019-04-23 23:47:31 +00:00
|
|
|
AsyncTemperatureHumiditySensorOutdoor,
|
2019-07-31 19:25:30 +00:00
|
|
|
AsyncTemperatureHumiditySensorWithoutDisplay,
|
|
|
|
AsyncWeatherSensor,
|
|
|
|
AsyncWeatherSensorPlus,
|
|
|
|
AsyncWeatherSensorPro,
|
|
|
|
)
|
2019-04-23 23:47:31 +00:00
|
|
|
from homematicip.base.enums import ValveState
|
|
|
|
|
2019-04-25 22:13:07 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2018-06-03 16:48:51 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DEVICE_CLASS_HUMIDITY,
|
|
|
|
DEVICE_CLASS_ILLUMINANCE,
|
|
|
|
DEVICE_CLASS_POWER,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
POWER_WATT,
|
2020-02-25 01:52:14 +00:00
|
|
|
SPEED_KILOMETERS_PER_HOUR,
|
2019-07-31 19:25:30 +00:00
|
|
|
TEMP_CELSIUS,
|
2020-02-28 19:46:48 +00:00
|
|
|
UNIT_PERCENTAGE,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-10-23 16:21:49 +00:00
|
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2020-01-26 13:54:33 +00:00
|
|
|
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice
|
2019-09-14 05:12:19 +00:00
|
|
|
from .device import ATTR_IS_GROUP, ATTR_MODEL_TYPE
|
2019-10-11 14:36:46 +00:00
|
|
|
from .hap import HomematicipHAP
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-10-28 00:03:26 +00:00
|
|
|
ATTR_CURRENT_ILLUMINATION = "current_illumination"
|
|
|
|
ATTR_LOWEST_ILLUMINATION = "lowest_illumination"
|
|
|
|
ATTR_HIGHEST_ILLUMINATION = "highest_illumination"
|
2019-09-09 20:02:53 +00:00
|
|
|
ATTR_LEFT_COUNTER = "left_counter"
|
|
|
|
ATTR_RIGHT_COUNTER = "right_counter"
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_TEMPERATURE_OFFSET = "temperature_offset"
|
|
|
|
ATTR_WIND_DIRECTION = "wind_direction"
|
|
|
|
ATTR_WIND_DIRECTION_VARIATION = "wind_direction_variation_in_degree"
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-10-28 00:03:26 +00:00
|
|
|
ILLUMINATION_DEVICE_ATTRIBUTES = {
|
|
|
|
"currentIllumination": ATTR_CURRENT_ILLUMINATION,
|
|
|
|
"lowestIllumination": ATTR_LOWEST_ILLUMINATION,
|
|
|
|
"highestIllumination": ATTR_HIGHEST_ILLUMINATION,
|
|
|
|
}
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_entry(
|
2019-10-23 16:21:49 +00:00
|
|
|
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
|
2019-07-31 19:25:30 +00:00
|
|
|
) -> None:
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Set up the HomematicIP Cloud sensors from a config entry."""
|
2020-01-26 13:54:33 +00:00
|
|
|
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
2019-11-25 13:17:14 +00:00
|
|
|
entities = [HomematicipAccesspointStatus(hap)]
|
2019-10-11 14:36:46 +00:00
|
|
|
for device in hap.home.devices:
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(device, (AsyncHeatingThermostat, AsyncHeatingThermostatCompact)):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipHeatingThermostat(hap, device))
|
|
|
|
entities.append(HomematicipTemperatureSensor(hap, device))
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(
|
|
|
|
device,
|
|
|
|
(
|
|
|
|
AsyncTemperatureHumiditySensorDisplay,
|
|
|
|
AsyncTemperatureHumiditySensorWithoutDisplay,
|
|
|
|
AsyncTemperatureHumiditySensorOutdoor,
|
|
|
|
AsyncWeatherSensor,
|
|
|
|
AsyncWeatherSensorPlus,
|
|
|
|
AsyncWeatherSensorPro,
|
|
|
|
),
|
|
|
|
):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipTemperatureSensor(hap, device))
|
|
|
|
entities.append(HomematicipHumiditySensor(hap, device))
|
2020-02-19 09:43:12 +00:00
|
|
|
elif isinstance(device, (AsyncRoomControlDeviceAnalog,)):
|
|
|
|
entities.append(HomematicipTemperatureSensor(hap, device))
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(
|
|
|
|
device,
|
|
|
|
(
|
|
|
|
AsyncLightSensor,
|
|
|
|
AsyncMotionDetectorIndoor,
|
|
|
|
AsyncMotionDetectorOutdoor,
|
|
|
|
AsyncMotionDetectorPushButton,
|
|
|
|
AsyncPresenceDetectorIndoor,
|
|
|
|
AsyncWeatherSensor,
|
|
|
|
AsyncWeatherSensorPlus,
|
|
|
|
AsyncWeatherSensorPro,
|
|
|
|
),
|
|
|
|
):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipIlluminanceSensor(hap, device))
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(
|
|
|
|
device,
|
|
|
|
(
|
|
|
|
AsyncPlugableSwitchMeasuring,
|
|
|
|
AsyncBrandSwitchMeasuring,
|
|
|
|
AsyncFullFlushSwitchMeasuring,
|
|
|
|
),
|
|
|
|
):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipPowerSensor(hap, device))
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(
|
|
|
|
device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
|
|
|
|
):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipWindspeedSensor(hap, device))
|
2019-07-31 19:25:30 +00:00
|
|
|
if isinstance(device, (AsyncWeatherSensorPlus, AsyncWeatherSensorPro)):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipTodayRainSensor(hap, device))
|
2019-09-09 20:02:53 +00:00
|
|
|
if isinstance(device, AsyncPassageDetector):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipPassageDetectorDeltaCounter(hap, device))
|
2018-03-23 18:05:02 +00:00
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
if entities:
|
|
|
|
async_add_entities(entities)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
|
2018-04-25 19:57:44 +00:00
|
|
|
class HomematicipAccesspointStatus(HomematicipGenericDevice):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Representation of an HomeMaticIP Cloud access point."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP) -> None:
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize access point device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, hap.home)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-02-27 19:25:11 +00:00
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_info(self) -> Dict[str, Any]:
|
2019-02-27 19:25:11 +00:00
|
|
|
"""Return device specific attributes."""
|
|
|
|
# Adds a sensor to the existing HAP device
|
|
|
|
return {
|
2019-07-31 19:25:30 +00:00
|
|
|
"identifiers": {
|
2019-02-27 19:25:11 +00:00
|
|
|
# Serial numbers of Homematic IP device
|
|
|
|
(HMIPC_DOMAIN, self._device.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def icon(self) -> str:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the icon of the access point device."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return "mdi:access-point-network"
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the state of the access point."""
|
|
|
|
return self._home.dutyCycle
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def available(self) -> bool:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Device available."""
|
|
|
|
return self._home.connected
|
|
|
|
|
2018-07-15 00:59:19 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2018-07-15 00:59:19 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2020-02-28 19:46:48 +00:00
|
|
|
return UNIT_PERCENTAGE
|
2018-07-15 00:59:19 +00:00
|
|
|
|
2019-08-22 16:02:35 +00:00
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-09-14 05:12:19 +00:00
|
|
|
"""Return the state attributes of the access point."""
|
2019-10-08 17:52:43 +00:00
|
|
|
state_attr = super().device_state_attributes
|
|
|
|
|
|
|
|
state_attr[ATTR_MODEL_TYPE] = "HmIP-HAP"
|
|
|
|
state_attr[ATTR_IS_GROUP] = False
|
|
|
|
|
|
|
|
return state_attr
|
2019-08-22 16:02:35 +00:00
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP heating thermostat device."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize heating thermostat device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Heating")
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def icon(self) -> str:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the icon."""
|
2018-07-18 10:19:08 +00:00
|
|
|
if super().icon:
|
|
|
|
return super().icon
|
2018-07-15 00:59:19 +00:00
|
|
|
if self._device.valveState != ValveState.ADAPTION_DONE:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "mdi:alert"
|
|
|
|
return "mdi:radiator"
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> int:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the state of the radiator valve."""
|
2018-07-15 00:59:19 +00:00
|
|
|
if self._device.valveState != ValveState.ADAPTION_DONE:
|
|
|
|
return self._device.valveState
|
2019-07-31 19:25:30 +00:00
|
|
|
return round(self._device.valvePosition * 100)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2020-02-28 19:46:48 +00:00
|
|
|
return UNIT_PERCENTAGE
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
|
2018-04-25 19:57:44 +00:00
|
|
|
class HomematicipHumiditySensor(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP Cloud humidity device."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize the thermometer device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Humidity")
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def device_class(self) -> str:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_HUMIDITY
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> int:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the state."""
|
|
|
|
return self._device.humidity
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2020-02-28 19:46:48 +00:00
|
|
|
return UNIT_PERCENTAGE
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
|
2018-04-25 19:57:44 +00:00
|
|
|
class HomematicipTemperatureSensor(HomematicipGenericDevice):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Representation of a HomematicIP Cloud thermometer device."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize the thermometer device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Temperature")
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def device_class(self) -> str:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_TEMPERATURE
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if hasattr(self._device, "valveActualTemperature"):
|
2019-04-22 07:30:49 +00:00
|
|
|
return self._device.valveActualTemperature
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
return self._device.actualTemperature
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2018-03-18 15:57:53 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return TEMP_CELSIUS
|
2018-06-03 16:48:51 +00:00
|
|
|
|
2019-03-12 13:52:13 +00:00
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Return the state attributes of the windspeed sensor."""
|
2019-09-06 13:28:24 +00:00
|
|
|
state_attr = super().device_state_attributes
|
|
|
|
|
|
|
|
temperature_offset = getattr(self._device, "temperatureOffset", None)
|
|
|
|
if temperature_offset:
|
|
|
|
state_attr[ATTR_TEMPERATURE_OFFSET] = temperature_offset
|
|
|
|
|
|
|
|
return state_attr
|
2019-03-12 13:52:13 +00:00
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
|
|
|
|
class HomematicipIlluminanceSensor(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP Illuminance device."""
|
2018-06-03 16:48:51 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Initialize the device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Illuminance")
|
2018-06-03 16:48:51 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def device_class(self) -> str:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_ILLUMINANCE
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Return the state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if hasattr(self._device, "averageIllumination"):
|
2019-04-22 07:30:49 +00:00
|
|
|
return self._device.averageIllumination
|
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
return self._device.illumination
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2018-06-03 16:48:51 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return "lx"
|
2019-02-08 11:43:48 +00:00
|
|
|
|
2019-10-28 00:03:26 +00:00
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-10-28 00:03:26 +00:00
|
|
|
"""Return the state attributes of the wind speed sensor."""
|
|
|
|
state_attr = super().device_state_attributes
|
|
|
|
|
|
|
|
for attr, attr_key in ILLUMINATION_DEVICE_ATTRIBUTES.items():
|
|
|
|
attr_value = getattr(self._device, attr, None)
|
|
|
|
if attr_value:
|
|
|
|
state_attr[attr_key] = attr_value
|
|
|
|
|
|
|
|
return state_attr
|
|
|
|
|
2019-02-08 11:43:48 +00:00
|
|
|
|
|
|
|
class HomematicipPowerSensor(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP power measuring device."""
|
2019-02-08 11:43:48 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2019-02-08 11:43:48 +00:00
|
|
|
"""Initialize the device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Power")
|
2019-02-08 11:43:48 +00:00
|
|
|
|
2019-04-04 04:52:23 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def device_class(self) -> str:
|
2019-04-04 04:52:23 +00:00
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_POWER
|
|
|
|
|
2019-02-08 11:43:48 +00:00
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2020-01-31 16:33:00 +00:00
|
|
|
"""Representation of the HomematicIP power consumption value."""
|
2019-02-08 11:43:48 +00:00
|
|
|
return self._device.currentPowerConsumption
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2019-02-08 11:43:48 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2019-03-02 10:29:59 +00:00
|
|
|
return POWER_WATT
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomematicipWindspeedSensor(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP wind speed sensor."""
|
2019-03-12 13:52:13 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Initialize the device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Windspeed")
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of the HomematicIP wind speed value."""
|
2019-03-12 13:52:13 +00:00
|
|
|
return self._device.windSpeed
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2020-02-25 01:52:14 +00:00
|
|
|
return SPEED_KILOMETERS_PER_HOUR
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Return the state attributes of the wind speed sensor."""
|
2019-09-06 13:28:24 +00:00
|
|
|
state_attr = super().device_state_attributes
|
|
|
|
|
|
|
|
wind_direction = getattr(self._device, "windDirection", None)
|
2019-10-08 17:52:43 +00:00
|
|
|
if wind_direction is not None:
|
2019-09-06 13:28:24 +00:00
|
|
|
state_attr[ATTR_WIND_DIRECTION] = _get_wind_direction(wind_direction)
|
|
|
|
|
|
|
|
wind_direction_variation = getattr(self._device, "windDirectionVariation", None)
|
|
|
|
if wind_direction_variation:
|
|
|
|
state_attr[ATTR_WIND_DIRECTION_VARIATION] = wind_direction_variation
|
|
|
|
|
|
|
|
return state_attr
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomematicipTodayRainSensor(HomematicipGenericDevice):
|
2019-08-02 21:20:07 +00:00
|
|
|
"""Representation of a HomematicIP rain counter of a day sensor."""
|
2019-03-12 13:52:13 +00:00
|
|
|
|
2019-10-11 14:36:46 +00:00
|
|
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Initialize the device."""
|
2019-10-11 14:36:46 +00:00
|
|
|
super().__init__(hap, device, "Today Rain")
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def state(self) -> float:
|
2020-01-31 16:33:00 +00:00
|
|
|
"""Representation of the HomematicIP today's rain value."""
|
2019-03-12 13:52:13 +00:00
|
|
|
return round(self._device.todayRainCounter, 2)
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def unit_of_measurement(self) -> str:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return "mm"
|
2019-03-12 13:52:13 +00:00
|
|
|
|
|
|
|
|
2019-09-09 20:02:53 +00:00
|
|
|
class HomematicipPassageDetectorDeltaCounter(HomematicipGenericDevice):
|
|
|
|
"""Representation of a HomematicIP passage detector delta counter."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self) -> int:
|
|
|
|
"""Representation of the HomematicIP passage detector delta counter value."""
|
|
|
|
return self._device.leftRightCounterDelta
|
|
|
|
|
|
|
|
@property
|
2019-11-25 13:17:14 +00:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-09-09 20:02:53 +00:00
|
|
|
"""Return the state attributes of the delta counter."""
|
|
|
|
state_attr = super().device_state_attributes
|
|
|
|
|
|
|
|
state_attr[ATTR_LEFT_COUNTER] = self._device.leftCounter
|
|
|
|
state_attr[ATTR_RIGHT_COUNTER] = self._device.rightCounter
|
|
|
|
|
|
|
|
return state_attr
|
|
|
|
|
|
|
|
|
2019-04-25 22:13:07 +00:00
|
|
|
def _get_wind_direction(wind_direction_degree: float) -> str:
|
2019-03-12 13:52:13 +00:00
|
|
|
"""Convert wind direction degree to named direction."""
|
|
|
|
if 11.25 <= wind_direction_degree < 33.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "NNE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 33.75 <= wind_direction_degree < 56.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "NE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 56.25 <= wind_direction_degree < 78.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "ENE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 78.75 <= wind_direction_degree < 101.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "E"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 101.25 <= wind_direction_degree < 123.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "ESE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 123.75 <= wind_direction_degree < 146.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "SE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 146.25 <= wind_direction_degree < 168.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "SSE"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 168.75 <= wind_direction_degree < 191.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "S"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 191.25 <= wind_direction_degree < 213.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "SSW"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 213.75 <= wind_direction_degree < 236.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "SW"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 236.25 <= wind_direction_degree < 258.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "WSW"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 258.75 <= wind_direction_degree < 281.25:
|
2020-04-11 13:40:59 +00:00
|
|
|
return POWER_WATT
|
2019-03-12 13:52:13 +00:00
|
|
|
if 281.25 <= wind_direction_degree < 303.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "WNW"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 303.75 <= wind_direction_degree < 326.25:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "NW"
|
2019-03-12 13:52:13 +00:00
|
|
|
if 326.25 <= wind_direction_degree < 348.75:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "NNW"
|
|
|
|
return "N"
|