diff --git a/homeassistant/components/google_photos/__init__.py b/homeassistant/components/google_photos/__init__.py index 40de02554ae..897598fa5cb 100644 --- a/homeassistant/components/google_photos/__init__.py +++ b/homeassistant/components/google_photos/__init__.py @@ -7,17 +7,26 @@ from google_photos_library_api.api import GooglePhotosLibraryApi from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady -from homeassistant.helpers import config_entry_oauth2_flow +from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.typing import ConfigType from . import api from .const import DOMAIN from .coordinator import GooglePhotosConfigEntry, GooglePhotosUpdateCoordinator from .services import async_register_services -__all__ = [ - "DOMAIN", -] +__all__ = ["DOMAIN"] + +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up Google Photos integration.""" + + async_register_services(hass) + + return True async def async_setup_entry( @@ -48,8 +57,6 @@ async def async_setup_entry( await coordinator.async_config_entry_first_refresh() entry.runtime_data = coordinator - async_register_services(hass) - return True diff --git a/homeassistant/components/google_photos/services.py b/homeassistant/components/google_photos/services.py index 8042df8f811..8b065ad34ac 100644 --- a/homeassistant/components/google_photos/services.py +++ b/homeassistant/components/google_photos/services.py @@ -152,11 +152,10 @@ def async_register_services(hass: HomeAssistant) -> None: } return None - if not hass.services.has_service(DOMAIN, UPLOAD_SERVICE): - hass.services.async_register( - DOMAIN, - UPLOAD_SERVICE, - async_handle_upload, - schema=UPLOAD_SERVICE_SCHEMA, - supports_response=SupportsResponse.OPTIONAL, - ) + hass.services.async_register( + DOMAIN, + UPLOAD_SERVICE, + async_handle_upload, + schema=UPLOAD_SERVICE_SCHEMA, + supports_response=SupportsResponse.OPTIONAL, + ) diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 991d7b51500..cf2c1101b17 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -5,13 +5,24 @@ from aiohue.util import normalize_bridge_id from homeassistant.components import persistent_notification from homeassistant.config_entries import SOURCE_IGNORE from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import config_validation as cv, device_registry as dr +from homeassistant.helpers.typing import ConfigType from .bridge import HueBridge, HueConfigEntry -from .const import DOMAIN, SERVICE_HUE_ACTIVATE_SCENE +from .const import DOMAIN from .migration import check_migration from .services import async_register_services +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up Hue integration.""" + + async_register_services(hass) + + return True + async def async_setup_entry(hass: HomeAssistant, entry: HueConfigEntry) -> bool: """Set up a bridge from a config entry.""" @@ -23,9 +34,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: HueConfigEntry) -> bool: if not await bridge.async_initialize_bridge(): return False - # register Hue domain services - async_register_services(hass) - api = bridge.api # For backwards compat @@ -106,7 +114,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: HueConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: HueConfigEntry) -> bool: """Unload a config entry.""" - unload_success = await entry.runtime_data.async_reset() - if not hass.config_entries.async_loaded_entries(DOMAIN): - hass.services.async_remove(DOMAIN, SERVICE_HUE_ACTIVATE_SCENE) - return unload_success + return await entry.runtime_data.async_reset() diff --git a/homeassistant/components/hue/services.py b/homeassistant/components/hue/services.py index 18dd19e3391..6639795d277 100644 --- a/homeassistant/components/hue/services.py +++ b/homeassistant/components/hue/services.py @@ -59,21 +59,20 @@ def async_register_services(hass: HomeAssistant) -> None: group_name, ) - if not hass.services.has_service(DOMAIN, SERVICE_HUE_ACTIVATE_SCENE): - # Register a local handler for scene activation - hass.services.async_register( - DOMAIN, - SERVICE_HUE_ACTIVATE_SCENE, - verify_domain_control(hass, DOMAIN)(hue_activate_scene), - schema=vol.Schema( - { - vol.Required(ATTR_GROUP_NAME): cv.string, - vol.Required(ATTR_SCENE_NAME): cv.string, - vol.Optional(ATTR_TRANSITION): cv.positive_int, - vol.Optional(ATTR_DYNAMIC): cv.boolean, - } - ), - ) + # Register a local handler for scene activation + hass.services.async_register( + DOMAIN, + SERVICE_HUE_ACTIVATE_SCENE, + verify_domain_control(hass, DOMAIN)(hue_activate_scene), + schema=vol.Schema( + { + vol.Required(ATTR_GROUP_NAME): cv.string, + vol.Required(ATTR_SCENE_NAME): cv.string, + vol.Optional(ATTR_TRANSITION): cv.positive_int, + vol.Optional(ATTR_DYNAMIC): cv.boolean, + } + ), + ) async def hue_activate_scene_v1( diff --git a/homeassistant/components/onedrive/services.py b/homeassistant/components/onedrive/services.py index 1f1afe1507c..0b1afe925d2 100644 --- a/homeassistant/components/onedrive/services.py +++ b/homeassistant/components/onedrive/services.py @@ -121,11 +121,10 @@ def async_register_services(hass: HomeAssistant) -> None: return {"files": [asdict(item_result) for item_result in upload_results]} return None - if not hass.services.has_service(DOMAIN, UPLOAD_SERVICE): - hass.services.async_register( - DOMAIN, - UPLOAD_SERVICE, - async_handle_upload, - schema=UPLOAD_SERVICE_SCHEMA, - supports_response=SupportsResponse.OPTIONAL, - ) + hass.services.async_register( + DOMAIN, + UPLOAD_SERVICE, + async_handle_upload, + schema=UPLOAD_SERVICE_SCHEMA, + supports_response=SupportsResponse.OPTIONAL, + ) diff --git a/homeassistant/components/picnic/__init__.py b/homeassistant/components/picnic/__init__.py index 8de407133cd..2d1c05c8b1a 100644 --- a/homeassistant/components/picnic/__init__.py +++ b/homeassistant/components/picnic/__init__.py @@ -5,14 +5,25 @@ from python_picnic_api2 import PicnicAPI from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN, CONF_COUNTRY_CODE, Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType from .const import CONF_API, CONF_COORDINATOR, DOMAIN from .coordinator import PicnicUpdateCoordinator from .services import async_register_services +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) PLATFORMS = [Platform.SENSOR, Platform.TODO] +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up Picnic integration.""" + + await async_register_services(hass) + + return True + + def create_picnic_client(entry: ConfigEntry): """Create an instance of the PicnicAPI client.""" return PicnicAPI( @@ -37,9 +48,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - # Register the services - await async_register_services(hass) - return True diff --git a/homeassistant/components/picnic/services.py b/homeassistant/components/picnic/services.py index 76d7b8a6c44..9496a9441e5 100644 --- a/homeassistant/components/picnic/services.py +++ b/homeassistant/components/picnic/services.py @@ -29,9 +29,6 @@ class PicnicServiceException(Exception): async def async_register_services(hass: HomeAssistant) -> None: """Register services for the Picnic integration, if not registered yet.""" - if hass.services.has_service(DOMAIN, SERVICE_ADD_PRODUCT_TO_CART): - return - async def async_add_product_service(call: ServiceCall): api_client = await get_api_client(hass, call.data[ATTR_CONFIG_ENTRY_ID]) await handle_add_product(hass, api_client, call)