Add tests for Modbus slave binary sensors, up coverage to 100% (#67373)

This commit is contained in:
jan iversen 2022-02-28 20:06:32 +01:00 committed by GitHub
parent 2ca97f6309
commit 690223fb69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 16 deletions

View File

@ -706,7 +706,6 @@ omit =
homeassistant/components/mjpeg/util.py
homeassistant/components/mochad/*
homeassistant/components/modbus/climate.py
homeassistant/components/modbus/binary_sensor.py
homeassistant/components/modem_callerid/button.py
homeassistant/components/modem_callerid/sensor.py
homeassistant/components/moehlenhoff_alpha2/__init__.py

View File

@ -257,16 +257,68 @@ async def test_config_slave_binary_sensor(hass, mock_modbus):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 51,
CONF_SLAVE_COUNT: 8,
}
]
},
],
)
@pytest.mark.parametrize(
"register_words,expected, slaves",
"config_addon,register_words,expected, slaves",
[
(
{CONF_SLAVE_COUNT: 1},
[0x01],
STATE_ON,
[
STATE_OFF,
],
),
(
{CONF_SLAVE_COUNT: 1},
[0x02],
STATE_OFF,
[
STATE_ON,
],
),
(
{CONF_SLAVE_COUNT: 1},
[0x04],
STATE_OFF,
[
STATE_OFF,
],
),
(
{CONF_SLAVE_COUNT: 7},
[0x01],
STATE_ON,
[
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
],
),
(
{CONF_SLAVE_COUNT: 7},
[0x82],
STATE_OFF,
[
STATE_ON,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_ON,
],
),
(
{CONF_SLAVE_COUNT: 10},
[0x01, 0x00],
STATE_ON,
[
@ -278,23 +330,12 @@ async def test_config_slave_binary_sensor(hass, mock_modbus):
STATE_OFF,
STATE_OFF,
STATE_OFF,
],
),
(
[0x02, 0x00],
STATE_OFF,
[
STATE_ON,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
],
),
(
{CONF_SLAVE_COUNT: 10},
[0x01, 0x01],
STATE_ON,
[
@ -306,6 +347,25 @@ async def test_config_slave_binary_sensor(hass, mock_modbus):
STATE_OFF,
STATE_OFF,
STATE_ON,
STATE_OFF,
STATE_OFF,
],
),
(
{CONF_SLAVE_COUNT: 10},
[0x81, 0x01],
STATE_ON,
[
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_OFF,
STATE_ON,
STATE_ON,
STATE_OFF,
STATE_OFF,
],
),
],
@ -314,6 +374,6 @@ async def test_slave_binary_sensor(hass, expected, slaves, mock_do_cycle):
"""Run test for given config."""
assert hass.states.get(ENTITY_ID).state == expected
for i in range(8):
for i in range(len(slaves)):
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_")
assert hass.states.get(entity_id).state == slaves[i]