Add power sensor to fibaro integration (#68848)
This commit is contained in:
parent
7f5ee53d51
commit
93a66cc357
1 changed files with 25 additions and 0 deletions
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||
ENERGY_KILO_WATT_HOUR,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
|
@ -68,6 +69,8 @@ async def async_setup_entry(
|
|||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][device_type]:
|
||||
if "energy" in device.interfaces:
|
||||
entities.append(FibaroEnergySensor(device))
|
||||
if "power" in device.interfaces:
|
||||
entities.append(FibaroPowerSensor(device))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
@ -146,3 +149,25 @@ class FibaroEnergySensor(FibaroDevice, SensorEntity):
|
|||
self._attr_native_value = convert(
|
||||
self.fibaro_device.properties.energy, float
|
||||
)
|
||||
|
||||
|
||||
class FibaroPowerSensor(FibaroDevice, SensorEntity):
|
||||
"""Representation of a Fibaro Power Sensor."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.POWER
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
_attr_native_unit_of_measurement = POWER_WATT
|
||||
|
||||
def __init__(self, fibaro_device):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(fibaro_device)
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(f"{self.ha_id}_power")
|
||||
self._attr_name = f"{fibaro_device.friendly_name} Power"
|
||||
self._attr_unique_id = f"{fibaro_device.unique_id_str}_power"
|
||||
|
||||
def update(self):
|
||||
"""Update the state."""
|
||||
with suppress(KeyError, ValueError):
|
||||
self._attr_native_value = convert(
|
||||
self.fibaro_device.properties.power, float
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue