mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Use right equipment identifier in DSMR setup (#103494)
This commit is contained in:
parent
a35f5dc6f5
commit
91182603d5
@ -53,6 +53,8 @@ class DSMRConnection:
|
|||||||
self._protocol = protocol
|
self._protocol = protocol
|
||||||
self._telegram: dict[str, DSMRObject] = {}
|
self._telegram: dict[str, DSMRObject] = {}
|
||||||
self._equipment_identifier = obis_ref.EQUIPMENT_IDENTIFIER
|
self._equipment_identifier = obis_ref.EQUIPMENT_IDENTIFIER
|
||||||
|
if dsmr_version == "5B":
|
||||||
|
self._equipment_identifier = obis_ref.BELGIUM_EQUIPMENT_IDENTIFIER
|
||||||
if dsmr_version == "5L":
|
if dsmr_version == "5L":
|
||||||
self._equipment_identifier = obis_ref.LUXEMBOURG_EQUIPMENT_IDENTIFIER
|
self._equipment_identifier = obis_ref.LUXEMBOURG_EQUIPMENT_IDENTIFIER
|
||||||
if dsmr_version == "Q3D":
|
if dsmr_version == "Q3D":
|
||||||
|
@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
from dsmr_parser.clients.protocol import DSMRProtocol
|
from dsmr_parser.clients.protocol import DSMRProtocol
|
||||||
from dsmr_parser.clients.rfxtrx_protocol import RFXtrxDSMRProtocol
|
from dsmr_parser.clients.rfxtrx_protocol import RFXtrxDSMRProtocol
|
||||||
from dsmr_parser.obis_references import (
|
from dsmr_parser.obis_references import (
|
||||||
|
BELGIUM_EQUIPMENT_IDENTIFIER,
|
||||||
EQUIPMENT_IDENTIFIER,
|
EQUIPMENT_IDENTIFIER,
|
||||||
EQUIPMENT_IDENTIFIER_GAS,
|
EQUIPMENT_IDENTIFIER_GAS,
|
||||||
LUXEMBOURG_EQUIPMENT_IDENTIFIER,
|
LUXEMBOURG_EQUIPMENT_IDENTIFIER,
|
||||||
@ -81,6 +82,15 @@ async def dsmr_connection_send_validate_fixture(hass):
|
|||||||
|
|
||||||
async def connection_factory(*args, **kwargs):
|
async def connection_factory(*args, **kwargs):
|
||||||
"""Return mocked out Asyncio classes."""
|
"""Return mocked out Asyncio classes."""
|
||||||
|
if args[1] == "5B":
|
||||||
|
protocol.telegram = {
|
||||||
|
BELGIUM_EQUIPMENT_IDENTIFIER: CosemObject(
|
||||||
|
BELGIUM_EQUIPMENT_IDENTIFIER, [{"value": "12345678", "unit": ""}]
|
||||||
|
),
|
||||||
|
EQUIPMENT_IDENTIFIER_GAS: CosemObject(
|
||||||
|
EQUIPMENT_IDENTIFIER_GAS, [{"value": "123456789", "unit": ""}]
|
||||||
|
),
|
||||||
|
}
|
||||||
if args[1] == "5L":
|
if args[1] == "5L":
|
||||||
protocol.telegram = {
|
protocol.telegram = {
|
||||||
LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemObject(
|
LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemObject(
|
||||||
|
@ -215,6 +215,50 @@ async def test_setup_serial_rfxtrx(
|
|||||||
assert result["data"] == {**entry_data, **SERIAL_DATA}
|
assert result["data"] == {**entry_data, **SERIAL_DATA}
|
||||||
|
|
||||||
|
|
||||||
|
@patch("serial.tools.list_ports.comports", return_value=[com_port()])
|
||||||
|
async def test_setup_5B(
|
||||||
|
com_mock, hass: HomeAssistant, dsmr_connection_send_validate_fixture
|
||||||
|
) -> None:
|
||||||
|
"""Test we can setup serial."""
|
||||||
|
port = com_port()
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
assert result["errors"] is None
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{"type": "Serial"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["step_id"] == "setup_serial"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with patch("homeassistant.components.dsmr.async_setup_entry", return_value=True):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{"port": port.device, "dsmr_version": "5B"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entry_data = {
|
||||||
|
"port": port.device,
|
||||||
|
"dsmr_version": "5B",
|
||||||
|
"protocol": "dsmr_protocol",
|
||||||
|
"serial_id": "12345678",
|
||||||
|
"serial_id_gas": "123456789",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert result["type"] == "create_entry"
|
||||||
|
assert result["title"] == port.device
|
||||||
|
assert result["data"] == entry_data
|
||||||
|
|
||||||
|
|
||||||
@patch("serial.tools.list_ports.comports", return_value=[com_port()])
|
@patch("serial.tools.list_ports.comports", return_value=[com_port()])
|
||||||
async def test_setup_5L(
|
async def test_setup_5L(
|
||||||
com_mock, hass: HomeAssistant, dsmr_connection_send_validate_fixture
|
com_mock, hass: HomeAssistant, dsmr_connection_send_validate_fixture
|
||||||
|
Loading…
x
Reference in New Issue
Block a user