From 7b4eef06092f16a50d2cffae3e712fd4208dd5fc Mon Sep 17 00:00:00 2001 From: Mattias Welponer Date: Thu, 31 May 2018 18:27:52 +0200 Subject: [PATCH 1/2] Add iluminance sensor and device_class for sensors --- .../components/sensor/homematicip_cloud.py | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/homematicip_cloud.py b/homeassistant/components/sensor/homematicip_cloud.py index aa350f7be5d048..ab52843dd1fe15 100644 --- a/homeassistant/components/sensor/homematicip_cloud.py +++ b/homeassistant/components/sensor/homematicip_cloud.py @@ -10,7 +10,8 @@ from homeassistant.components.homematicip_cloud import ( HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN, ATTR_HOME_ID) -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import (TEMP_CELSIUS, + DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE) _LOGGER = logging.getLogger(__name__) @@ -36,7 +37,7 @@ async def async_setup_platform(hass, config, async_add_devices, """Set up the HomematicIP sensors devices.""" from homematicip.device import ( HeatingThermostat, TemperatureHumiditySensorWithoutDisplay, - TemperatureHumiditySensorDisplay) + TemperatureHumiditySensorDisplay, MotionDetectorIndoor) if discovery_info is None: return @@ -50,6 +51,8 @@ async def async_setup_platform(hass, config, async_add_devices, TemperatureHumiditySensorWithoutDisplay)): devices.append(HomematicipTemperatureSensor(home, device)) devices.append(HomematicipHumiditySensor(home, device)) + if isinstance(device, MotionDetectorIndoor): + devices.append(HomematicipIlluminanceSensor(home, device)) if devices: async_add_devices(devices) @@ -149,6 +152,11 @@ def __init__(self, home, device): """Initialize the thermometer device.""" super().__init__(home, device, 'Humidity') + @property + def device_class(self): + """Return the device class of the sensor.""" + return DEVICE_CLASS_HUMIDITY + @property def icon(self): """Return the icon.""" @@ -172,6 +180,11 @@ def __init__(self, home, device): """Initialize the thermometer device.""" super().__init__(home, device, 'Temperature') + @property + def device_class(self): + """Return the device class of the sensor.""" + return DEVICE_CLASS_TEMPERATURE + @property def icon(self): """Return the icon.""" @@ -186,3 +199,26 @@ def state(self): def unit_of_measurement(self): """Return the unit this state is expressed in.""" return TEMP_CELSIUS + + +class HomematicipIlluminanceSensor(HomematicipGenericDevice): + """MomematicIP the thermometer device.""" + + 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' From ce2361851585049733a8cd4e07383e424e0b4405 Mon Sep 17 00:00:00 2001 From: Mattias Welponer Date: Thu, 31 May 2018 18:52:40 +0200 Subject: [PATCH 2/2] Fix lint --- homeassistant/components/sensor/homematicip_cloud.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/homematicip_cloud.py b/homeassistant/components/sensor/homematicip_cloud.py index ab52843dd1fe15..ccd1949cc3b2bd 100644 --- a/homeassistant/components/sensor/homematicip_cloud.py +++ b/homeassistant/components/sensor/homematicip_cloud.py @@ -10,8 +10,9 @@ from homeassistant.components.homematicip_cloud import ( HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN, ATTR_HOME_ID) -from homeassistant.const import (TEMP_CELSIUS, - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE) +from homeassistant.const import ( + TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_ILLUMINANCE) _LOGGER = logging.getLogger(__name__)