Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 18 additions & 13 deletions tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@
from homeassistant.components.modbus import number


async def test_number_validator():
@pytest.mark.parametrize(
"value,value_type",
[
(15, int),
(15.1, float),
("15", int),
("15.1", float),
(-15, int),
(-15.1, float),
("-15", int),
("-15.1", float),
],
)
async def test_number_validator(value, value_type):
"""Test number validator."""

# positive tests
value = number(15)
assert isinstance(value, int)
assert isinstance(number(value), value_type)

value = number(15.1)
assert isinstance(value, float)

value = number("15")
assert isinstance(value, int)
async def test_number_exception():
"""Test number exception."""

value = number("15.1")
assert isinstance(value, float)

# exception test
try:
value = number("x15.1")
number("x15.1")
except (vol.Invalid):
return

Expand Down
20 changes: 12 additions & 8 deletions tests/components/modbus/test_modbus_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@


@pytest.mark.parametrize("do_discovery", [False, True])
@pytest.mark.parametrize("do_options", [False, True])
@pytest.mark.parametrize(
"do_options",
[
{},
{
CONF_SLAVE: 10,
CONF_INPUT_TYPE: CALL_TYPE_DISCRETE,
CONF_DEVICE_CLASS: "door",
},
],
)
async def test_config_binary_sensor(hass, do_discovery, do_options):
"""Run test for binary sensor."""
sensor_name = "test_sensor"
Expand All @@ -31,13 +41,7 @@ async def test_config_binary_sensor(hass, do_discovery, do_options):
CONF_ADDRESS: 51,
}
if do_options:
config_sensor.update(
{
CONF_SLAVE: 10,
CONF_INPUT_TYPE: CALL_TYPE_DISCRETE,
CONF_DEVICE_CLASS: "door",
}
)
config_sensor.update()
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await base_config_test(
hass,
config_sensor,
Expand Down
19 changes: 11 additions & 8 deletions tests/components/modbus/test_modbus_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
from .conftest import base_config_test, base_test


@pytest.mark.parametrize("do_options", [False, True])
@pytest.mark.parametrize(
"do_options",
[
{},
{
CONF_SCAN_INTERVAL: 20,
CONF_DATA_COUNT: 2,
},
],
)
async def test_config_climate(hass, do_options):
"""Run test for climate."""
device_name = "test_climate"
Expand All @@ -23,13 +32,7 @@ async def test_config_climate(hass, do_options):
CONF_CURRENT_TEMP: 117,
CONF_SLAVE: 10,
}
if do_options:
device_config.update(
{
CONF_SCAN_INTERVAL: 20,
CONF_DATA_COUNT: 2,
}
)
device_config.update(do_options)
await base_config_test(
hass,
device_config,
Expand Down
19 changes: 11 additions & 8 deletions tests/components/modbus/test_modbus_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
from .conftest import base_config_test, base_test


@pytest.mark.parametrize("do_options", [False, True])
@pytest.mark.parametrize(
"do_options",
[
{},
{
CONF_SLAVE: 10,
CONF_SCAN_INTERVAL: 20,
},
],
)
@pytest.mark.parametrize("read_type", [CALL_TYPE_COIL, CONF_REGISTER])
async def test_config_cover(hass, do_options, read_type):
"""Run test for cover."""
Expand All @@ -24,13 +33,7 @@ async def test_config_cover(hass, do_options, read_type):
CONF_NAME: device_name,
read_type: 1234,
}
if do_options:
device_config.update(
{
CONF_SLAVE: 10,
CONF_SCAN_INTERVAL: 20,
}
)
device_config.update(do_options)
await base_config_test(
hass,
device_config,
Expand Down
97 changes: 74 additions & 23 deletions tests/components/modbus/test_modbus_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,90 @@
from .conftest import base_config_test, base_test


@pytest.mark.parametrize("do_discovery", [False, True])
@pytest.mark.parametrize("do_options", [False, True])
@pytest.mark.parametrize(
"do_type", [CALL_TYPE_REGISTER_HOLDING, CALL_TYPE_REGISTER_INPUT]
)
async def test_config_sensor(hass, do_discovery, do_options, do_type):
"""Run test for sensor."""
sensor_name = "test_sensor"
config_sensor = {
CONF_NAME: sensor_name,
CONF_ADDRESS: 51,
}
if do_options:
config_sensor.update(
"do_discovery, do_config",
[
(
False,
{
CONF_REGISTER: 51,
},
),
(
False,
{
CONF_REGISTER: 51,
CONF_SLAVE: 10,
CONF_COUNT: 1,
CONF_DATA_TYPE: "int",
CONF_PRECISION: 0,
CONF_SCALE: 1,
CONF_REVERSE_ORDER: False,
CONF_OFFSET: 0,
CONF_REGISTER_TYPE: CALL_TYPE_REGISTER_HOLDING,
CONF_DEVICE_CLASS: "battery",
},
),
(
False,
{
CONF_REGISTER: 51,
CONF_SLAVE: 10,
CONF_COUNT: 1,
CONF_DATA_TYPE: "int",
CONF_PRECISION: 0,
CONF_SCALE: 1,
CONF_REVERSE_ORDER: False,
CONF_OFFSET: 0,
CONF_INPUT_TYPE: do_type,
CONF_REGISTER_TYPE: CALL_TYPE_REGISTER_INPUT,
CONF_DEVICE_CLASS: "battery",
}
)
if not do_discovery:
# bridge difference in configuration
config_sensor[CONF_REGISTER] = config_sensor[CONF_ADDRESS]
del config_sensor[CONF_ADDRESS]
if do_options:
config_sensor[CONF_REGISTER_TYPE] = config_sensor[CONF_INPUT_TYPE]
del config_sensor[CONF_INPUT_TYPE]
},
),
(
True,
{
CONF_ADDRESS: 51,
},
),
(
True,
{
CONF_ADDRESS: 51,
CONF_SLAVE: 10,
CONF_COUNT: 1,
CONF_DATA_TYPE: "int",
CONF_PRECISION: 0,
CONF_SCALE: 1,
CONF_REVERSE_ORDER: False,
CONF_OFFSET: 0,
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
CONF_DEVICE_CLASS: "battery",
},
),
(
True,
{
CONF_ADDRESS: 51,
CONF_SLAVE: 10,
CONF_COUNT: 1,
CONF_DATA_TYPE: "int",
CONF_PRECISION: 0,
CONF_SCALE: 1,
CONF_REVERSE_ORDER: False,
CONF_OFFSET: 0,
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_INPUT,
CONF_DEVICE_CLASS: "battery",
},
),
],
)
async def test_config_sensor(hass, do_discovery, do_config):
"""Run test for sensor."""
sensor_name = "test_sensor"
config_sensor = {
CONF_NAME: sensor_name,
}
config_sensor.update(do_config)
await base_config_test(
hass,
config_sensor,
Expand Down
Loading