Add HomematicIP Cloud light power consumption and energie attributes (#15343)

* Add power consumption and energie attributes

* Fix lint

* Change attribute name and include kwh
This commit is contained in:
Mattias Welponer 2018-07-09 05:37:59 +02:00 committed by Martin Hjelmare
parent 703d71c064
commit 1ff329d9d6

View File

@ -17,7 +17,7 @@ DEPENDENCIES = ['homematicip_cloud']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTR_POWER_CONSUMPTION = 'power_consumption' ATTR_POWER_CONSUMPTION = 'power_consumption'
ATTR_ENERGIE_COUNTER = 'energie_counter' ATTR_ENERGIE_COUNTER = 'energie_counter_kwh'
ATTR_PROFILE_MODE = 'profile_mode' ATTR_PROFILE_MODE = 'profile_mode'
@ -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): async def async_setup_entry(hass, config_entry, async_add_devices):
"""Set up the HomematicIP lights from a config entry.""" """Set up the HomematicIP lights from a config entry."""
from homematicip.device import ( from homematicip.aio.device import (
BrandSwitchMeasuring) AsyncBrandSwitchMeasuring)
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = [] devices = []
for device in home.devices: for device in home.devices:
if isinstance(device, BrandSwitchMeasuring): if isinstance(device, AsyncBrandSwitchMeasuring):
devices.append(HomematicipLightMeasuring(home, device)) devices.append(HomematicipLightMeasuring(home, device))
if devices: if devices:
@ -67,13 +67,15 @@ class HomematicipLightMeasuring(HomematicipLight):
"""MomematicIP measuring light device.""" """MomematicIP measuring light device."""
@property @property
def current_power_w(self): def device_state_attributes(self):
"""Return the current power usage in W.""" """Return the state attributes of the generic device."""
return self._device.currentPowerConsumption attr = super().device_state_attributes
if self._device.currentPowerConsumption > 0.05:
@property attr.update({
def today_energy_kwh(self): ATTR_POWER_CONSUMPTION:
"""Return the today total energy usage in kWh.""" round(self._device.currentPowerConsumption, 2)
if self._device.energyCounter is None: })
return 0 attr.update({
return round(self._device.energyCounter) ATTR_ENERGIE_COUNTER: round(self._device.energyCounter, 2)
})
return attr