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
4 changes: 0 additions & 4 deletions homeassistant/components/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ async def async_setup(hass, config):
"""Set up Modbus component."""
hass.data[MODBUS_DOMAIN] = hub_collect = {}

_LOGGER.debug("registering hubs")
for client_config in config[MODBUS_DOMAIN]:
hub_collect[client_config[CONF_NAME]] = ModbusHub(client_config, hass.loop)

Expand All @@ -109,7 +108,6 @@ def stop_modbus(event):
def start_modbus(event):
"""Start Modbus service."""
for client in hub_collect.values():
_LOGGER.debug("setup hub %s", client.name)
client.setup()

hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_modbus)
Expand Down Expand Up @@ -161,7 +159,6 @@ class ModbusHub:

def __init__(self, client_config, main_loop):
"""Initialize the Modbus hub."""
_LOGGER.debug("Preparing setup: %s", client_config)

# generic configuration
self._loop = main_loop
Expand Down Expand Up @@ -200,7 +197,6 @@ def setup(self):
# Client* do deliver loop, client as result but
# pylint does not accept that fact

_LOGGER.debug("doing setup")
if self._config_type == "serial":
_, self._client = ClientSerial(
schedulers.ASYNC_IO,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus binary sensors."""
sensors = []
for entry in config[CONF_INPUTS]:
Expand All @@ -70,7 +70,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
)
)

add_entities(sensors)
async_add_entities(sensors)


class ModbusBinarySensor(BinarySensorDevice):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus Thermostat Platform."""
name = config[CONF_NAME]
modbus_slave = config[CONF_SLAVE]
Expand All @@ -91,7 +91,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
hub_name = config[CONF_HUB]
hub = hass.data[MODBUS_DOMAIN][hub_name]

add_entities(
async_add_entities(
[
ModbusThermostat(
hub,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def number(value: Any) -> Union[int, float]:
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus sensors."""
sensors = []
data_types = {DATA_TYPE_INT: {1: "h", 2: "i", 4: "q"}}
Expand Down Expand Up @@ -148,7 +148,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):

if not sensors:
return False
add_entities(sensors)
async_add_entities(sensors)


class ModbusRegisterSensor(RestoreEntity):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Read configuration and create Modbus devices."""
switches = []
if CONF_COILS in config:
Expand Down Expand Up @@ -109,7 +109,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
)
)

add_entities(switches)
async_add_entities(switches)


class ModbusCoilSwitch(ToggleEntity, RestoreEntity):
Expand Down
22 changes: 8 additions & 14 deletions tests/components/modbus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def mock_hub(hass):
return hub


common_register_config = {CONF_NAME: "test-config", CONF_REGISTER: 1234}


class ReadResult:
"""Storage class for register read results."""

Expand All @@ -46,18 +43,16 @@ def __init__(self, register_words):
read_result = None


async def simulate_read_registers(unit, address, count):
"""Simulate modbus register read."""
del unit, address, count # not used in simulation, but in real connection
global read_result
return read_result


async def run_test(
hass, mock_hub, register_config, entity_domain, register_words, expected
hass, use_mock_hub, register_config, entity_domain, register_words, expected
):
"""Run test for given config and check that sensor outputs expected result."""

async def simulate_read_registers(unit, address, count):
"""Simulate modbus register read."""
del unit, address, count # not used in simulation, but in real connection
return read_result

# Full sensor configuration
sensor_name = "modbus_test_sensor"
scan_interval = 5
Expand All @@ -72,12 +67,11 @@ async def run_test(
}

# Setup inputs for the sensor
global read_result
read_result = ReadResult(register_words)
if register_config.get(CONF_REGISTER_TYPE) == CALL_TYPE_REGISTER_INPUT:
mock_hub.read_input_registers = simulate_read_registers
use_mock_hub.read_input_registers = simulate_read_registers
else:
mock_hub.read_holding_registers = simulate_read_registers
use_mock_hub.read_holding_registers = simulate_read_registers

# Initialize sensor
now = dt_util.utcnow()
Expand Down