From 31b6b3deb52329839ac29b4e70719f0862d3f759 Mon Sep 17 00:00:00 2001 From: Daniel Reimer Date: Sun, 24 Apr 2022 22:02:19 +0200 Subject: [PATCH] Add sensors for current and potential to AVM FRITZ!SmartHome / Fritz!DECT (#69999) * Update sensor.py Add sensors for current and potential to AVM FRITZ!SmartHome. Tested with Fritz!DECT 200 * Update sensor.py black, flake8 and isort checked * Fix the change requests Fixed the division by 1000 on two code parts to comply with the AVM API documention. Added device.power to availability check. * black --fast applied * fix issort * rename electric potential to voltage Co-authored-by: mib1185 --- homeassistant/components/fritzbox/sensor.py | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/homeassistant/components/fritzbox/sensor.py b/homeassistant/components/fritzbox/sensor.py index 473e68ed5da..e590f14ce89 100644 --- a/homeassistant/components/fritzbox/sensor.py +++ b/homeassistant/components/fritzbox/sensor.py @@ -17,6 +17,8 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( + ELECTRIC_CURRENT_AMPERE, + ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, PERCENTAGE, POWER_WATT, @@ -87,6 +89,26 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = ( suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] native_value=lambda device: device.power / 1000 if device.power else 0.0, ), + FritzSensorEntityDescription( + key="voltage", + name="Voltage", + native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, + suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] + native_value=lambda device: device.voltage / 1000 if device.voltage else 0.0, + ), + FritzSensorEntityDescription( + key="electric_current", + name="Electric Current", + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + device_class=SensorDeviceClass.CURRENT, + state_class=SensorStateClass.MEASUREMENT, + suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] + native_value=lambda device: device.power / device.voltage + if device.power and device.voltage + else 0.0, + ), FritzSensorEntityDescription( key="total_energy", name="Total Energy",