diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 869d9f7ac67..4bbcf185f28 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -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) @@ -109,7 +108,6 @@ async def async_setup(hass, config): 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) @@ -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 @@ -200,7 +197,6 @@ class ModbusHub: # 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, diff --git a/homeassistant/components/modbus/binary_sensor.py b/homeassistant/components/modbus/binary_sensor.py index 51dfb7c5795..9989b9d530a 100644 --- a/homeassistant/components/modbus/binary_sensor.py +++ b/homeassistant/components/modbus/binary_sensor.py @@ -54,7 +54,7 @@ PLATFORM_SCHEMA = vol.All( ) -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]: @@ -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): diff --git a/homeassistant/components/modbus/climate.py b/homeassistant/components/modbus/climate.py index 182dfeef2de..e5fbcf4d421 100644 --- a/homeassistant/components/modbus/climate.py +++ b/homeassistant/components/modbus/climate.py @@ -72,7 +72,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -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] @@ -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, diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index 59abe2fd6d5..be3bc4c52c6 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -89,7 +89,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -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"}} @@ -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): diff --git a/homeassistant/components/modbus/switch.py b/homeassistant/components/modbus/switch.py index d7d6f121874..e4ec6a004fb 100644 --- a/homeassistant/components/modbus/switch.py +++ b/homeassistant/components/modbus/switch.py @@ -76,7 +76,7 @@ PLATFORM_SCHEMA = vol.All( ) -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: @@ -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): diff --git a/tests/components/modbus/conftest.py b/tests/components/modbus/conftest.py index 043236c503c..d2fff820cdb 100644 --- a/tests/components/modbus/conftest.py +++ b/tests/components/modbus/conftest.py @@ -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.""" @@ -46,18 +43,16 @@ class ReadResult: 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 @@ -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()