Skip to content

Commit

Permalink
Remove deprecated ring.update action (#125762)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede authored Sep 11, 2024
1 parent 344e43a commit bbdc036
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 137 deletions.
27 changes: 1 addition & 26 deletions homeassistant/components/ring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import APPLICATION_NAME, CONF_TOKEN
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import (
device_registry as dr,
entity_registry as er,
instance_id,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue

from .const import CONF_LISTEN_CREDENTIALS, DOMAIN, PLATFORMS
from .coordinator import RingDataCoordinator, RingListenCoordinator
Expand Down Expand Up @@ -103,30 +102,6 @@ def listen_credentials_updater(token: dict[str, Any]) -> None:
if hass.services.has_service(DOMAIN, "update"):
return True

async def async_refresh_all(_: ServiceCall) -> None:
"""Refresh all ring data."""
_LOGGER.warning(
"Detected use of service 'ring.update'. "
"This is deprecated and will stop working in Home Assistant 2024.10. "
"Use 'homeassistant.update_entity' instead which updates all ring entities",
)
async_create_issue(
hass,
DOMAIN,
"deprecated_service_ring_update",
breaks_in_ha_version="2024.10.0",
is_fixable=True,
is_persistent=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_service_ring_update",
)
for loaded_entry in hass.config_entries.async_loaded_entries(DOMAIN):
await loaded_entry.runtime_data.devices_coordinator.async_refresh()

# register service
hass.services.async_register(DOMAIN, "update", async_refresh_all)

return True


Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/ring/services.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions homeassistant/components/ring/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,7 @@
}
}
},
"services": {
"update": {
"name": "Update",
"description": "Updates the data we have for all your ring devices."
}
},
"issues": {
"deprecated_service_ring_update": {
"title": "Detected use of deprecated action `ring.update`",
"fix_flow": {
"step": {
"confirm": {
"title": "[%key:component::ring::issues::deprecated_service_ring_update::title%]",
"description": "Use `homeassistant.update_entity` instead which will update all ring entities.\n\nPlease replace uses of this action and adjust your automations and scripts and select **submit** to close this issue."
}
}
}
},
"deprecated_entity": {
"title": "Detected deprecated `{platform}` entity usage",
"description": "We detected that entity `{entity}` is being used in `{info}`\n\nWe have created a new `{new_platform}` entity and you should migrate `{info}` to use this new entity.\n\nWhen you are done migrating `{info}` and are ready to have the deprecated `{entity}` entity removed, disable the entity and restart Home Assistant."
Expand Down
19 changes: 0 additions & 19 deletions tests/components/ring/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,6 @@ def _has_capability(capability):
)


async def test_updates_work(
hass: HomeAssistant, mock_ring_client, mock_ring_devices
) -> None:
"""Tests the update service works correctly."""
await setup_platform(hass, Platform.CAMERA)
state = hass.states.get("camera.internal")
assert state.attributes.get("motion_detection") is True

internal_camera_mock = mock_ring_devices.get_device(345678)
internal_camera_mock.motion_detection = False

await hass.services.async_call("ring", "update", {}, blocking=True)

await hass.async_block_till_done()

state = hass.states.get("camera.internal")
assert state.attributes.get("motion_detection") is not True


@pytest.mark.parametrize(
("exception_type", "reauth_expected"),
[
Expand Down
29 changes: 1 addition & 28 deletions tests/components/ring/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import CONF_TOKEN, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er, issue_registry as ir
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component

from .device_mocks import FRONT_DOOR_DEVICE_ID
Expand Down Expand Up @@ -233,33 +233,6 @@ async def test_error_on_device_update(
assert hass.config_entries.async_get_entry(mock_config_entry.entry_id)


async def test_issue_deprecated_service_ring_update(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
caplog: pytest.LogCaptureFixture,
mock_ring_client,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the issue is raised on deprecated service ring.update."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

await hass.services.async_call(DOMAIN, "update", {}, blocking=True)

issue = issue_registry.async_get_issue("ring", "deprecated_service_ring_update")
assert issue
assert issue.issue_domain == "ring"
assert issue.issue_id == "deprecated_service_ring_update"
assert issue.translation_key == "deprecated_service_ring_update"

assert (
"Detected use of service 'ring.update'. "
"This is deprecated and will stop working in Home Assistant 2024.10. "
"Use 'homeassistant.update_entity' instead which updates all ring entities"
) in caplog.text


@pytest.mark.parametrize(
("domain", "old_unique_id"),
[
Expand Down
19 changes: 0 additions & 19 deletions tests/components/ring/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ async def test_light_can_be_turned_on(hass: HomeAssistant, mock_ring_client) ->
assert state.state == "on"


async def test_updates_work(
hass: HomeAssistant, mock_ring_client, mock_ring_devices
) -> None:
"""Tests the update service works correctly."""
await setup_platform(hass, Platform.LIGHT)
state = hass.states.get("light.front_light")
assert state.state == "off"

front_light_mock = mock_ring_devices.get_device(765432)
front_light_mock.lights = "on"

await hass.services.async_call("ring", "update", {}, blocking=True)

await hass.async_block_till_done()

state = hass.states.get("light.front_light")
assert state.state == "on"


@pytest.mark.parametrize(
("exception_type", "reauth_expected"),
[
Expand Down
28 changes: 1 addition & 27 deletions tests/components/ring/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import ring_doorbell

from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component

from .common import setup_platform

Expand Down Expand Up @@ -66,31 +65,6 @@ async def test_siren_can_be_turned_on(hass: HomeAssistant, mock_ring_client) ->
assert state.state == "on"


async def test_updates_work(
hass: HomeAssistant, mock_ring_client, mock_ring_devices
) -> None:
"""Tests the update service works correctly."""
await setup_platform(hass, Platform.SWITCH)
state = hass.states.get("switch.front_siren")
assert state.state == "off"

front_siren_mock = mock_ring_devices.get_device(765432)
front_siren_mock.siren = 20

await async_setup_component(hass, "homeassistant", {})
await hass.services.async_call(
"homeassistant",
"update_entity",
{ATTR_ENTITY_ID: ["switch.front_siren"]},
blocking=True,
)

await hass.async_block_till_done()

state = hass.states.get("switch.front_siren")
assert state.state == "on"


@pytest.mark.parametrize(
("exception_type", "reauth_expected"),
[
Expand Down

0 comments on commit bbdc036

Please sign in to comment.