From 814e7d729976def0147592dd9360709882300c31 Mon Sep 17 00:00:00 2001 From: Mattias Welponer Date: Sat, 7 Jul 2018 14:44:38 +0200 Subject: [PATCH 1/3] Add power consumption and energie attributes --- .../components/light/homematicip_cloud.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/light/homematicip_cloud.py b/homeassistant/components/light/homematicip_cloud.py index 5984fb0365792e..85a94b0a4d42ca 100644 --- a/homeassistant/components/light/homematicip_cloud.py +++ b/homeassistant/components/light/homematicip_cloud.py @@ -29,13 +29,13 @@ async def async_setup_platform(hass, config, async_add_devices, async def async_setup_entry(hass, config_entry, async_add_devices): """Set up the HomematicIP lights from a config entry.""" - from homematicip.device import ( - BrandSwitchMeasuring) + from homematicip.aio.device import ( + AsyncBrandSwitchMeasuring) home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home devices = [] for device in home.devices: - if isinstance(device, BrandSwitchMeasuring): + if isinstance(device, AsyncBrandSwitchMeasuring): devices.append(HomematicipLightMeasuring(home, device)) if devices: @@ -67,13 +67,14 @@ class HomematicipLightMeasuring(HomematicipLight): """MomematicIP measuring light device.""" @property - def current_power_w(self): - """Return the current power usage in W.""" - return self._device.currentPowerConsumption - - @property - def today_energy_kwh(self): - """Return the today total energy usage in kWh.""" - if self._device.energyCounter is None: - return 0 - return round(self._device.energyCounter) + def device_state_attributes(self): + """Return the state attributes of the generic device.""" + attr = super().device_state_attributes + if self._device.currentPowerConsumption > 0.05: + attr.update({ + ATTR_POWER_CONSUMPTION: round(self._device.currentPowerConsumption, 2) + }) + attr.update({ + ATTR_ENERGIE_COUNTER: round(self._device.energyCounter, 2) + }) + return attr From 0c53d3c4c49ce4bf76dff3da7f25ff1d69f0d26f Mon Sep 17 00:00:00 2001 From: Mattias Welponer Date: Sat, 7 Jul 2018 15:03:31 +0200 Subject: [PATCH 2/3] Fix lint --- homeassistant/components/light/homematicip_cloud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/homematicip_cloud.py b/homeassistant/components/light/homematicip_cloud.py index 85a94b0a4d42ca..275121a84488c6 100644 --- a/homeassistant/components/light/homematicip_cloud.py +++ b/homeassistant/components/light/homematicip_cloud.py @@ -72,7 +72,8 @@ def device_state_attributes(self): attr = super().device_state_attributes if self._device.currentPowerConsumption > 0.05: attr.update({ - ATTR_POWER_CONSUMPTION: round(self._device.currentPowerConsumption, 2) + ATTR_POWER_CONSUMPTION: + round(self._device.currentPowerConsumption, 2) }) attr.update({ ATTR_ENERGIE_COUNTER: round(self._device.energyCounter, 2) From b5f45cc5ad7a581b40f91c6812285159f04d6291 Mon Sep 17 00:00:00 2001 From: Mattias Welponer Date: Sat, 7 Jul 2018 22:21:19 +0200 Subject: [PATCH 3/3] Change attribute name and include kwh --- homeassistant/components/light/homematicip_cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/homematicip_cloud.py b/homeassistant/components/light/homematicip_cloud.py index 275121a84488c6..5c513113f90fb4 100644 --- a/homeassistant/components/light/homematicip_cloud.py +++ b/homeassistant/components/light/homematicip_cloud.py @@ -17,7 +17,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_POWER_CONSUMPTION = 'power_consumption' -ATTR_ENERGIE_COUNTER = 'energie_counter' +ATTR_ENERGIE_COUNTER = 'energie_counter_kwh' ATTR_PROFILE_MODE = 'profile_mode'