mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix bool registers in modbus integration (#41506)
When a register is of type bool modbus returns a whole byte, but ONLY the lowest bit determine true/false.
This commit is contained in:
@@ -13,34 +13,6 @@ from .conftest import run_base_read_test, setup_base_test
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_sensor_test(hass, use_mock_hub, value, expected):
|
||||
"""Run test for given config."""
|
||||
switch_name = "modbus_test_switch"
|
||||
scan_interval = 5
|
||||
entity_id, now, device = await setup_base_test(
|
||||
switch_name,
|
||||
hass,
|
||||
use_mock_hub,
|
||||
{
|
||||
CONF_COILS: [
|
||||
{CONF_NAME: switch_name, CALL_TYPE_COIL: 1234, CONF_SLAVE: 1},
|
||||
]
|
||||
},
|
||||
SWITCH_DOMAIN,
|
||||
scan_interval,
|
||||
)
|
||||
|
||||
await run_base_read_test(
|
||||
entity_id,
|
||||
hass,
|
||||
use_mock_hub,
|
||||
CALL_TYPE_COIL,
|
||||
value,
|
||||
expected,
|
||||
now + timedelta(seconds=scan_interval + 1),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"regs,expected",
|
||||
[
|
||||
@@ -48,6 +20,14 @@ async def run_sensor_test(hass, use_mock_hub, value, expected):
|
||||
[0x00],
|
||||
STATE_OFF,
|
||||
),
|
||||
(
|
||||
[0x80],
|
||||
STATE_OFF,
|
||||
),
|
||||
(
|
||||
[0xFE],
|
||||
STATE_OFF,
|
||||
),
|
||||
(
|
||||
[0xFF],
|
||||
STATE_ON,
|
||||
@@ -59,10 +39,28 @@ async def run_sensor_test(hass, use_mock_hub, value, expected):
|
||||
],
|
||||
)
|
||||
async def test_coil_switch(hass, mock_hub, regs, expected):
|
||||
"""Test reading of switch coil."""
|
||||
await run_sensor_test(
|
||||
"""Run test for given config."""
|
||||
switch_name = "modbus_test_switch"
|
||||
scan_interval = 5
|
||||
entity_id, now, device = await setup_base_test(
|
||||
switch_name,
|
||||
hass,
|
||||
mock_hub,
|
||||
{
|
||||
CONF_COILS: [
|
||||
{CONF_NAME: switch_name, CALL_TYPE_COIL: 1234, CONF_SLAVE: 1},
|
||||
]
|
||||
},
|
||||
SWITCH_DOMAIN,
|
||||
scan_interval,
|
||||
)
|
||||
|
||||
await run_base_read_test(
|
||||
entity_id,
|
||||
hass,
|
||||
mock_hub,
|
||||
CALL_TYPE_COIL,
|
||||
regs,
|
||||
expected,
|
||||
now + timedelta(seconds=scan_interval + 1),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user