2018-03-18 15:57:53 +00:00
|
|
|
"""
|
2018-08-21 19:25:16 +00:00
|
|
|
Support for HomematicIP Cloud sensors.
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-08-21 19:25:16 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2018-03-23 18:05:02 +00:00
|
|
|
https://home-assistant.io/components/sensor.homematicip_cloud/
|
2018-03-18 15:57:53 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.homematicip_cloud import (
|
2019-02-08 11:43:48 +00:00
|
|
|
DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice)
|
2018-06-03 16:48:51 +00:00
|
|
|
from homeassistant.const import (
|
2019-02-08 11:43:48 +00:00
|
|
|
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
|
|
|
|
DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['homematicip_cloud']
|
|
|
|
|
|
|
|
ATTR_VALVE_STATE = 'valve_state'
|
|
|
|
ATTR_VALVE_POSITION = 'valve_position'
|
2018-04-25 19:57:44 +00:00
|
|
|
ATTR_TEMPERATURE = 'temperature'
|
2018-03-18 15:57:53 +00:00
|
|
|
ATTR_TEMPERATURE_OFFSET = 'temperature_offset'
|
2018-04-25 19:57:44 +00:00
|
|
|
ATTR_HUMIDITY = 'humidity'
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
|
2018-08-21 19:25:16 +00:00
|
|
|
async def async_setup_platform(
|
2018-08-24 14:37:30 +00:00
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Set up the HomematicIP Cloud sensors devices."""
|
2018-07-06 21:05:34 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Set up the HomematicIP Cloud sensors from a config entry."""
|
2018-09-15 19:28:50 +00:00
|
|
|
from homematicip.aio.device import (
|
|
|
|
AsyncHeatingThermostat, AsyncTemperatureHumiditySensorWithoutDisplay,
|
|
|
|
AsyncTemperatureHumiditySensorDisplay, AsyncMotionDetectorIndoor,
|
2018-12-25 09:40:21 +00:00
|
|
|
AsyncTemperatureHumiditySensorOutdoor,
|
2019-02-08 11:43:48 +00:00
|
|
|
AsyncMotionDetectorPushButton, AsyncLightSensor,
|
|
|
|
AsyncPlugableSwitchMeasuring, AsyncBrandSwitchMeasuring,
|
|
|
|
AsyncFullFlushSwitchMeasuring)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-07-06 21:05:34 +00:00
|
|
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
2018-04-25 19:57:44 +00:00
|
|
|
devices = [HomematicipAccesspointStatus(home)]
|
2018-03-18 15:57:53 +00:00
|
|
|
for device in home.devices:
|
2018-09-15 19:28:50 +00:00
|
|
|
if isinstance(device, AsyncHeatingThermostat):
|
2018-03-23 18:05:02 +00:00
|
|
|
devices.append(HomematicipHeatingThermostat(home, device))
|
2018-09-15 19:28:50 +00:00
|
|
|
if isinstance(device, (AsyncTemperatureHumiditySensorDisplay,
|
|
|
|
AsyncTemperatureHumiditySensorWithoutDisplay,
|
|
|
|
AsyncTemperatureHumiditySensorOutdoor)):
|
2018-04-25 19:57:44 +00:00
|
|
|
devices.append(HomematicipTemperatureSensor(home, device))
|
|
|
|
devices.append(HomematicipHumiditySensor(home, device))
|
2018-12-25 09:40:21 +00:00
|
|
|
if isinstance(device, (AsyncMotionDetectorIndoor,
|
|
|
|
AsyncMotionDetectorPushButton)):
|
2018-06-03 16:48:51 +00:00
|
|
|
devices.append(HomematicipIlluminanceSensor(home, device))
|
2019-02-08 11:43:48 +00:00
|
|
|
if isinstance(device, AsyncLightSensor):
|
|
|
|
devices.append(HomematicipLightSensor(home, device))
|
|
|
|
if isinstance(device, (AsyncPlugableSwitchMeasuring,
|
|
|
|
AsyncBrandSwitchMeasuring,
|
|
|
|
AsyncFullFlushSwitchMeasuring)):
|
|
|
|
devices.append(HomematicipPowerSensor(home, device))
|
2018-03-23 18:05:02 +00:00
|
|
|
|
2018-04-25 19:57:44 +00:00
|
|
|
if devices:
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(devices)
|
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
|
|
|
|
2018-03-23 18:05:02 +00:00
|
|
|
def __init__(self, home):
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize access point device."""
|
|
|
|
super().__init__(home, home)
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon of the access point device."""
|
|
|
|
return 'mdi:access-point-network'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the access point."""
|
|
|
|
return self._home.dutyCycle
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Device available."""
|
|
|
|
return self._home.connected
|
|
|
|
|
2018-07-15 00:59:19 +00:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return '%'
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Represenation of a HomematicIP heating thermostat device."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-03-23 18:05:02 +00:00
|
|
|
def __init__(self, home, device):
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize heating thermostat device."""
|
|
|
|
super().__init__(home, device, 'Heating')
|
2018-03-18 15:57:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon."""
|
2018-07-15 00:59:19 +00:00
|
|
|
from homematicip.base.enums import ValveState
|
|
|
|
|
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:
|
2018-03-18 15:57:53 +00:00
|
|
|
return 'mdi:alert'
|
|
|
|
return 'mdi:radiator'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the radiator valve."""
|
2018-07-15 00:59:19 +00:00
|
|
|
from homematicip.base.enums import ValveState
|
|
|
|
|
|
|
|
if self._device.valveState != ValveState.ADAPTION_DONE:
|
|
|
|
return self._device.valveState
|
2018-03-18 15:57:53 +00:00
|
|
|
return round(self._device.valvePosition*100)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return '%'
|
|
|
|
|
|
|
|
|
2018-04-25 19:57:44 +00:00
|
|
|
class HomematicipHumiditySensor(HomematicipGenericDevice):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Represenation of a HomematicIP Cloud humidity device."""
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-03-23 18:05:02 +00:00
|
|
|
def __init__(self, home, device):
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize the thermometer device."""
|
|
|
|
super().__init__(home, device, 'Humidity')
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_HUMIDITY
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state."""
|
|
|
|
return self._device.humidity
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return '%'
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-03-23 18:05:02 +00:00
|
|
|
def __init__(self, home, device):
|
2018-04-25 19:57:44 +00:00
|
|
|
"""Initialize the thermometer device."""
|
|
|
|
super().__init__(home, device, 'Temperature')
|
2018-03-18 15:57:53 +00:00
|
|
|
|
2018-06-03 16:48:51 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_TEMPERATURE
|
|
|
|
|
2018-03-18 15:57:53 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state."""
|
|
|
|
return self._device.actualTemperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return TEMP_CELSIUS
|
2018-06-03 16:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomematicipIlluminanceSensor(HomematicipGenericDevice):
|
2018-08-21 19:25:16 +00:00
|
|
|
"""Represenation of a HomematicIP Illuminance device."""
|
2018-06-03 16:48:51 +00:00
|
|
|
|
|
|
|
def __init__(self, home, device):
|
|
|
|
"""Initialize the device."""
|
|
|
|
super().__init__(home, device, 'Illuminance')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return DEVICE_CLASS_ILLUMINANCE
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state."""
|
|
|
|
return self._device.illumination
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return 'lx'
|
2019-02-08 11:43:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomematicipLightSensor(HomematicipIlluminanceSensor):
|
|
|
|
"""Represenation of a HomematicIP Illuminance device."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state."""
|
|
|
|
return self._device.averageIllumination
|
|
|
|
|
|
|
|
|
|
|
|
class HomematicipPowerSensor(HomematicipGenericDevice):
|
|
|
|
"""Represenation of a HomematicIP power measuring device."""
|
|
|
|
|
|
|
|
def __init__(self, home, device):
|
|
|
|
"""Initialize the device."""
|
|
|
|
super().__init__(home, device, 'Power')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Represenation of the HomematicIP power comsumption value."""
|
|
|
|
return self._device.currentPowerConsumption
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return 'W'
|