diff --git a/homeassistant/components/rainbird/__init__.py b/homeassistant/components/rainbird/__init__.py index 7b41a3f2f5e..9c6605bcbba 100644 --- a/homeassistant/components/rainbird/__init__.py +++ b/homeassistant/components/rainbird/__init__.py @@ -6,7 +6,7 @@ import logging from pyrainbird.async_client import AsyncRainbirdClient, AsyncRainbirdController import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry, ConfigEntryState +from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import ( CONF_FRIENDLY_NAME, CONF_HOST, @@ -14,15 +14,13 @@ from homeassistant.const import ( CONF_TRIGGER_TIME, Platform, ) -from homeassistant.core import HomeAssistant, ServiceCall -from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import entity_registry as er +from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType -from .const import ATTR_CONFIG_ENTRY_ID, ATTR_DURATION, CONF_SERIAL_NUMBER, CONF_ZONES +from .const import CONF_SERIAL_NUMBER, CONF_ZONES from .coordinator import RainbirdUpdateCoordinator PLATFORMS = [Platform.SWITCH, Platform.SENSOR, Platform.BINARY_SENSOR, Platform.NUMBER] @@ -54,16 +52,6 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) -SERVICE_SET_RAIN_DELAY = "set_rain_delay" -SERVICE_SCHEMA_RAIN_DELAY = vol.All( - vol.Schema( - { - vol.Required(ATTR_CONFIG_ENTRY_ID): cv.string, - vol.Required(ATTR_DURATION): cv.positive_float, - } - ), -) - async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Rain Bird component.""" @@ -116,44 +104,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - async def set_rain_delay(call: ServiceCall) -> None: - """Service call to delay automatic irrigigation.""" - - entry_id = call.data[ATTR_CONFIG_ENTRY_ID] - duration = call.data[ATTR_DURATION] - if entry_id not in hass.data[DOMAIN]: - raise HomeAssistantError(f"Config entry id does not exist: {entry_id}") - coordinator = hass.data[DOMAIN][entry_id] - - entity_registry = er.async_get(hass) - entity_ids = ( - entry.entity_id - for entry in er.async_entries_for_config_entry(entity_registry, entry_id) - if entry.unique_id == f"{coordinator.serial_number}-rain-delay" - ) - async_create_issue( - hass, - DOMAIN, - "deprecated_raindelay", - breaks_in_ha_version="2023.4.0", - is_fixable=True, - is_persistent=True, - severity=IssueSeverity.WARNING, - translation_key="deprecated_raindelay", - translation_placeholders={ - "alternate_target": next(entity_ids, "unknown"), - }, - ) - - await coordinator.controller.set_rain_delay(duration) - - hass.services.async_register( - DOMAIN, - SERVICE_SET_RAIN_DELAY, - set_rain_delay, - schema=SERVICE_SCHEMA_RAIN_DELAY, - ) - return True @@ -163,12 +113,4 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): 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: - hass.services.async_remove(DOMAIN, SERVICE_SET_RAIN_DELAY) - return unload_ok diff --git a/homeassistant/components/rainbird/strings.json b/homeassistant/components/rainbird/strings.json index f950146f160..642612b11d2 100644 --- a/homeassistant/components/rainbird/strings.json +++ b/homeassistant/components/rainbird/strings.json @@ -32,17 +32,6 @@ "deprecated_yaml": { "title": "The Rain Bird YAML configuration is being removed", "description": "Configuring Rain Bird in configuration.yaml is being removed in Home Assistant 2023.4.\n\nYour configuration has been imported into the UI automatically, however default per-zone irrigation times are no longer supported. Remove the Rain Bird YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue." - }, - "deprecated_raindelay": { - "title": "The Rain Bird Rain Delay Service is being removed", - "fix_flow": { - "step": { - "confirm": { - "title": "The Rain Bird Rain Delay Service is being removed", - "description": "The Rain Bird service `rainbird.set_rain_delay` is being removed and replaced by a Number entity for managing the rain delay. Any existing automations or scripts will need to be updated to use `number.set_value` with a target of `{alternate_target}` instead." - } - } - } } } } diff --git a/tests/components/rainbird/test_init.py b/tests/components/rainbird/test_init.py index dedfbfe0864..8a7838c3caf 100644 --- a/tests/components/rainbird/test_init.py +++ b/tests/components/rainbird/test_init.py @@ -5,25 +5,19 @@ from __future__ import annotations import pytest from homeassistant.components.rainbird import DOMAIN -from homeassistant.components.rainbird.const import ATTR_CONFIG_ENTRY_ID, ATTR_DURATION -from homeassistant.config_entries import ConfigEntry, ConfigEntryState -from homeassistant.const import Platform +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import device_registry as dr, issue_registry as ir from .conftest import ( - ACK_ECHO, CONFIG, CONFIG_ENTRY_DATA, - SERIAL_NUMBER, SERIAL_RESPONSE, UNAVAILABLE_RESPONSE, ComponentSetup, mock_response, ) -from tests.test_util.aiohttp import AiohttpClientMocker, AiohttpClientMockResponse +from tests.test_util.aiohttp import AiohttpClientMockResponse @pytest.mark.parametrize( @@ -100,65 +94,3 @@ async def test_communication_failure( assert [ entry.state for entry in hass.config_entries.async_entries(DOMAIN) ] == config_entry_states - - -@pytest.mark.parametrize("platforms", [[Platform.NUMBER, Platform.SENSOR]]) -async def test_rain_delay_service( - hass: HomeAssistant, - setup_integration: ComponentSetup, - aioclient_mock: AiohttpClientMocker, - responses: list[str], - config_entry: ConfigEntry, - issue_registry: ir.IssueRegistry, -) -> None: - """Test calling the rain delay service.""" - - assert await setup_integration() - - device_registry = dr.async_get(hass) - device = device_registry.async_get_device({(DOMAIN, SERIAL_NUMBER)}) - assert device - assert device.name == "Rain Bird Controller" - - aioclient_mock.mock_calls.clear() - responses.append(mock_response(ACK_ECHO)) - - await hass.services.async_call( - DOMAIN, - "set_rain_delay", - {ATTR_CONFIG_ENTRY_ID: config_entry.entry_id, ATTR_DURATION: 3}, - blocking=True, - ) - - assert len(aioclient_mock.mock_calls) == 1 - - issue = issue_registry.async_get_issue( - domain=DOMAIN, issue_id="deprecated_raindelay" - ) - assert issue - assert issue.translation_placeholders == { - "alternate_target": "number.rain_bird_controller_rain_delay" - } - - -async def test_rain_delay_invalid_config_entry( - hass: HomeAssistant, - setup_integration: ComponentSetup, - aioclient_mock: AiohttpClientMocker, - config_entry: ConfigEntry, -) -> None: - """Test calling the rain delay service.""" - - assert await setup_integration() - - aioclient_mock.mock_calls.clear() - - with pytest.raises(HomeAssistantError, match="Config entry id does not exist"): - await hass.services.async_call( - DOMAIN, - "set_rain_delay", - {ATTR_CONFIG_ENTRY_ID: "invalid", ATTR_DURATION: 3}, - blocking=True, - ) - - assert len(aioclient_mock.mock_calls) == 0