Add statistics support to Huisbaasje (#54651)

This commit is contained in:
Dennis Schroer 2021-10-22 22:00:44 +02:00 committed by GitHub
parent 823ca7ee40
commit f1091b80a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 367 additions and 48 deletions

View File

@ -229,7 +229,7 @@ homeassistant/components/http/* @home-assistant/core
homeassistant/components/huawei_lte/* @scop @fphammerle homeassistant/components/huawei_lte/* @scop @fphammerle
homeassistant/components/huawei_router/* @abmantis homeassistant/components/huawei_router/* @abmantis
homeassistant/components/hue/* @balloob @frenck homeassistant/components/hue/* @balloob @frenck
homeassistant/components/huisbaasje/* @denniss17 homeassistant/components/huisbaasje/* @dennisschroer
homeassistant/components/humidifier/* @home-assistant/core @Shulyaka homeassistant/components/humidifier/* @home-assistant/core @Shulyaka
homeassistant/components/hunterdouglas_powerview/* @bdraco homeassistant/components/hunterdouglas_powerview/* @bdraco
homeassistant/components/hvv_departures/* @vigonotion homeassistant/components/hvv_departures/* @vigonotion

View File

@ -8,9 +8,10 @@ from huisbaasje.const import (
SOURCE_TYPE_GAS, SOURCE_TYPE_GAS,
) )
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
TIME_HOURS, TIME_HOURS,
@ -49,31 +50,62 @@ SENSORS_INFO = [
"name": "Huisbaasje Current Power", "name": "Huisbaasje Current Power",
"device_class": DEVICE_CLASS_POWER, "device_class": DEVICE_CLASS_POWER,
"source_type": SOURCE_TYPE_ELECTRICITY, "source_type": SOURCE_TYPE_ELECTRICITY,
"state_class": STATE_CLASS_MEASUREMENT,
}, },
{ {
"name": "Huisbaasje Current Power In", "name": "Huisbaasje Current Power In Peak",
"device_class": DEVICE_CLASS_POWER, "device_class": DEVICE_CLASS_POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_IN, "source_type": SOURCE_TYPE_ELECTRICITY_IN,
"state_class": STATE_CLASS_MEASUREMENT,
}, },
{ {
"name": "Huisbaasje Current Power In Low", "name": "Huisbaasje Current Power In Off Peak",
"device_class": DEVICE_CLASS_POWER, "device_class": DEVICE_CLASS_POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_IN_LOW, "source_type": SOURCE_TYPE_ELECTRICITY_IN_LOW,
"state_class": STATE_CLASS_MEASUREMENT,
}, },
{ {
"name": "Huisbaasje Current Power Out", "name": "Huisbaasje Current Power Out Peak",
"device_class": DEVICE_CLASS_POWER, "device_class": DEVICE_CLASS_POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT, "source_type": SOURCE_TYPE_ELECTRICITY_OUT,
"state_class": STATE_CLASS_MEASUREMENT,
}, },
{ {
"name": "Huisbaasje Current Power Out Low", "name": "Huisbaasje Current Power Out Off Peak",
"device_class": DEVICE_CLASS_POWER, "device_class": DEVICE_CLASS_POWER,
"source_type": SOURCE_TYPE_ELECTRICITY_OUT_LOW, "source_type": SOURCE_TYPE_ELECTRICITY_OUT_LOW,
"state_class": STATE_CLASS_MEASUREMENT, },
{
"name": "Huisbaasje Energy Consumption Peak Today",
"device_class": DEVICE_CLASS_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,
"precision": 3,
},
{
"name": "Huisbaasje Energy Consumption Off Peak Today",
"device_class": DEVICE_CLASS_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,
"precision": 3,
},
{
"name": "Huisbaasje Energy Production Peak Today",
"device_class": DEVICE_CLASS_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,
"precision": 3,
},
{
"name": "Huisbaasje Energy Production Off Peak Today",
"device_class": DEVICE_CLASS_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,
"precision": 3,
}, },
{ {
"name": "Huisbaasje Energy Today", "name": "Huisbaasje Energy Today",
@ -113,37 +145,44 @@ SENSORS_INFO = [
"source_type": SOURCE_TYPE_GAS, "source_type": SOURCE_TYPE_GAS,
"icon": "mdi:fire", "icon": "mdi:fire",
"precision": 1, "precision": 1,
"state_class": STATE_CLASS_MEASUREMENT,
}, },
{ {
"name": "Huisbaasje Gas Today", "name": "Huisbaasje Gas Today",
"device_class": DEVICE_CLASS_GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS, "unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS, "source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_DAY, "sensor_type": SENSOR_TYPE_THIS_DAY,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"icon": "mdi:counter", "icon": "mdi:counter",
"precision": 1, "precision": 1,
}, },
{ {
"name": "Huisbaasje Gas This Week", "name": "Huisbaasje Gas This Week",
"device_class": DEVICE_CLASS_GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS, "unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS, "source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_WEEK, "sensor_type": SENSOR_TYPE_THIS_WEEK,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"icon": "mdi:counter", "icon": "mdi:counter",
"precision": 1, "precision": 1,
}, },
{ {
"name": "Huisbaasje Gas This Month", "name": "Huisbaasje Gas This Month",
"device_class": DEVICE_CLASS_GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS, "unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS, "source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_MONTH, "sensor_type": SENSOR_TYPE_THIS_MONTH,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"icon": "mdi:counter", "icon": "mdi:counter",
"precision": 1, "precision": 1,
}, },
{ {
"name": "Huisbaasje Gas This Year", "name": "Huisbaasje Gas This Year",
"device_class": DEVICE_CLASS_GAS,
"unit_of_measurement": VOLUME_CUBIC_METERS, "unit_of_measurement": VOLUME_CUBIC_METERS,
"source_type": SOURCE_TYPE_GAS, "source_type": SOURCE_TYPE_GAS,
"sensor_type": SENSOR_TYPE_THIS_YEAR, "sensor_type": SENSOR_TYPE_THIS_YEAR,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"icon": "mdi:counter", "icon": "mdi:counter",
"precision": 1, "precision": 1,
}, },

View File

@ -3,7 +3,11 @@
"name": "Huisbaasje", "name": "Huisbaasje",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/huisbaasje", "documentation": "https://www.home-assistant.io/integrations/huisbaasje",
"requirements": ["huisbaasje-client==0.1.0"], "requirements": [
"codeowners": ["@denniss17"], "huisbaasje-client==0.1.0"
],
"codeowners": [
"@dennisschroer"
],
"iot_class": "cloud_polling" "iot_class": "cloud_polling"
} }

View File

@ -1,7 +1,9 @@
"""Platform for sensor integration.""" """Platform for sensor integration."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.sensor import SensorEntity import logging
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ID, POWER_WATT from homeassistant.const import CONF_ID, POWER_WATT
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -12,6 +14,8 @@ from homeassistant.helpers.update_coordinator import (
from .const import DATA_COORDINATOR, DOMAIN, SENSOR_TYPE_RATE, SENSORS_INFO from .const import DATA_COORDINATOR, DOMAIN, SENSOR_TYPE_RATE, SENSORS_INFO
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities
@ -40,7 +44,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity):
unit_of_measurement: str = POWER_WATT, unit_of_measurement: str = POWER_WATT,
icon: str = "mdi:lightning-bolt", icon: str = "mdi:lightning-bolt",
precision: int = 0, precision: int = 0,
state_class: str | None = None, state_class: str | None = STATE_CLASS_MEASUREMENT,
) -> None: ) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
super().__init__(coordinator) super().__init__(coordinator)

View File

@ -35,17 +35,17 @@ MOCK_CURRENT_MEASUREMENTS = {
}, },
"electricityOut": { "electricityOut": {
"measurement": None, "measurement": None,
"thisDay": {"value": 0.0, "cost": 0.0}, "thisDay": {"value": 1.51234, "cost": 0.0},
"thisWeek": {"value": 0.0, "cost": 0.0}, "thisWeek": {"value": 2.5, "cost": 0.0},
"thisMonth": {"value": 0.0, "cost": 0.0}, "thisMonth": {"value": 3.5, "cost": 0.0},
"thisYear": {"value": 0.0, "cost": 0.0}, "thisYear": {"value": 4.5, "cost": 0.0},
}, },
"electricityOutLow": { "electricityOutLow": {
"measurement": None, "measurement": None,
"thisDay": {"value": 0.0, "cost": 0.0}, "thisDay": {"value": 1.09281, "cost": 0.0},
"thisWeek": {"value": 0.0, "cost": 0.0}, "thisWeek": {"value": 2.0, "cost": 0.0},
"thisMonth": {"value": 0.0, "cost": 0.0}, "thisMonth": {"value": 3.0, "cost": 0.0},
"thisYear": {"value": 0.0, "cost": 0.0}, "thisYear": {"value": 4.0, "cost": 0.0},
}, },
"gas": { "gas": {
"measurement": { "measurement": {

View File

@ -56,7 +56,7 @@ async def test_setup_entry(hass: HomeAssistant):
# Assert entities are loaded # Assert entities are loaded
entities = hass.states.async_entity_ids("sensor") entities = hass.states.async_entity_ids("sensor")
assert len(entities) == 14 assert len(entities) == 18
# Assert mocks are called # Assert mocks are called
assert len(mock_authenticate.mock_calls) == 1 assert len(mock_authenticate.mock_calls) == 1
@ -128,13 +128,13 @@ async def test_unload_entry(hass: HomeAssistant):
await hass.async_block_till_done() await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED assert config_entry.state is ConfigEntryState.LOADED
entities = hass.states.async_entity_ids("sensor") entities = hass.states.async_entity_ids("sensor")
assert len(entities) == 14 assert len(entities) == 18
# Unload config entry # Unload config entry
await hass.config_entries.async_unload(config_entry.entry_id) await hass.config_entries.async_unload(config_entry.entry_id)
assert config_entry.state is ConfigEntryState.NOT_LOADED assert config_entry.state is ConfigEntryState.NOT_LOADED
entities = hass.states.async_entity_ids("sensor") entities = hass.states.async_entity_ids("sensor")
assert len(entities) == 14 assert len(entities) == 18
for entity in entities: for entity in entities:
assert hass.states.get(entity).state == STATE_UNAVAILABLE assert hass.states.get(entity).state == STATE_UNAVAILABLE

View File

@ -2,7 +2,26 @@
from unittest.mock import patch from unittest.mock import patch
from homeassistant.components import huisbaasje from homeassistant.components import huisbaasje
from homeassistant.const import CONF_ID, CONF_PASSWORD, CONF_USERNAME 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.const import (
ATTR_DEVICE_CLASS,
ATTR_ICON,
ATTR_UNIT_OF_MEASUREMENT,
CONF_ID,
CONF_PASSWORD,
CONF_USERNAME,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
VOLUME_CUBIC_METERS,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -41,25 +60,255 @@ async def test_setup_entry(hass: HomeAssistant):
await hass.async_block_till_done() await hass.async_block_till_done()
# Assert data is loaded # Assert data is loaded
assert hass.states.get("sensor.huisbaasje_current_power").state == "1012.0" current_power = hass.states.get("sensor.huisbaasje_current_power")
assert hass.states.get("sensor.huisbaasje_current_power_in").state == "1012.0" 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_UNIT_OF_MEASUREMENT) == POWER_WATT
current_power_in = hass.states.get("sensor.huisbaasje_current_power_in_peak")
assert current_power_in.state == "1012.0"
assert current_power_in.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
assert current_power_in.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert ( assert (
hass.states.get("sensor.huisbaasje_current_power_in_low").state == "unknown" current_power_in.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
) )
assert hass.states.get("sensor.huisbaasje_current_power_out").state == "unknown" assert current_power_in.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
current_power_in_low = hass.states.get(
"sensor.huisbaasje_current_power_in_off_peak"
)
assert current_power_in_low.state == "unknown"
assert ( assert (
hass.states.get("sensor.huisbaasje_current_power_out_low").state current_power_in_low.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
== "unknown" )
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
)
assert (
current_power_in_low.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
)
current_power_out = hass.states.get("sensor.huisbaasje_current_power_out_peak")
assert current_power_out.state == "unknown"
assert current_power_out.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
assert current_power_out.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
current_power_out.attributes.get(ATTR_STATE_CLASS)
== STATE_CLASS_MEASUREMENT
)
assert current_power_out.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
current_power_out_low = hass.states.get(
"sensor.huisbaasje_current_power_out_off_peak"
)
assert current_power_out_low.state == "unknown"
assert (
current_power_out_low.attributes.get(ATTR_DEVICE_CLASS)
== DEVICE_CLASS_POWER
)
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
)
assert (
current_power_out_low.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
)
energy_consumption_peak_today = hass.states.get(
"sensor.huisbaasje_energy_consumption_peak_today"
)
assert energy_consumption_peak_today.state == "2.67"
assert (
energy_consumption_peak_today.attributes.get(ATTR_DEVICE_CLASS)
== DEVICE_CLASS_ENERGY
)
assert (
energy_consumption_peak_today.attributes.get(ATTR_ICON)
== "mdi:lightning-bolt"
)
assert (
energy_consumption_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
energy_consumption_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_consumption_off_peak_today = hass.states.get(
"sensor.huisbaasje_energy_consumption_off_peak_today"
)
assert energy_consumption_off_peak_today.state == "0.627"
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_DEVICE_CLASS)
== DEVICE_CLASS_ENERGY
)
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_ICON)
== "mdi:lightning-bolt"
)
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
energy_consumption_off_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_production_peak_today = hass.states.get(
"sensor.huisbaasje_energy_production_peak_today"
)
assert energy_production_peak_today.state == "1.512"
assert (
energy_production_peak_today.attributes.get(ATTR_DEVICE_CLASS)
== DEVICE_CLASS_ENERGY
)
assert (
energy_production_peak_today.attributes.get(ATTR_ICON)
== "mdi:lightning-bolt"
)
assert (
energy_production_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
energy_production_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_production_off_peak_today = hass.states.get(
"sensor.huisbaasje_energy_production_off_peak_today"
)
assert energy_production_off_peak_today.state == "1.093"
assert (
energy_production_off_peak_today.attributes.get(ATTR_DEVICE_CLASS)
== DEVICE_CLASS_ENERGY
)
assert (
energy_production_off_peak_today.attributes.get(ATTR_ICON)
== "mdi:lightning-bolt"
)
assert (
energy_production_off_peak_today.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
energy_production_off_peak_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_today = hass.states.get("sensor.huisbaasje_energy_today")
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_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_this_week = hass.states.get("sensor.huisbaasje_energy_this_week")
assert energy_this_week.state == "17.5"
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
)
assert (
energy_this_week.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_this_month = hass.states.get("sensor.huisbaasje_energy_this_month")
assert energy_this_month.state == "103.3"
assert (
energy_this_month.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
)
assert energy_this_month.attributes.get(ATTR_ICON) == "mdi:lightning-bolt"
assert (
energy_this_month.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_MEASUREMENT
)
assert (
energy_this_month.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
energy_this_year = hass.states.get("sensor.huisbaasje_energy_this_year")
assert energy_this_year.state == "673.0"
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
)
assert (
energy_this_year.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== ENERGY_KILO_WATT_HOUR
)
current_gas = hass.states.get("sensor.huisbaasje_current_gas")
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_UNIT_OF_MEASUREMENT)
== FLOW_CUBIC_METERS_PER_HOUR
)
gas_today = hass.states.get("sensor.huisbaasje_gas_today")
assert gas_today.state == "1.1"
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
)
assert gas_today.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
gas_this_week = hass.states.get("sensor.huisbaasje_gas_this_week")
assert gas_this_week.state == "5.6"
assert gas_this_week.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_this_week.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_week.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
gas_this_week.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== VOLUME_CUBIC_METERS
)
gas_this_month = hass.states.get("sensor.huisbaasje_gas_this_month")
assert gas_this_month.state == "39.1"
assert gas_this_month.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_this_month.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_month.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
gas_this_month.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== VOLUME_CUBIC_METERS
)
gas_this_year = hass.states.get("sensor.huisbaasje_gas_this_year")
assert gas_this_year.state == "116.7"
assert gas_this_year.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_this_year.attributes.get(ATTR_ICON) == "mdi:counter"
assert (
gas_this_year.attributes.get(ATTR_STATE_CLASS)
is STATE_CLASS_TOTAL_INCREASING
)
assert (
gas_this_year.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== VOLUME_CUBIC_METERS
) )
assert hass.states.get("sensor.huisbaasje_current_gas").state == "0.0"
assert hass.states.get("sensor.huisbaasje_energy_today").state == "3.3"
assert hass.states.get("sensor.huisbaasje_energy_this_week").state == "17.5"
assert hass.states.get("sensor.huisbaasje_energy_this_month").state == "103.3"
assert hass.states.get("sensor.huisbaasje_energy_this_year").state == "673.0"
assert hass.states.get("sensor.huisbaasje_gas_today").state == "1.1"
assert hass.states.get("sensor.huisbaasje_gas_this_week").state == "5.6"
assert hass.states.get("sensor.huisbaasje_gas_this_month").state == "39.1"
assert hass.states.get("sensor.huisbaasje_gas_this_year").state == "116.7"
# Assert mocks are called # Assert mocks are called
assert len(mock_authenticate.mock_calls) == 1 assert len(mock_authenticate.mock_calls) == 1
@ -97,17 +346,40 @@ async def test_setup_entry_absent_measurement(hass: HomeAssistant):
# Assert data is loaded # Assert data is loaded
assert hass.states.get("sensor.huisbaasje_current_power").state == "1012.0" assert hass.states.get("sensor.huisbaasje_current_power").state == "1012.0"
assert hass.states.get("sensor.huisbaasje_current_power_in").state == "unknown"
assert ( assert (
hass.states.get("sensor.huisbaasje_current_power_in_low").state == "unknown" hass.states.get("sensor.huisbaasje_current_power_in_peak").state
== "unknown"
) )
assert hass.states.get("sensor.huisbaasje_current_power_out").state == "unknown"
assert ( assert (
hass.states.get("sensor.huisbaasje_current_power_out_low").state hass.states.get("sensor.huisbaasje_current_power_in_off_peak").state
== "unknown"
)
assert (
hass.states.get("sensor.huisbaasje_current_power_out_peak").state
== "unknown"
)
assert (
hass.states.get("sensor.huisbaasje_current_power_out_off_peak").state
== "unknown" == "unknown"
) )
assert hass.states.get("sensor.huisbaasje_current_gas").state == "unknown" assert hass.states.get("sensor.huisbaasje_current_gas").state == "unknown"
assert hass.states.get("sensor.huisbaasje_energy_today").state == "3.3" assert hass.states.get("sensor.huisbaasje_energy_today").state == "3.3"
assert (
hass.states.get("sensor.huisbaasje_energy_consumption_peak_today").state
== "unknown"
)
assert (
hass.states.get("sensor.huisbaasje_energy_consumption_off_peak_today").state
== "unknown"
)
assert (
hass.states.get("sensor.huisbaasje_energy_production_peak_today").state
== "unknown"
)
assert (
hass.states.get("sensor.huisbaasje_energy_production_off_peak_today").state
== "unknown"
)
assert hass.states.get("sensor.huisbaasje_gas_today").state == "unknown" assert hass.states.get("sensor.huisbaasje_gas_today").state == "unknown"
# Assert mocks are called # Assert mocks are called