From 77de1b23319336ce245115b1abc0a59f2f544bcf Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 14 May 2024 15:18:45 +0200 Subject: [PATCH] Move abode service registration (#117418) --- homeassistant/components/abode/__init__.py | 18 ++++++++++-------- tests/components/abode/test_init.py | 15 +++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/abode/__init__.py b/homeassistant/components/abode/__init__.py index 76d4e5a5351..a27eda2cf12 100644 --- a/homeassistant/components/abode/__init__.py +++ b/homeassistant/components/abode/__init__.py @@ -29,6 +29,7 @@ from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, ServiceCall from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import config_validation as cv from homeassistant.helpers.dispatcher import dispatcher_send +from homeassistant.helpers.typing import ConfigType from .const import CONF_POLLING, DOMAIN, LOGGER @@ -80,6 +81,12 @@ class AbodeSystem: logout_listener: CALLBACK_TYPE | None = None +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up the Abode component.""" + setup_hass_services(hass) + return True + + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Abode integration from a config entry.""" username = entry.data[CONF_USERNAME] @@ -108,7 +115,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await setup_hass_events(hass) - await hass.async_add_executor_job(setup_hass_services, hass) await hass.async_add_executor_job(setup_abode_events, hass) return True @@ -116,10 +122,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - hass.services.async_remove(DOMAIN, SERVICE_SETTINGS) - hass.services.async_remove(DOMAIN, SERVICE_CAPTURE_IMAGE) - hass.services.async_remove(DOMAIN, SERVICE_TRIGGER_AUTOMATION) - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) await hass.async_add_executor_job(hass.data[DOMAIN].abode.events.stop) @@ -172,15 +174,15 @@ def setup_hass_services(hass: HomeAssistant) -> None: signal = f"abode_trigger_automation_{entity_id}" dispatcher_send(hass, signal) - hass.services.register( + hass.services.async_register( DOMAIN, SERVICE_SETTINGS, change_setting, schema=CHANGE_SETTING_SCHEMA ) - hass.services.register( + hass.services.async_register( DOMAIN, SERVICE_CAPTURE_IMAGE, capture_image, schema=CAPTURE_IMAGE_SCHEMA ) - hass.services.register( + hass.services.async_register( DOMAIN, SERVICE_TRIGGER_AUTOMATION, trigger_automation, schema=AUTOMATION_SCHEMA ) diff --git a/tests/components/abode/test_init.py b/tests/components/abode/test_init.py index 58e9ccb2c41..9fca6dcbdd3 100644 --- a/tests/components/abode/test_init.py +++ b/tests/components/abode/test_init.py @@ -8,12 +8,7 @@ from jaraco.abode.exceptions import ( Exception as AbodeException, ) -from homeassistant.components.abode import ( - DOMAIN as ABODE_DOMAIN, - SERVICE_CAPTURE_IMAGE, - SERVICE_SETTINGS, - SERVICE_TRIGGER_AUTOMATION, -) +from homeassistant.components.abode import DOMAIN as ABODE_DOMAIN, SERVICE_SETTINGS from homeassistant.components.alarm_control_panel import DOMAIN as ALARM_DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_USERNAME @@ -62,12 +57,8 @@ async def test_unload_entry(hass: HomeAssistant) -> None: patch("jaraco.abode.event_controller.EventController.stop") as mock_events_stop, ): assert await hass.config_entries.async_unload(mock_entry.entry_id) - mock_logout.assert_called_once() - mock_events_stop.assert_called_once() - - assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_SETTINGS) - assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_CAPTURE_IMAGE) - assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_TRIGGER_AUTOMATION) + mock_logout.assert_called_once() + mock_events_stop.assert_called_once() async def test_invalid_credentials(hass: HomeAssistant) -> None: