diff --git a/homeassistant/components/dsmr/const.py b/homeassistant/components/dsmr/const.py index 5e1a54aedc4..7bc0247aea6 100644 --- a/homeassistant/components/dsmr/const.py +++ b/homeassistant/components/dsmr/const.py @@ -34,3 +34,6 @@ DSMR_VERSIONS = {"2.2", "4", "5", "5B", "5L", "5S", "Q3D"} DSMR_PROTOCOL = "dsmr_protocol" RFXTRX_DSMR_PROTOCOL = "rfxtrx_dsmr_protocol" + +# Temp obis until sensors replaced by mbus variants +BELGIUM_5MIN_GAS_METER_READING = r"\d-\d:24\.2\.3.+?\r\n" diff --git a/homeassistant/components/dsmr/manifest.json b/homeassistant/components/dsmr/manifest.json index 3fc81d2f8e7..b3f59a15b80 100644 --- a/homeassistant/components/dsmr/manifest.json +++ b/homeassistant/components/dsmr/manifest.json @@ -7,5 +7,5 @@ "integration_type": "hub", "iot_class": "local_push", "loggers": ["dsmr_parser"], - "requirements": ["dsmr-parser==0.33"] + "requirements": ["dsmr-parser==1.3.0"] } diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index 5bd5138a7d6..2ff0a834e9e 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -39,6 +39,7 @@ from homeassistant.helpers.typing import StateType from homeassistant.util import Throttle from .const import ( + BELGIUM_5MIN_GAS_METER_READING, CONF_DSMR_VERSION, CONF_PRECISION, CONF_PROTOCOL, @@ -361,7 +362,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = ( DSMRSensorEntityDescription( key="belgium_5min_gas_meter_reading", translation_key="gas_meter_reading", - obis_reference=obis_references.BELGIUM_5MIN_GAS_METER_READING, + obis_reference=BELGIUM_5MIN_GAS_METER_READING, dsmr_versions={"5B"}, is_gas=True, force_update=True, diff --git a/requirements_all.txt b/requirements_all.txt index 8eff0d9e307..c5b17fa6a56 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -701,7 +701,7 @@ dovado==0.4.1 dremel3dpy==2.1.1 # homeassistant.components.dsmr -dsmr-parser==0.33 +dsmr-parser==1.3.0 # homeassistant.components.dwd_weather_warnings dwdwfsapi==1.0.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 314a8b15398..047a0c028b5 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -572,7 +572,7 @@ discovery30303==0.2.1 dremel3dpy==2.1.1 # homeassistant.components.dsmr -dsmr-parser==0.33 +dsmr-parser==1.3.0 # homeassistant.components.dwd_weather_warnings dwdwfsapi==1.0.6 diff --git a/tests/components/dsmr/conftest.py b/tests/components/dsmr/conftest.py index 8c94c756edc..67e8b724a97 100644 --- a/tests/components/dsmr/conftest.py +++ b/tests/components/dsmr/conftest.py @@ -68,9 +68,15 @@ async def dsmr_connection_send_validate_fixture(hass): protocol = MagicMock(spec=DSMRProtocol) protocol.telegram = { - EQUIPMENT_IDENTIFIER: CosemObject([{"value": "12345678", "unit": ""}]), - EQUIPMENT_IDENTIFIER_GAS: CosemObject([{"value": "123456789", "unit": ""}]), - P1_MESSAGE_TIMESTAMP: CosemObject([{"value": "12345678", "unit": ""}]), + EQUIPMENT_IDENTIFIER: CosemObject( + EQUIPMENT_IDENTIFIER, [{"value": "12345678", "unit": ""}] + ), + EQUIPMENT_IDENTIFIER_GAS: CosemObject( + EQUIPMENT_IDENTIFIER_GAS, [{"value": "123456789", "unit": ""}] + ), + P1_MESSAGE_TIMESTAMP: CosemObject( + P1_MESSAGE_TIMESTAMP, [{"value": "12345678", "unit": ""}] + ), } async def connection_factory(*args, **kwargs): @@ -78,20 +84,22 @@ async def dsmr_connection_send_validate_fixture(hass): if args[1] == "5L": protocol.telegram = { LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemObject( - [{"value": "12345678", "unit": ""}] + LUXEMBOURG_EQUIPMENT_IDENTIFIER, [{"value": "12345678", "unit": ""}] ), EQUIPMENT_IDENTIFIER_GAS: CosemObject( - [{"value": "123456789", "unit": ""}] + EQUIPMENT_IDENTIFIER_GAS, [{"value": "123456789", "unit": ""}] ), } if args[1] == "5S": protocol.telegram = { - P1_MESSAGE_TIMESTAMP: CosemObject([{"value": "12345678", "unit": ""}]), + P1_MESSAGE_TIMESTAMP: CosemObject( + P1_MESSAGE_TIMESTAMP, [{"value": "12345678", "unit": ""}] + ), } if args[1] == "Q3D": protocol.telegram = { Q3D_EQUIPMENT_IDENTIFIER: CosemObject( - [{"value": "12345678", "unit": ""}] + Q3D_EQUIPMENT_IDENTIFIER, [{"value": "12345678", "unit": ""}] ), } @@ -129,9 +137,15 @@ async def rfxtrx_dsmr_connection_send_validate_fixture(hass): protocol = MagicMock(spec=RFXtrxDSMRProtocol) protocol.telegram = { - EQUIPMENT_IDENTIFIER: CosemObject([{"value": "12345678", "unit": ""}]), - EQUIPMENT_IDENTIFIER_GAS: CosemObject([{"value": "123456789", "unit": ""}]), - P1_MESSAGE_TIMESTAMP: CosemObject([{"value": "12345678", "unit": ""}]), + EQUIPMENT_IDENTIFIER: CosemObject( + EQUIPMENT_IDENTIFIER, [{"value": "12345678", "unit": ""}] + ), + EQUIPMENT_IDENTIFIER_GAS: CosemObject( + EQUIPMENT_IDENTIFIER_GAS, [{"value": "123456789", "unit": ""}] + ), + P1_MESSAGE_TIMESTAMP: CosemObject( + P1_MESSAGE_TIMESTAMP, [{"value": "12345678", "unit": ""}] + ), } async def connection_factory(*args, **kwargs): diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index ed04bda02f8..6972f0cc0cf 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -11,6 +11,7 @@ from itertools import chain, repeat from unittest.mock import DEFAULT, MagicMock from homeassistant import config_entries +from homeassistant.components.dsmr.const import BELGIUM_5MIN_GAS_METER_READING from homeassistant.components.sensor import ( ATTR_OPTIONS, ATTR_STATE_CLASS, @@ -59,14 +60,18 @@ async def test_default_setup(hass: HomeAssistant, dsmr_connection_fixture) -> No telegram = { CURRENT_ELECTRICITY_USAGE: CosemObject( - [{"value": Decimal("0.0"), "unit": UnitOfPower.WATT}] + CURRENT_ELECTRICITY_USAGE, + [{"value": Decimal("0.0"), "unit": UnitOfPower.WATT}], + ), + ELECTRICITY_ACTIVE_TARIFF: CosemObject( + ELECTRICITY_ACTIVE_TARIFF, [{"value": "0001", "unit": ""}] ), - ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]), GAS_METER_READING: MBusObject( + GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(745.695), "unit": UnitOfVolume.CUBIC_METERS}, - ] + ], ), } @@ -199,12 +204,15 @@ async def test_v4_meter(hass: HomeAssistant, dsmr_connection_fixture) -> None: telegram = { HOURLY_GAS_METER_READING: MBusObject( + HOURLY_GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(745.695), "unit": "m3"}, - ] + ], + ), + ELECTRICITY_ACTIVE_TARIFF: CosemObject( + ELECTRICITY_ACTIVE_TARIFF, [{"value": "0001", "unit": ""}] ), - ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]), } mock_entry = MockConfigEntry( @@ -275,12 +283,15 @@ async def test_v5_meter(hass: HomeAssistant, dsmr_connection_fixture) -> None: telegram = { HOURLY_GAS_METER_READING: MBusObject( + HOURLY_GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(745.695), "unit": "m3"}, - ] + ], + ), + ELECTRICITY_ACTIVE_TARIFF: CosemObject( + ELECTRICITY_ACTIVE_TARIFF, [{"value": "0001", "unit": ""}] ), - ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]), } mock_entry = MockConfigEntry( @@ -348,16 +359,19 @@ async def test_luxembourg_meter(hass: HomeAssistant, dsmr_connection_fixture) -> telegram = { HOURLY_GAS_METER_READING: MBusObject( + HOURLY_GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(745.695), "unit": "m3"}, - ] + ], ), ELECTRICITY_IMPORTED_TOTAL: CosemObject( - [{"value": Decimal(123.456), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_IMPORTED_TOTAL, + [{"value": Decimal(123.456), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), ELECTRICITY_EXPORTED_TOTAL: CosemObject( - [{"value": Decimal(654.321), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_EXPORTED_TOTAL, + [{"value": Decimal(654.321), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), } @@ -416,10 +430,7 @@ 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 ( - BELGIUM_5MIN_GAS_METER_READING, - ELECTRICITY_ACTIVE_TARIFF, - ) + from dsmr_parser.obis_references import ELECTRICITY_ACTIVE_TARIFF from dsmr_parser.objects import CosemObject, MBusObject entry_data = { @@ -436,12 +447,15 @@ async def test_belgian_meter(hass: HomeAssistant, dsmr_connection_fixture) -> No telegram = { BELGIUM_5MIN_GAS_METER_READING: MBusObject( + BELGIUM_5MIN_GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(745.695), "unit": "m3"}, - ] + ], + ), + ELECTRICITY_ACTIVE_TARIFF: CosemObject( + ELECTRICITY_ACTIVE_TARIFF, [{"value": "0001", "unit": ""}] ), - ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]), } mock_entry = MockConfigEntry( @@ -503,7 +517,11 @@ async def test_belgian_meter_low(hass: HomeAssistant, dsmr_connection_fixture) - "time_between_update": 0, } - telegram = {ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0002", "unit": ""}])} + telegram = { + ELECTRICITY_ACTIVE_TARIFF: CosemObject( + ELECTRICITY_ACTIVE_TARIFF, [{"value": "0002", "unit": ""}] + ) + } mock_entry = MockConfigEntry( domain="dsmr", unique_id="/dev/ttyUSB0", data=entry_data, options=entry_options @@ -556,10 +574,12 @@ async def test_swedish_meter(hass: HomeAssistant, dsmr_connection_fixture) -> No telegram = { ELECTRICITY_IMPORTED_TOTAL: CosemObject( - [{"value": Decimal(123.456), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_IMPORTED_TOTAL, + [{"value": Decimal(123.456), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), ELECTRICITY_EXPORTED_TOTAL: CosemObject( - [{"value": Decimal(654.321), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_EXPORTED_TOTAL, + [{"value": Decimal(654.321), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), } @@ -629,10 +649,12 @@ async def test_easymeter(hass: HomeAssistant, dsmr_connection_fixture) -> None: telegram = { ELECTRICITY_IMPORTED_TOTAL: CosemObject( - [{"value": Decimal(54184.6316), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_IMPORTED_TOTAL, + [{"value": Decimal(54184.6316), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), ELECTRICITY_EXPORTED_TOTAL: CosemObject( - [{"value": Decimal(19981.1069), "unit": UnitOfEnergy.KILO_WATT_HOUR}] + ELECTRICITY_EXPORTED_TOTAL, + [{"value": Decimal(19981.1069), "unit": UnitOfEnergy.KILO_WATT_HOUR}], ), } @@ -856,10 +878,11 @@ async def test_gas_meter_providing_energy_reading( telegram = { GAS_METER_READING: MBusObject( + GAS_METER_READING, [ {"value": datetime.datetime.fromtimestamp(1551642213)}, {"value": Decimal(123.456), "unit": UnitOfEnergy.GIGA_JOULE}, - ] + ], ), }