Add peak usage sensors to dsmr (#102227)

This commit is contained in:
dupondje 2023-10-20 15:59:34 +02:00 committed by GitHub
parent a187164bf8
commit da653c36fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View File

@ -356,6 +356,22 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key="belgium_current_average_demand",
translation_key="current_average_demand",
obis_reference=obis_references.BELGIUM_CURRENT_AVERAGE_DEMAND,
dsmr_versions={"5B"},
force_update=True,
device_class=SensorDeviceClass.POWER,
),
DSMRSensorEntityDescription(
key="belgium_maximum_demand_current_month",
translation_key="maximum_demand_current_month",
obis_reference=obis_references.BELGIUM_MAXIMUM_DEMAND_MONTH,
dsmr_versions={"5B"},
force_update=True,
device_class=SensorDeviceClass.POWER,
),
DSMRSensorEntityDescription(
key="hourly_gas_meter_reading",
translation_key="gas_meter_reading",

View File

@ -76,6 +76,12 @@
"gas_meter_reading": {
"name": "Gas consumption"
},
"current_average_demand": {
"name": "Current average demand"
},
"maximum_demand_current_month": {
"name": "Maximum demand current month"
},
"instantaneous_active_power_l1_negative": {
"name": "Power production phase L1"
},

View File

@ -480,7 +480,11 @@ async def test_belgian_meter(hass: HomeAssistant, dsmr_connection_fixture) -> No
"""Test if Belgian meter is correctly parsed."""
(connection_factory, transport, protocol) = dsmr_connection_fixture
from dsmr_parser.obis_references import ELECTRICITY_ACTIVE_TARIFF
from dsmr_parser.obis_references import (
BELGIUM_CURRENT_AVERAGE_DEMAND,
BELGIUM_MAXIMUM_DEMAND_MONTH,
ELECTRICITY_ACTIVE_TARIFF,
)
from dsmr_parser.objects import CosemObject, MBusObject
entry_data = {
@ -503,6 +507,17 @@ async def test_belgian_meter(hass: HomeAssistant, dsmr_connection_fixture) -> No
{"value": Decimal(745.695), "unit": "m3"},
],
),
BELGIUM_CURRENT_AVERAGE_DEMAND: CosemObject(
BELGIUM_CURRENT_AVERAGE_DEMAND,
[{"value": Decimal(1.75), "unit": "kW"}],
),
BELGIUM_MAXIMUM_DEMAND_MONTH: MBusObject(
BELGIUM_MAXIMUM_DEMAND_MONTH,
[
{"value": datetime.datetime.fromtimestamp(1551642218)},
{"value": Decimal(4.11), "unit": "kW"},
],
),
ELECTRICITY_ACTIVE_TARIFF: CosemObject(
ELECTRICITY_ACTIVE_TARIFF, [{"value": "0001", "unit": ""}]
),
@ -534,6 +549,20 @@ async def test_belgian_meter(hass: HomeAssistant, dsmr_connection_fixture) -> No
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
# check current average demand is parsed correctly
avg_demand = hass.states.get("sensor.electricity_meter_current_average_demand")
assert avg_demand.state == "1.75"
assert avg_demand.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.KILO_WATT
assert avg_demand.attributes.get(ATTR_STATE_CLASS) is None
# check max average demand is parsed correctly
max_demand = hass.states.get(
"sensor.electricity_meter_maximum_demand_current_month"
)
assert max_demand.state == "4.11"
assert max_demand.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.KILO_WATT
assert max_demand.attributes.get(ATTR_STATE_CLASS) is None
# check if gas consumption is parsed correctly
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
assert gas_consumption.state == "745.695"