From b75263e486627f80d841f34be368d8dbc8e336d9 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 16 Apr 2026 18:41:22 +0200 Subject: [PATCH] Add heat/cool dmsr device support (#168279) --- homeassistant/components/dsmr/sensor.py | 11 ++++ tests/components/dsmr/test_sensor.py | 68 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index 0c4595e8f7f2..0d050b4c95b3 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -87,6 +87,7 @@ class MbusDeviceType(IntEnum): GAS = 3 HEAT = 4 WATER = 7 + HEAT_COOL = 12 SENSORS: tuple[DSMRSensorEntityDescription, ...] = ( @@ -571,6 +572,16 @@ SENSORS_MBUS_DEVICE_TYPE: dict[int, tuple[DSMRSensorEntityDescription, ...]] = { state_class=SensorStateClass.TOTAL_INCREASING, ), ), + MbusDeviceType.HEAT_COOL: ( + DSMRSensorEntityDescription( + key="heat_reading", + translation_key="heat_meter_reading", + obis_reference="MBUS_METER_READING", + is_heat=True, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + ), + ), } diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index 7e01431a5dc3..c67bdbfd444f 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -1659,6 +1659,74 @@ async def test_heat_meter_mbus( ) +async def test_heat_cool_meter_mbus( + hass: HomeAssistant, dsmr_connection_fixture: tuple[MagicMock, MagicMock, MagicMock] +) -> None: + """Test if heat/cool meter reading is correctly parsed.""" + (connection_factory, _transport, _protocol) = dsmr_connection_fixture + + entry_data = { + "port": "/dev/ttyUSB0", + "dsmr_version": "5", + "serial_id": "1234", + "serial_id_gas": None, + } + entry_options = { + "time_between_update": 0, + } + + telegram = Telegram() + telegram.add( + MBUS_DEVICE_TYPE, + CosemObject((0, 1), [{"value": "012", "unit": ""}]), + "MBUS_DEVICE_TYPE", + ) + telegram.add( + MBUS_METER_READING, + MBusObject( + (0, 1), + [ + {"value": datetime.datetime.fromtimestamp(1551642213)}, + {"value": Decimal("745.695"), "unit": "GJ"}, + ], + ), + "MBUS_METER_READING", + ) + + mock_entry = MockConfigEntry( + domain="dsmr", unique_id="/dev/ttyUSB0", data=entry_data, options=entry_options + ) + + hass.loop.set_debug(True) + mock_entry.add_to_hass(hass) + + await hass.config_entries.async_setup(mock_entry.entry_id) + await hass.async_block_till_done() + + telegram_callback = connection_factory.call_args_list[0][0][2] + + # simulate a telegram pushed from the smartmeter and parsed by dsmr_parser + telegram_callback(telegram) + + # after receiving telegram entities need to have the chance to be created + await hass.async_block_till_done() + + # check if gas consumption is parsed correctly + heat_consumption = hass.states.get("sensor.heat_meter_energy") + assert heat_consumption.state == "745.695" + assert ( + heat_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY + ) + assert ( + heat_consumption.attributes.get("unit_of_measurement") + == UnitOfEnergy.GIGA_JOULE + ) + assert ( + heat_consumption.attributes.get(ATTR_STATE_CLASS) + == SensorStateClass.TOTAL_INCREASING + ) + + def test_all_obis_references_exists() -> None: """Verify that all attributes exist by name in database.""" for sensor in SENSORS: