Use UnitOfVolumeFlowRate in huisbaasje and plugwise (#88967)

This commit is contained in:
epenet 2023-03-01 15:26:39 +01:00 committed by GitHub
parent 0c66346fb0
commit 23cdafd12f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 11 deletions

View file

@ -8,14 +8,10 @@ from energyflip.const import (
SOURCE_TYPE_GAS,
)
from homeassistant.const import UnitOfTime, UnitOfVolume
DATA_COORDINATOR = "coordinator"
DOMAIN = "huisbaasje"
FLOW_CUBIC_METERS_PER_HOUR = f"{UnitOfVolume.CUBIC_METERS}/{UnitOfTime.HOURS}"
"""Interval in seconds between polls to huisbaasje."""
POLLING_INTERVAL = 20

View file

@ -21,7 +21,13 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ID, UnitOfEnergy, UnitOfPower, UnitOfVolume
from homeassistant.const import (
CONF_ID,
UnitOfEnergy,
UnitOfPower,
UnitOfVolume,
UnitOfVolumeFlowRate,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
@ -32,7 +38,6 @@ from homeassistant.helpers.update_coordinator import (
from .const import (
DATA_COORDINATOR,
DOMAIN,
FLOW_CUBIC_METERS_PER_HOUR,
SENSOR_TYPE_RATE,
SENSOR_TYPE_THIS_DAY,
SENSOR_TYPE_THIS_MONTH,
@ -179,7 +184,7 @@ SENSORS_INFO = [
),
HuisbaasjeSensorEntityDescription(
name="Huisbaasje Current Gas",
native_unit_of_measurement=FLOW_CUBIC_METERS_PER_HOUR,
native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
sensor_type=SENSOR_TYPE_RATE,
state_class=SensorStateClass.MEASUREMENT,
key=SOURCE_TYPE_GAS,

View file

@ -17,8 +17,8 @@ from homeassistant.const import (
UnitOfPower,
UnitOfPressure,
UnitOfTemperature,
UnitOfTime,
UnitOfVolume,
UnitOfVolumeFlowRate,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -305,7 +305,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
key="gas_consumed_interval",
name="Gas consumed interval",
icon="mdi:meter-gas",
native_unit_of_measurement=f"{UnitOfVolume.CUBIC_METERS}/{UnitOfTime.HOURS}",
native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(

View file

@ -2,7 +2,6 @@
from unittest.mock import patch
from homeassistant.components import huisbaasje
from homeassistant.components.huisbaasje.const import FLOW_CUBIC_METERS_PER_HOUR
from homeassistant.components.sensor import (
ATTR_STATE_CLASS,
SensorDeviceClass,
@ -18,6 +17,7 @@ from homeassistant.const import (
UnitOfEnergy,
UnitOfPower,
UnitOfVolume,
UnitOfVolumeFlowRate,
)
from homeassistant.core import HomeAssistant
@ -292,7 +292,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
)
assert (
current_gas.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== FLOW_CUBIC_METERS_PER_HOUR
== UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR
)
gas_today = hass.states.get("sensor.huisbaasje_gas_today")