* Change modbus configuration to new style. The old (frozen) configuration is still supported, but when detected a big warning is issued that it will soon be removed. This allows users to change their configuration at their pace. Clean configuration SCHEMAs and move common modbus parts to MODBUS_SCHEMA (renamed from BASE_SCHEMA). Add BASE_COMPONENT_SCHEMA to ensure common configuration of components. All component define e.g. NAME, move these to a common schema. change components (binary_sensor, sensor, switch) to new config Add test set for modbus itself (old config and discovery_info). Add test of devices discovery_info configuration * Update discovery_info configuration for binary_sensor. * Update discovery_info configuration for sensor. * Update discovery_info configuration for switch. * Review comments. * update due to change in core * flake8 problem. * Correct log message. * add should_poll property. * Fix polling for Modbus binary sensor * Fix polling for Modbus sensor * Fix polling for Modbus switch * Fix switch. * Fix pytest errors. * Update homeassistant/components/modbus/binary_sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/binary_sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/modbus.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/switch.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/switch.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/modbus/switch.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * ToogleEntity -> SwitchEntity and add abastract * Update homeassistant/components/modbus/switch.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/modbus/test_init.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * removed if/else in test. * Remove other if. Co-authored-by: Vladimir Zahradnik <vladimir@zahradnik.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
70 lines
1.4 KiB
Python
70 lines
1.4 KiB
Python
"""The tests for the Modbus sensor component."""
|
|
import pytest
|
|
|
|
from homeassistant.components.modbus.const import (
|
|
CONF_BAUDRATE,
|
|
CONF_BYTESIZE,
|
|
CONF_PARITY,
|
|
CONF_STOPBITS,
|
|
MODBUS_DOMAIN as DOMAIN,
|
|
)
|
|
from homeassistant.const import (
|
|
CONF_DELAY,
|
|
CONF_HOST,
|
|
CONF_METHOD,
|
|
CONF_NAME,
|
|
CONF_PORT,
|
|
CONF_TIMEOUT,
|
|
CONF_TYPE,
|
|
)
|
|
|
|
from .conftest import base_config_test
|
|
|
|
|
|
@pytest.mark.parametrize("do_discovery", [False, True])
|
|
@pytest.mark.parametrize(
|
|
"do_options",
|
|
[
|
|
{},
|
|
{
|
|
CONF_NAME: "modbusTest",
|
|
CONF_TIMEOUT: 30,
|
|
CONF_DELAY: 10,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.parametrize(
|
|
"do_config",
|
|
[
|
|
{
|
|
CONF_TYPE: "tcp",
|
|
CONF_HOST: "modbusTestHost",
|
|
CONF_PORT: 5501,
|
|
},
|
|
{
|
|
CONF_TYPE: "serial",
|
|
CONF_BAUDRATE: 9600,
|
|
CONF_BYTESIZE: 8,
|
|
CONF_METHOD: "rtu",
|
|
CONF_PORT: "usb01",
|
|
CONF_PARITY: "E",
|
|
CONF_STOPBITS: 1,
|
|
},
|
|
],
|
|
)
|
|
async def test_config_modbus(hass, do_discovery, do_options, do_config):
|
|
"""Run test for modbus."""
|
|
config = {
|
|
DOMAIN: do_config,
|
|
}
|
|
config.update(do_options)
|
|
await base_config_test(
|
|
hass,
|
|
None,
|
|
"",
|
|
DOMAIN,
|
|
None,
|
|
None,
|
|
method_discovery=do_discovery,
|
|
config_modbus=config,
|
|
)
|