diff --git a/homeassistant/components/ebusd/__init__.py b/homeassistant/components/ebusd/__init__.py index f131d73d67a1..e38ad5e57802 100644 --- a/homeassistant/components/ebusd/__init__.py +++ b/homeassistant/components/ebusd/__init__.py @@ -19,6 +19,7 @@ from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, EBUSD_DATA, SENSOR_TYPES +from .services import setup_services _LOGGER = logging.getLogger(__name__) @@ -26,7 +27,6 @@ DEFAULT_NAME = "ebusd" DEFAULT_PORT = 8888 CONF_CIRCUIT = "circuit" CACHE_TTL = 900 -SERVICE_EBUSD_WRITE = "ebusd_write" def verify_ebusd_config(config: ConfigType) -> ConfigType: @@ -62,6 +62,7 @@ CONFIG_SCHEMA = probatio.Schema( def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the eBusd component.""" _LOGGER.debug("Integration setup started") + setup_services(hass) conf: ConfigType = config[DOMAIN] name: str = conf[CONF_NAME] circuit: str = conf[CONF_CIRCUIT] @@ -80,8 +81,6 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: } load_platform(hass, Platform.SENSOR, DOMAIN, sensor_config, config) - hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE, hass.data[EBUSD_DATA].write) - _LOGGER.debug("Ebusd integration setup completed") return True diff --git a/homeassistant/components/ebusd/services.py b/homeassistant/components/ebusd/services.py new file mode 100644 index 000000000000..ae1327b3387f --- /dev/null +++ b/homeassistant/components/ebusd/services.py @@ -0,0 +1,17 @@ +"""Services for the Ebusd integration.""" + +from homeassistant.core import HomeAssistant, ServiceCall + +from .const import DOMAIN, EBUSD_DATA + +SERVICE_EBUSD_WRITE = "ebusd_write" + + +def _ebusd_write(call: ServiceCall) -> None: + """Call write method on ebusd.""" + call.hass.data[EBUSD_DATA].write(call) + + +def setup_services(hass: HomeAssistant) -> None: + """Register the Ebusd services.""" + hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE, _ebusd_write)