From 4e8e53f35791b3b68686a5e84b03465b71bca905 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 27 Oct 2022 02:22:44 -0600 Subject: [PATCH] Remove previously-deprecated OpenUV services (#81055) --- homeassistant/components/openuv/__init__.py | 173 +----------------- homeassistant/components/openuv/services.yaml | 36 ---- tests/components/openuv/conftest.py | 2 - 3 files changed, 4 insertions(+), 207 deletions(-) delete mode 100644 homeassistant/components/openuv/services.yaml diff --git a/homeassistant/components/openuv/__init__.py b/homeassistant/components/openuv/__init__.py index fb649bce759..c4a9d347a40 100644 --- a/homeassistant/components/openuv/__init__.py +++ b/homeassistant/components/openuv/__init__.py @@ -5,9 +5,8 @@ import asyncio from typing import Any from pyopenuv import Client -import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_API_KEY, CONF_BINARY_SENSORS, @@ -17,17 +16,10 @@ from homeassistant.const import ( CONF_SENSORS, Platform, ) -from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import ( - aiohttp_client, - config_validation as cv, - entity_registry, -) +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import aiohttp_client from homeassistant.helpers.entity import EntityDescription -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from homeassistant.helpers.service import verify_domain_control -from homeassistant.helpers.update_coordinator import CoordinatorEntity, UpdateFailed +from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( CONF_FROM_WINDOW, @@ -41,82 +33,11 @@ from .const import ( ) from .coordinator import OpenUvCoordinator -CONF_ENTRY_ID = "entry_id" - PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR] -SERVICE_NAME_UPDATE_DATA = "update_data" -SERVICE_NAME_UPDATE_PROTECTION_DATA = "update_protection_data" -SERVICE_NAME_UPDATE_UV_INDEX_DATA = "update_uv_index_data" - -SERVICES = ( - SERVICE_NAME_UPDATE_DATA, - SERVICE_NAME_UPDATE_PROTECTION_DATA, - SERVICE_NAME_UPDATE_UV_INDEX_DATA, -) - - -@callback -def async_get_entity_id_from_unique_id_suffix( - hass: HomeAssistant, entry: ConfigEntry, unique_id_suffix: str -) -> str: - """Get the entity ID for a config entry based on unique ID suffix.""" - ent_reg = entity_registry.async_get(hass) - [registry_entry] = [ - registry_entry - for registry_entry in ent_reg.entities.values() - if registry_entry.config_entry_id == entry.entry_id - and registry_entry.unique_id.endswith(unique_id_suffix) - ] - return registry_entry.entity_id - - -@callback -def async_log_deprecated_service_call( - hass: HomeAssistant, - call: ServiceCall, - alternate_service: str, - alternate_targets: list[str], - breaks_in_ha_version: str, -) -> None: - """Log a warning about a deprecated service call.""" - deprecated_service = f"{call.domain}.{call.service}" - - if len(alternate_targets) > 1: - translation_key = "deprecated_service_multiple_alternate_targets" - else: - translation_key = "deprecated_service_single_alternate_target" - - async_create_issue( - hass, - DOMAIN, - f"deprecated_service_{deprecated_service}", - breaks_in_ha_version=breaks_in_ha_version, - is_fixable=False, - is_persistent=True, - severity=IssueSeverity.WARNING, - translation_key=translation_key, - translation_placeholders={ - "alternate_service": alternate_service, - "alternate_targets": ", ".join(alternate_targets), - "deprecated_service": deprecated_service, - }, - ) - - LOGGER.warning( - ( - 'The "%s" service is deprecated and will be removed in %s; review the ' - "Repairs item in the UI for more information" - ), - deprecated_service, - breaks_in_ha_version, - ) - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up OpenUV as config entry.""" - _verify_domain_control = verify_domain_control(hass, DOMAIN) - websession = aiohttp_client.async_get_clientsession(hass) client = Client( entry.data[CONF_API_KEY], @@ -162,81 +83,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - # We determine entity IDs needed to help the user migrate from deprecated services: - current_uv_index_entity_id = async_get_entity_id_from_unique_id_suffix( - hass, entry, "current_uv_index" - ) - protection_window_entity_id = async_get_entity_id_from_unique_id_suffix( - hass, entry, "protection_window" - ) - - @_verify_domain_control - async def update_data(call: ServiceCall) -> None: - """Refresh all OpenUV data.""" - LOGGER.debug("Refreshing all OpenUV data") - async_log_deprecated_service_call( - hass, - call, - "homeassistant.update_entity", - [protection_window_entity_id, current_uv_index_entity_id], - "2022.12.0", - ) - - tasks = [coordinator.async_refresh() for coordinator in coordinators.values()] - try: - await asyncio.gather(*tasks) - except UpdateFailed as err: - raise HomeAssistantError(err) from err - - @_verify_domain_control - async def update_uv_index_data(call: ServiceCall) -> None: - """Refresh OpenUV UV index data.""" - LOGGER.debug("Refreshing OpenUV UV index data") - async_log_deprecated_service_call( - hass, - call, - "homeassistant.update_entity", - [current_uv_index_entity_id], - "2022.12.0", - ) - - try: - await coordinators[DATA_UV].async_request_refresh() - except UpdateFailed as err: - raise HomeAssistantError(err) from err - - @_verify_domain_control - async def update_protection_data(call: ServiceCall) -> None: - """Refresh OpenUV protection window data.""" - LOGGER.debug("Refreshing OpenUV protection window data") - async_log_deprecated_service_call( - hass, - call, - "homeassistant.update_entity", - [protection_window_entity_id], - "2022.12.0", - ) - - try: - await coordinators[DATA_PROTECTION_WINDOW].async_request_refresh() - except UpdateFailed as err: - raise HomeAssistantError(err) from err - - service_schema = vol.Schema( - { - vol.Optional(CONF_ENTRY_ID, default=entry.entry_id): cv.string, - } - ) - - for service, method in ( - (SERVICE_NAME_UPDATE_DATA, update_data), - (SERVICE_NAME_UPDATE_UV_INDEX_DATA, update_uv_index_data), - (SERVICE_NAME_UPDATE_PROTECTION_DATA, update_protection_data), - ): - if hass.services.has_service(DOMAIN, service): - continue - hass.services.async_register(DOMAIN, service, method, schema=service_schema) - return True @@ -246,17 +92,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: - # If this is the last loaded instance of OpenUV, deregister any services - # defined during integration setup: - for service_name in SERVICES: - hass.services.async_remove(DOMAIN, service_name) - return unload_ok diff --git a/homeassistant/components/openuv/services.yaml b/homeassistant/components/openuv/services.yaml deleted file mode 100644 index 3e2e6ab0087..00000000000 --- a/homeassistant/components/openuv/services.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Describes the format for available OpenUV services -update_data: - name: Update data - description: Request new data from OpenUV. Consumes two API calls. - fields: - entry_id: - name: Config Entry - description: The configured instance of the OpenUV integration to use - required: true - selector: - config_entry: - integration: openuv - -update_uv_index_data: - name: Update UV index data - description: Request new UV index data from OpenUV. - fields: - entry_id: - name: Config Entry - description: The configured instance of the OpenUV integration to use - required: true - selector: - config_entry: - integration: openuv - -update_protection_data: - name: Update protection data - description: Request new protection window data from OpenUV. - fields: - entry_id: - name: Config Entry - description: The configured instance of the OpenUV integration to use - required: true - selector: - config_entry: - integration: openuv diff --git a/tests/components/openuv/conftest.py b/tests/components/openuv/conftest.py index 3caa41749ee..b2c0a6c7ec5 100644 --- a/tests/components/openuv/conftest.py +++ b/tests/components/openuv/conftest.py @@ -56,8 +56,6 @@ def data_uv_index_fixture(): async def setup_openuv_fixture(hass, config, data_protection_window, data_uv_index): """Define a fixture to set up OpenUV.""" with patch( - "homeassistant.components.openuv.async_get_entity_id_from_unique_id_suffix", - ), patch( "homeassistant.components.openuv.Client.uv_index", return_value=data_uv_index ), patch( "homeassistant.components.openuv.Client.uv_protection_window",