Support Energy Sensor and Statistics in Homematic IP Cloud Integration (#57734)

* Update sensor.py

* Update test_device.py
pull/58495/head
FlavorFx 2021-10-26 20:01:42 +02:00 committed by GitHub
parent f15840e7ff
commit c5cf69dd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -26,13 +26,19 @@ from homematicip.aio.device import (
)
from homematicip.base.enums import ValveState
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR,
LENGTH_MILLIMETERS,
LIGHT_LUX,
PERCENTAGE,
@ -111,6 +117,7 @@ async def async_setup_entry(
),
):
entities.append(HomematicipPowerSensor(hap, device))
entities.append(HomematicipEnergySensor(hap, device))
if isinstance(
device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
):
@ -127,6 +134,8 @@ async def async_setup_entry(
class HomematicipAccesspointDutyCycle(HomematicipGenericEntity, SensorEntity):
"""Representation of then HomeMaticIP access point."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize access point status entity."""
super().__init__(hap, device, post="Duty Cycle")
@ -179,6 +188,8 @@ class HomematicipHeatingThermostat(HomematicipGenericEntity, SensorEntity):
class HomematicipHumiditySensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP humidity sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the thermometer device."""
super().__init__(hap, device, post="Humidity")
@ -202,6 +213,8 @@ class HomematicipHumiditySensor(HomematicipGenericEntity, SensorEntity):
class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP thermometer."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the thermometer device."""
super().__init__(hap, device, post="Temperature")
@ -239,6 +252,8 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity):
class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP Illuminance sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device."""
super().__init__(hap, device, post="Illuminance")
@ -277,6 +292,8 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
class HomematicipPowerSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP power measuring sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device."""
super().__init__(hap, device, post="Power")
@ -297,6 +314,31 @@ class HomematicipPowerSensor(HomematicipGenericEntity, SensorEntity):
return POWER_WATT
class HomematicipEnergySensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP energy measuring sensor."""
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device."""
super().__init__(hap, device, post="Energy")
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_ENERGY
@property
def native_value(self) -> float:
"""Return the energy counter value."""
return self._device.energyCounter
@property
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return ENERGY_KILO_WATT_HOUR
class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP wind speed sensor."""

View File

@ -22,7 +22,7 @@ async def test_hmip_load_all_supported_devices(hass, default_mock_hap_factory):
test_devices=None, test_groups=None
)
assert len(mock_hap.hmip_device_by_entity_id) == 253
assert len(mock_hap.hmip_device_by_entity_id) == 258
async def test_hmip_remove_device(hass, default_mock_hap_factory):