1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Use new enums in huisbaasje (#61776)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-14 10:54:47 +01:00 committed by GitHub
parent b7c0b21c6c
commit eddc1ae0ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 59 deletions

View File

@ -8,15 +8,8 @@ from huisbaasje.const import (
SOURCE_TYPE_GAS,
)
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
from homeassistant.const import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
TIME_HOURS,
VOLUME_CUBIC_METERS,
)
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import ENERGY_KILO_WATT_HOUR, TIME_HOURS, VOLUME_CUBIC_METERS
DATA_COORDINATOR = "coordinator"
@ -48,68 +41,68 @@ SOURCE_TYPES = [
SENSORS_INFO = [
{
"name": "Huisbaasje Current Power",
"device_class": DEVICE_CLASS_POWER,
"device_class": SensorDeviceClass.POWER,
"source_type": SOURCE_TYPE_ELECTRICITY,
},
{
"name": "Huisbaasje Current Power In Peak",
"device_class": DEVICE_CLASS_POWER,
"device_class": SensorDeviceClass.POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_IN,
},
{
"name": "Huisbaasje Current Power In Off Peak",
"device_class": DEVICE_CLASS_POWER,
"device_class": SensorDeviceClass.POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_IN_LOW,
},
{
"name": "Huisbaasje Current Power Out Peak",
"device_class": DEVICE_CLASS_POWER,
"device_class": SensorDeviceClass.POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT,
},
{
"name": "Huisbaasje Current Power Out Off Peak",
"device_class": DEVICE_CLASS_POWER,
"device_class": SensorDeviceClass.POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT_LOW,
},
{
"name": "Huisbaasje Energy Consumption Peak Today",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY_IN,
"sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"precision": 3,
},
{
"name": "Huisbaasje Energy Consumption Off Peak Today",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY_IN_LOW,
"sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"precision": 3,
},
{
"name": "Huisbaasje Energy Production Peak Today",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT,
"sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"precision": 3,
},
{
"name": "Huisbaasje Energy Production Off Peak Today",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT_LOW,
"sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"precision": 3,
},
{
"name": "Huisbaasje Energy Today",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY,
"sensor_type": SENSOR_TYPE_THIS_DAY,
@ -117,7 +110,7 @@ SENSORS_INFO = [
},
{
"name": "Huisbaasje Energy This Week",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY,
"sensor_type": SENSOR_TYPE_THIS_WEEK,
@ -125,7 +118,7 @@ SENSORS_INFO = [
},
{
"name": "Huisbaasje Energy This Month",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY,
"sensor_type": SENSOR_TYPE_THIS_MONTH,
@ -133,7 +126,7 @@ SENSORS_INFO = [
},
{
"name": "Huisbaasje Energy This Year",
"device_class": DEVICE_CLASS_ENERGY,
"device_class": SensorDeviceClass.ENERGY,
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
"source_type": SOURCE_TYPE_ELECTRICITY,
"sensor_type": SENSOR_TYPE_THIS_YEAR,
@ -148,41 +141,41 @@ SENSORS_INFO = [
},
{
"name": "Huisbaasje Gas Today",
"device_class": DEVICE_CLASS_GAS,
"device_class": SensorDeviceClass.GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": "mdi:counter",
"precision": 1,
},
{
"name": "Huisbaasje Gas This Week",
"device_class": DEVICE_CLASS_GAS,
"device_class": SensorDeviceClass.GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_WEEK,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": "mdi:counter",
"precision": 1,
},
{
"name": "Huisbaasje Gas This Month",
"device_class": DEVICE_CLASS_GAS,
"device_class": SensorDeviceClass.GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_MONTH,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": "mdi:counter",
"precision": 1,
},
{
"name": "Huisbaasje Gas This Year",
"device_class": DEVICE_CLASS_GAS,
"device_class": SensorDeviceClass.GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_YEAR,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": "mdi:counter",
"precision": 1,
},

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import logging
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ID, POWER_WATT
from homeassistant.core import HomeAssistant
@ -44,7 +44,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity):
unit_of_measurement: str = POWER_WATT,
icon: str = "mdi:lightning-bolt",
precision: int = 0,
state_class: str | None = STATE_CLASS_MEASUREMENT,
state_class: str | None = SensorStateClass.MEASUREMENT,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)

View File

@ -3,11 +3,7 @@ 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,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ICON,
@ -64,7 +60,10 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_power.state == "1012.0"
assert current_power.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
assert current_power.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert current_power.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
current_power.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.MEASUREMENT
)
assert current_power.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
current_power_in = hass.states.get("sensor.huisbaasje_current_power_in_peak")
@ -72,7 +71,8 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_power_in.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
assert current_power_in.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
current_power_in.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
current_power_in.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.MEASUREMENT
)
assert current_power_in.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
@ -86,7 +86,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_power_in_low.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
current_power_in_low.attributes.get(ATTR_STATE_CLASS)
== STATE_CLASS_MEASUREMENT
is SensorStateClass.MEASUREMENT
)
assert (
current_power_in_low.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
@ -98,7 +98,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_power_out.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
current_power_out.attributes.get(ATTR_STATE_CLASS)
== STATE_CLASS_MEASUREMENT
is SensorStateClass.MEASUREMENT
)
assert current_power_out.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
@ -113,7 +113,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_power_out_low.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
current_power_out_low.attributes.get(ATTR_STATE_CLASS)
== STATE_CLASS_MEASUREMENT
is SensorStateClass.MEASUREMENT
)
assert (
current_power_out_low.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
@ -133,7 +133,7 @@ async def test_setup_entry(hass: HomeAssistant):
)
assert (
energy_consumption_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
energy_consumption_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -154,7 +154,7 @@ async def test_setup_entry(hass: HomeAssistant):
)
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -175,7 +175,7 @@ async def test_setup_entry(hass: HomeAssistant):
)
assert (
energy_production_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
energy_production_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -196,7 +196,7 @@ async def test_setup_entry(hass: HomeAssistant):
)
assert (
energy_production_off_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
energy_production_off_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -207,7 +207,10 @@ async def test_setup_entry(hass: HomeAssistant):
assert energy_today.state == "3.3"
assert energy_today.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
assert energy_today.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert energy_today.attributes.get(ATTR_STATE_CLASS) is STATE_CLASS_MEASUREMENT
assert (
energy_today.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.MEASUREMENT
)
assert (
energy_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
@ -218,7 +221,8 @@ async def test_setup_entry(hass: HomeAssistant):
assert energy_this_week.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
assert energy_this_week.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
energy_this_week.attributes.get(ATTR_STATE_CLASS) is STATE_CLASS_MEASUREMENT
energy_this_week.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.MEASUREMENT
)
assert (
energy_this_week.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -233,7 +237,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert energy_this_month.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
energy_this_month.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_MEASUREMENT
is SensorStateClass.MEASUREMENT
)
assert (
energy_this_month.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -245,7 +249,8 @@ async def test_setup_entry(hass: HomeAssistant):
assert energy_this_year.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
assert energy_this_year.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
energy_this_year.attributes.get(ATTR_STATE_CLASS) is STATE_CLASS_MEASUREMENT
energy_this_year.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.MEASUREMENT
)
assert (
energy_this_year.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -256,7 +261,9 @@ async def test_setup_entry(hass: HomeAssistant):
assert current_gas.state == "0.0"
assert current_gas.attributes.get(ATTR_DEVICE_CLASS) is None
assert current_gas.attributes.get(ATTR_ICON) == "mdi:fire"
assert current_gas.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
current_gas.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
)
assert (
current_gas.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== FLOW_CUBIC_METERS_PER_HOUR
@ -267,7 +274,8 @@ async def test_setup_entry(hass: HomeAssistant):
assert gas_today.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_today.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_today.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
gas_today.attributes.get(ATTR_STATE_CLASS)
is SensorStateClass.TOTAL_INCREASING
)
assert gas_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
@ -277,7 +285,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert gas_this_week.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_week.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
gas_this_week.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -290,7 +298,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert gas_this_month.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_month.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
gas_this_month.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@ -303,7 +311,7 @@ async def test_setup_entry(hass: HomeAssistant):
assert gas_this_year.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_year.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
is SensorStateClass.TOTAL_INCREASING
)
assert (
gas_this_year.attributes.get(ATTR_UNIT_OF_MEASUREMENT)