Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
CONF_WRITE_TYPE = "write_type"
CONF_ZERO_SUPPRESS = "zero_suppress"

DEVICE_ID = "device_id"
RTUOVERTCP = "rtuovertcp"
SERIAL = "serial"
TCP = "tcp"
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/modbus/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
CONF_PARITY,
CONF_STOPBITS,
DEFAULT_HUB,
DEVICE_ID,
MODBUS_DOMAIN as DOMAIN,
PLATFORMS,
RTUOVERTCP,
Expand Down Expand Up @@ -381,7 +382,7 @@ async def low_level_pb_call(
) -> ModbusPDU | None:
"""Call sync. pymodbus."""
kwargs: dict[str, Any] = (
{ATTR_SLAVE: slave} if slave is not None else {ATTR_SLAVE: 1}
{DEVICE_ID: slave} if slave is not None else {DEVICE_ID: 1}
)
entry = self._pb_request[use_call]

Expand Down
8 changes: 4 additions & 4 deletions tests/components/modbus/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ async def test_hvac_onoff_values(hass: HomeAssistant, mock_modbus) -> None:
)
await hass.async_block_till_done()

mock_modbus.write_register.assert_called_with(11, value=0xAA, slave=10)
mock_modbus.write_register.assert_called_with(11, value=0xAA, device_id=10)

await hass.services.async_call(
CLIMATE_DOMAIN,
Expand All @@ -477,7 +477,7 @@ async def test_hvac_onoff_values(hass: HomeAssistant, mock_modbus) -> None:
)
await hass.async_block_till_done()

mock_modbus.write_register.assert_called_with(11, value=0xFF, slave=10)
mock_modbus.write_register.assert_called_with(11, value=0xFF, device_id=10)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -506,7 +506,7 @@ async def test_hvac_onoff_coil(hass: HomeAssistant, mock_modbus) -> None:
)
await hass.async_block_till_done()

mock_modbus.write_coil.assert_called_with(11, value=1, slave=10)
mock_modbus.write_coil.assert_called_with(11, value=1, device_id=10)

await hass.services.async_call(
CLIMATE_DOMAIN,
Expand All @@ -516,7 +516,7 @@ async def test_hvac_onoff_coil(hass: HomeAssistant, mock_modbus) -> None:
)
await hass.async_block_till_done()

mock_modbus.write_coil.assert_called_with(11, value=0, slave=10)
mock_modbus.write_coil.assert_called_with(11, value=0, device_id=10)


@pytest.mark.parametrize(
Expand Down
7 changes: 4 additions & 3 deletions tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
CONF_SWING_MODE_VALUES,
CONF_VIRTUAL_COUNT,
DEFAULT_SCAN_INTERVAL,
DEVICE_ID,
MODBUS_DOMAIN as DOMAIN,
RTUOVERTCP,
SERIAL,
Expand Down Expand Up @@ -867,7 +868,7 @@ async def test_pb_service_write(
assert func_name[do_write[FUNC]].called
assert func_name[do_write[FUNC]].call_args.args == (data[ATTR_ADDRESS],)
assert func_name[do_write[FUNC]].call_args.kwargs == {
"slave": 17,
DEVICE_ID: 17,
value_arg_name[do_write[FUNC]]: data[do_write[DATA]],
}

Expand Down Expand Up @@ -1326,7 +1327,7 @@ async def test_check_default_slave(
"""Test default slave."""
assert mock_modbus.read_holding_registers.mock_calls
first_call = mock_modbus.read_holding_registers.mock_calls[0]
assert first_call.kwargs["slave"] == expected_slave_value
assert first_call.kwargs[DEVICE_ID] == expected_slave_value


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1407,7 +1408,7 @@ async def test_pb_service_write_no_slave(
assert func_name[do_write[FUNC]].called
assert func_name[do_write[FUNC]].call_args.args == (data[ATTR_ADDRESS],)
assert func_name[do_write[FUNC]].call_args.kwargs == {
"slave": 1,
DEVICE_ID: 1,
value_arg_name[do_write[FUNC]]: data[do_write[DATA]],
}

Expand Down