mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
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:
parent
703d71c064
commit
1ff329d9d6
@ -17,7 +17,7 @@ DEPENDENCIES = ['homematicip_cloud']
|
||||
_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'
|
||||
|
||||
|
||||
@ -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,15 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user