Rename domain import in modbus (#33906)

pull/33924/head
jan iversen 2020-04-09 22:15:20 +02:00 committed by GitHub
parent 4c38e6cfa5
commit 9535dd87b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -35,7 +35,7 @@ from .const import (
CONF_PARITY,
CONF_STOPBITS,
DEFAULT_HUB,
MODBUS_DOMAIN,
MODBUS_DOMAIN as DOMAIN,
SERVICE_WRITE_COIL,
SERVICE_WRITE_REGISTER,
)
@ -68,7 +68,7 @@ ETHERNET_SCHEMA = BASE_SCHEMA.extend(
)
CONFIG_SCHEMA = vol.Schema(
{MODBUS_DOMAIN: vol.All(cv.ensure_list, [vol.Any(SERIAL_SCHEMA, ETHERNET_SCHEMA)])},
{DOMAIN: vol.All(cv.ensure_list, [vol.Any(SERIAL_SCHEMA, ETHERNET_SCHEMA)])},
extra=vol.ALLOW_EXTRA,
)
@ -95,9 +95,9 @@ SERVICE_WRITE_COIL_SCHEMA = vol.Schema(
async def async_setup(hass, config):
"""Set up Modbus component."""
hass.data[MODBUS_DOMAIN] = hub_collect = {}
hass.data[DOMAIN] = hub_collect = {}
for client_config in config[MODBUS_DOMAIN]:
for client_config in config[DOMAIN]:
hub_collect[client_config[CONF_NAME]] = ModbusHub(client_config, hass.loop)
def stop_modbus(event):
@ -140,13 +140,13 @@ async def async_setup(hass, config):
# Register services for modbus
hass.services.async_register(
MODBUS_DOMAIN,
DOMAIN,
SERVICE_WRITE_REGISTER,
write_register,
schema=SERVICE_WRITE_REGISTER_SCHEMA,
)
hass.services.async_register(
MODBUS_DOMAIN, SERVICE_WRITE_COIL, write_coil, schema=SERVICE_WRITE_COIL_SCHEMA,
DOMAIN, SERVICE_WRITE_COIL, write_coil, schema=SERVICE_WRITE_COIL_SCHEMA,
)
return True
@ -204,7 +204,6 @@ class ModbusHub:
stopbits=self._config_stopbits,
bytesize=self._config_bytesize,
parity=self._config_parity,
timeout=self._config_timeout,
loop=self._loop,
)
elif self._config_type == "rtuovertcp":

View File

@ -11,7 +11,7 @@ from homeassistant.components.modbus.const import (
CONF_REGISTER_TYPE,
CONF_REGISTERS,
DEFAULT_HUB,
MODBUS_DOMAIN,
MODBUS_DOMAIN as DOMAIN,
)
from homeassistant.const import CONF_NAME, CONF_PLATFORM, CONF_SCAN_INTERVAL
from homeassistant.setup import async_setup_component
@ -25,10 +25,10 @@ _LOGGER = logging.getLogger(__name__)
@pytest.fixture()
def mock_hub(hass):
"""Mock hub."""
mock_integration(hass, MockModule(MODBUS_DOMAIN))
mock_integration(hass, MockModule(DOMAIN))
hub = mock.MagicMock()
hub.name = "hub"
hass.data[MODBUS_DOMAIN] = {DEFAULT_HUB: hub}
hass.data[DOMAIN] = {DEFAULT_HUB: hub}
return hub