From fe8805de6d71473eee9fcacee82cb3eb7575fdcc Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 18 Jun 2024 22:26:44 +0200 Subject: [PATCH] Remove deprecated blink refresh service (#119919) * Remove deprecated blink refresh service * Remove string * Fix tests --- homeassistant/components/blink/const.py | 1 - homeassistant/components/blink/icons.json | 1 - homeassistant/components/blink/services.py | 44 ++------ homeassistant/components/blink/services.yaml | 8 -- homeassistant/components/blink/strings.json | 10 -- tests/components/blink/test_init.py | 2 - tests/components/blink/test_services.py | 113 +------------------ 7 files changed, 9 insertions(+), 170 deletions(-) diff --git a/homeassistant/components/blink/const.py b/homeassistant/components/blink/const.py index 7de0e860bd8..0f24eec2178 100644 --- a/homeassistant/components/blink/const.py +++ b/homeassistant/components/blink/const.py @@ -21,7 +21,6 @@ TYPE_BATTERY = "battery" TYPE_WIFI_STRENGTH = "wifi_strength" SERVICE_RECORD = "record" -SERVICE_REFRESH = "blink_update" SERVICE_TRIGGER = "trigger_camera" SERVICE_SAVE_VIDEO = "save_video" SERVICE_SAVE_RECENT_CLIPS = "save_recent_clips" diff --git a/homeassistant/components/blink/icons.json b/homeassistant/components/blink/icons.json index 99bc91e37d4..615a3c4c6dc 100644 --- a/homeassistant/components/blink/icons.json +++ b/homeassistant/components/blink/icons.json @@ -12,7 +12,6 @@ } }, "services": { - "blink_update": "mdi:update", "record": "mdi:video-box", "trigger_camera": "mdi:image-refresh", "save_video": "mdi:file-video", diff --git a/homeassistant/components/blink/services.py b/homeassistant/components/blink/services.py index e01371c5c09..298ead00a45 100644 --- a/homeassistant/components/blink/services.py +++ b/homeassistant/components/blink/services.py @@ -8,13 +8,9 @@ from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import ATTR_DEVICE_ID, CONF_PIN from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import HomeAssistantError, ServiceValidationError -from homeassistant.helpers import ( - config_validation as cv, - device_registry as dr, - issue_registry as ir, -) +from homeassistant.helpers import config_validation as cv, device_registry as dr -from .const import ATTR_CONFIG_ENTRY_ID, DOMAIN, SERVICE_REFRESH, SERVICE_SEND_PIN +from .const import ATTR_CONFIG_ENTRY_ID, DOMAIN, SERVICE_SEND_PIN from .coordinator import BlinkUpdateCoordinator SERVICE_UPDATE_SCHEMA = vol.Schema( @@ -93,33 +89,9 @@ def setup_services(hass: HomeAssistant) -> None: call.data[CONF_PIN], ) - async def blink_refresh(call: ServiceCall): - """Call blink to refresh info.""" - ir.async_create_issue( - hass, - DOMAIN, - "service_deprecation", - breaks_in_ha_version="2024.7.0", - is_fixable=True, - is_persistent=True, - severity=ir.IssueSeverity.WARNING, - translation_key="service_deprecation", - ) - - for coordinator in collect_coordinators(call.data[ATTR_DEVICE_ID]): - await coordinator.api.refresh(force_cache=True) - - # Register all the above services - # Refresh service is deprecated and will be removed in 7/2024 - service_mapping = [ - (blink_refresh, SERVICE_REFRESH, SERVICE_UPDATE_SCHEMA), - (send_pin, SERVICE_SEND_PIN, SERVICE_SEND_PIN_SCHEMA), - ] - - for service_handler, service_name, schema in service_mapping: - hass.services.async_register( - DOMAIN, - service_name, - service_handler, - schema=schema, - ) + hass.services.async_register( + DOMAIN, + SERVICE_SEND_PIN, + send_pin, + schema=SERVICE_SEND_PIN_SCHEMA, + ) diff --git a/homeassistant/components/blink/services.yaml b/homeassistant/components/blink/services.yaml index 480810af2ba..244763d5535 100644 --- a/homeassistant/components/blink/services.yaml +++ b/homeassistant/components/blink/services.yaml @@ -1,13 +1,5 @@ # Describes the format for available Blink services -blink_update: - fields: - device_id: - required: true - selector: - device: - integration: blink - record: target: entity: diff --git a/homeassistant/components/blink/strings.json b/homeassistant/components/blink/strings.json index 8f94f8c9543..bd0e7789816 100644 --- a/homeassistant/components/blink/strings.json +++ b/homeassistant/components/blink/strings.json @@ -55,16 +55,6 @@ } }, "services": { - "blink_update": { - "name": "Update", - "description": "Forces a refresh.", - "fields": { - "device_id": { - "name": "Device ID", - "description": "The Blink device id." - } - } - }, "record": { "name": "Record", "description": "Requests camera to record a clip." diff --git a/tests/components/blink/test_init.py b/tests/components/blink/test_init.py index 46806ef3349..3cd2cd51ebd 100644 --- a/tests/components/blink/test_init.py +++ b/tests/components/blink/test_init.py @@ -8,7 +8,6 @@ import pytest from homeassistant.components.blink.const import ( DOMAIN, - SERVICE_REFRESH, SERVICE_SAVE_VIDEO, SERVICE_SEND_PIN, ) @@ -82,7 +81,6 @@ async def test_unload_entry_multiple( assert mock_config_entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(mock_config_entry.entry_id) assert mock_config_entry.state is ConfigEntryState.NOT_LOADED - assert hass.services.has_service(DOMAIN, SERVICE_REFRESH) assert hass.services.has_service(DOMAIN, SERVICE_SAVE_VIDEO) assert hass.services.has_service(DOMAIN, SERVICE_SEND_PIN) diff --git a/tests/components/blink/test_services.py b/tests/components/blink/test_services.py index d2685bd04eb..856d9e6e8a0 100644 --- a/tests/components/blink/test_services.py +++ b/tests/components/blink/test_services.py @@ -7,14 +7,12 @@ import pytest from homeassistant.components.blink.const import ( ATTR_CONFIG_ENTRY_ID, DOMAIN, - SERVICE_REFRESH, SERVICE_SEND_PIN, ) from homeassistant.config_entries import ConfigEntryState -from homeassistant.const import ATTR_DEVICE_ID, CONF_PIN +from homeassistant.const import CONF_PIN from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import device_registry as dr from tests.common import MockConfigEntry @@ -23,43 +21,6 @@ FILENAME = "blah" PIN = "1234" -async def test_refresh_service_calls( - hass: HomeAssistant, - device_registry: dr.DeviceRegistry, - mock_blink_api: MagicMock, - mock_blink_auth_api: MagicMock, - mock_config_entry: MockConfigEntry, -) -> None: - """Test refrest service calls.""" - - mock_config_entry.add_to_hass(hass) - assert await hass.config_entries.async_setup(mock_config_entry.entry_id) - await hass.async_block_till_done() - - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "12345")}) - assert device_entry - - assert mock_config_entry.state is ConfigEntryState.LOADED - assert mock_blink_api.refresh.call_count == 1 - - await hass.services.async_call( - DOMAIN, - SERVICE_REFRESH, - {ATTR_DEVICE_ID: [device_entry.id]}, - blocking=True, - ) - - assert mock_blink_api.refresh.call_count == 2 - - with pytest.raises(HomeAssistantError): - await hass.services.async_call( - DOMAIN, - SERVICE_REFRESH, - {ATTR_DEVICE_ID: ["bad-device_id"]}, - blocking=True, - ) - - async def test_pin_service_calls( hass: HomeAssistant, mock_blink_api: MagicMock, @@ -128,47 +89,6 @@ async def test_service_pin_called_with_non_blink_device( ) -async def test_service_update_called_with_non_blink_device( - hass: HomeAssistant, - mock_blink_api: MagicMock, - device_registry: dr.DeviceRegistry, - mock_blink_auth_api: MagicMock, - mock_config_entry: MockConfigEntry, -) -> None: - """Test update service calls with non blink device.""" - - mock_config_entry.add_to_hass(hass) - assert await hass.config_entries.async_setup(mock_config_entry.entry_id) - await hass.async_block_till_done() - - other_domain = "NotBlink" - other_config_id = "555" - other_mock_config_entry = MockConfigEntry( - title="Not Blink", domain=other_domain, entry_id=other_config_id - ) - other_mock_config_entry.add_to_hass(hass) - - device_entry = device_registry.async_get_or_create( - config_entry_id=other_config_id, - identifiers={ - (other_domain, 1), - }, - ) - - hass.config.is_allowed_path = Mock(return_value=True) - mock_blink_api.cameras = {CAMERA_NAME: AsyncMock()} - - parameters = {ATTR_DEVICE_ID: [device_entry.id]} - - with pytest.raises(HomeAssistantError): - await hass.services.async_call( - DOMAIN, - SERVICE_REFRESH, - parameters, - blocking=True, - ) - - async def test_service_pin_called_with_unloaded_entry( hass: HomeAssistant, mock_blink_api: MagicMock, @@ -193,34 +113,3 @@ async def test_service_pin_called_with_unloaded_entry( parameters, blocking=True, ) - - -async def test_service_update_called_with_unloaded_entry( - hass: HomeAssistant, - device_registry: dr.DeviceRegistry, - mock_blink_api: MagicMock, - mock_blink_auth_api: MagicMock, - mock_config_entry: MockConfigEntry, -) -> None: - """Test update service calls with not ready config entry.""" - - mock_config_entry.add_to_hass(hass) - assert await hass.config_entries.async_setup(mock_config_entry.entry_id) - await hass.async_block_till_done() - - mock_config_entry.mock_state(hass, ConfigEntryState.SETUP_ERROR) - hass.config.is_allowed_path = Mock(return_value=True) - mock_blink_api.cameras = {CAMERA_NAME: AsyncMock()} - - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "12345")}) - assert device_entry - - parameters = {ATTR_DEVICE_ID: [device_entry.id]} - - with pytest.raises(HomeAssistantError): - await hass.services.async_call( - DOMAIN, - SERVICE_REFRESH, - parameters, - blocking=True, - )