Skip to content

Commit

Permalink
Prepare ring update service for deprecation (home-assistant#108781)
Browse files Browse the repository at this point in the history
* Prepare ring update service for deprecation

* Update service removal release number
  • Loading branch information
sdb9696 authored Mar 11, 2024
1 parent f8d1232 commit 48cb09a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
18 changes: 18 additions & 0 deletions homeassistant/components/ring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from homeassistant.const import APPLICATION_NAME, CONF_TOKEN, __version__
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue

from .const import (
DOMAIN,
Expand Down Expand Up @@ -62,6 +63,23 @@ def token_updater(token):

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 info in hass.data[DOMAIN].values():
await info[RING_DEVICES_COORDINATOR].async_refresh()
await info[RING_NOTIFICATIONS_COORDINATOR].async_refresh()
Expand Down
13 changes: 13 additions & 0 deletions homeassistant/components/ring/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,18 @@
"name": "Update",
"description": "Updates the data we have for all your ring devices."
}
},
"issues": {
"deprecated_service_ring_update": {
"title": "Detected use of deprecated service `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 calls to this service and adjust your automations and scripts and select **submit** to close this issue."
}
}
}
}
}
}
28 changes: 28 additions & 0 deletions tests/components/ring/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from homeassistant.components.ring import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers.issue_registry import IssueRegistry
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -238,3 +239,30 @@ async def test_error_on_device_update(
record.message for record in caplog.records if record.levelname == "ERROR"
]
assert mock_config_entry.entry_id in hass.data[DOMAIN]


async def test_issue_deprecated_service_ring_update(
hass: HomeAssistant,
issue_registry: IssueRegistry,
caplog: pytest.LogCaptureFixture,
requests_mock: requests_mock.Mocker,
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

0 comments on commit 48cb09a

Please sign in to comment.