From d63b7bc5f1bc62ffaa82cd54f31d61ae086aadab Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 28 Dec 2021 08:33:40 +0100 Subject: [PATCH] Extract attribute into sensor for PVOutput (#62894) --- homeassistant/components/pvoutput/sensor.py | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/homeassistant/components/pvoutput/sensor.py b/homeassistant/components/pvoutput/sensor.py index 5f3765c688ee95..af89a2b4a0abf6 100644 --- a/homeassistant/components/pvoutput/sensor.py +++ b/homeassistant/components/pvoutput/sensor.py @@ -20,7 +20,12 @@ ATTR_VOLTAGE, CONF_API_KEY, CONF_NAME, + ELECTRIC_POTENTIAL_VOLT, + ENERGY_KILO_WATT_HOUR, ENERGY_WATT_HOUR, + POWER_KILO_WATT, + POWER_WATT, + TEMP_CELSIUS, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -67,6 +72,14 @@ class PVOutputSensorEntityDescription( SENSORS: tuple[PVOutputSensorEntityDescription, ...] = ( + PVOutputSensorEntityDescription( + key="energy_consumption", + name="Energy Consumed", + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_consumption, + ), PVOutputSensorEntityDescription( key="energy_generation", name="Energy Generated", @@ -75,6 +88,45 @@ class PVOutputSensorEntityDescription( state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda status: status.energy_generation, ), + PVOutputSensorEntityDescription( + key="normalized_ouput", + name="Efficiency", + native_unit_of_measurement=f"{ENERGY_KILO_WATT_HOUR}/{POWER_KILO_WATT}", + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda status: status.normalized_ouput, + ), + PVOutputSensorEntityDescription( + key="power_consumption", + name="Power Consumed", + native_unit_of_measurement=POWER_WATT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda status: status.power_consumption, + ), + PVOutputSensorEntityDescription( + key="power_generation", + name="Power Generated", + native_unit_of_measurement=POWER_WATT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda status: status.power_generation, + ), + PVOutputSensorEntityDescription( + key="temperature", + name="Temperature", + native_unit_of_measurement=TEMP_CELSIUS, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda status: status.temperature, + ), + PVOutputSensorEntityDescription( + key="voltage", + name="Voltage", + native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda status: status.voltage, + ), )