Remove deprecated blink refresh service (#119919)
* Remove deprecated blink refresh service * Remove string * Fix tests
This commit is contained in:
parent
f61347719f
commit
fe8805de6d
7 changed files with 9 additions and 170 deletions
|
@ -21,7 +21,6 @@ TYPE_BATTERY = "battery"
|
||||||
TYPE_WIFI_STRENGTH = "wifi_strength"
|
TYPE_WIFI_STRENGTH = "wifi_strength"
|
||||||
|
|
||||||
SERVICE_RECORD = "record"
|
SERVICE_RECORD = "record"
|
||||||
SERVICE_REFRESH = "blink_update"
|
|
||||||
SERVICE_TRIGGER = "trigger_camera"
|
SERVICE_TRIGGER = "trigger_camera"
|
||||||
SERVICE_SAVE_VIDEO = "save_video"
|
SERVICE_SAVE_VIDEO = "save_video"
|
||||||
SERVICE_SAVE_RECENT_CLIPS = "save_recent_clips"
|
SERVICE_SAVE_RECENT_CLIPS = "save_recent_clips"
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"blink_update": "mdi:update",
|
|
||||||
"record": "mdi:video-box",
|
"record": "mdi:video-box",
|
||||||
"trigger_camera": "mdi:image-refresh",
|
"trigger_camera": "mdi:image-refresh",
|
||||||
"save_video": "mdi:file-video",
|
"save_video": "mdi:file-video",
|
||||||
|
|
|
@ -8,13 +8,9 @@ from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||||
from homeassistant.const import ATTR_DEVICE_ID, CONF_PIN
|
from homeassistant.const import ATTR_DEVICE_ID, CONF_PIN
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
config_validation as cv,
|
|
||||||
device_registry as dr,
|
|
||||||
issue_registry as ir,
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
from .coordinator import BlinkUpdateCoordinator
|
||||||
|
|
||||||
SERVICE_UPDATE_SCHEMA = vol.Schema(
|
SERVICE_UPDATE_SCHEMA = vol.Schema(
|
||||||
|
@ -93,33 +89,9 @@ def setup_services(hass: HomeAssistant) -> None:
|
||||||
call.data[CONF_PIN],
|
call.data[CONF_PIN],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def blink_refresh(call: ServiceCall):
|
hass.services.async_register(
|
||||||
"""Call blink to refresh info."""
|
DOMAIN,
|
||||||
ir.async_create_issue(
|
SERVICE_SEND_PIN,
|
||||||
hass,
|
send_pin,
|
||||||
DOMAIN,
|
schema=SERVICE_SEND_PIN_SCHEMA,
|
||||||
"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,
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
# Describes the format for available Blink services
|
# Describes the format for available Blink services
|
||||||
|
|
||||||
blink_update:
|
|
||||||
fields:
|
|
||||||
device_id:
|
|
||||||
required: true
|
|
||||||
selector:
|
|
||||||
device:
|
|
||||||
integration: blink
|
|
||||||
|
|
||||||
record:
|
record:
|
||||||
target:
|
target:
|
||||||
entity:
|
entity:
|
||||||
|
|
|
@ -55,16 +55,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"blink_update": {
|
|
||||||
"name": "Update",
|
|
||||||
"description": "Forces a refresh.",
|
|
||||||
"fields": {
|
|
||||||
"device_id": {
|
|
||||||
"name": "Device ID",
|
|
||||||
"description": "The Blink device id."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"record": {
|
"record": {
|
||||||
"name": "Record",
|
"name": "Record",
|
||||||
"description": "Requests camera to record a clip."
|
"description": "Requests camera to record a clip."
|
||||||
|
|
|
@ -8,7 +8,6 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.blink.const import (
|
from homeassistant.components.blink.const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_REFRESH,
|
|
||||||
SERVICE_SAVE_VIDEO,
|
SERVICE_SAVE_VIDEO,
|
||||||
SERVICE_SEND_PIN,
|
SERVICE_SEND_PIN,
|
||||||
)
|
)
|
||||||
|
@ -82,7 +81,6 @@ async def test_unload_entry_multiple(
|
||||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||||
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
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_SAVE_VIDEO)
|
||||||
assert hass.services.has_service(DOMAIN, SERVICE_SEND_PIN)
|
assert hass.services.has_service(DOMAIN, SERVICE_SEND_PIN)
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,12 @@ import pytest
|
||||||
from homeassistant.components.blink.const import (
|
from homeassistant.components.blink.const import (
|
||||||
ATTR_CONFIG_ENTRY_ID,
|
ATTR_CONFIG_ENTRY_ID,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_REFRESH,
|
|
||||||
SERVICE_SEND_PIN,
|
SERVICE_SEND_PIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
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.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import device_registry as dr
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -23,43 +21,6 @@ FILENAME = "blah"
|
||||||
PIN = "1234"
|
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(
|
async def test_pin_service_calls(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_blink_api: MagicMock,
|
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(
|
async def test_service_pin_called_with_unloaded_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_blink_api: MagicMock,
|
mock_blink_api: MagicMock,
|
||||||
|
@ -193,34 +113,3 @@ async def test_service_pin_called_with_unloaded_entry(
|
||||||
parameters,
|
parameters,
|
||||||
blocking=True,
|
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,
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue