mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove tibber legacy notify service after 6 months of deprecation (#130292)
This commit is contained in:
parent
ee41725b53
commit
d8b55d39e4
@ -6,15 +6,9 @@ import aiohttp
|
||||
import tibber
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_NAME,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, EVENT_HOMEASSISTANT_STOP, Platform
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@ -73,19 +67,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
# Use discovery to load platform legacy notify platform
|
||||
# The use of the legacy notify service was deprecated with HA Core 2024.6
|
||||
# Support will be removed with HA Core 2024.12
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass,
|
||||
Platform.NOTIFY,
|
||||
DOMAIN,
|
||||
{CONF_NAME: DOMAIN},
|
||||
hass.data[DATA_HASS_CONFIG],
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
@ -2,38 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from tibber import Tibber
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TITLE,
|
||||
ATTR_TITLE_DEFAULT,
|
||||
BaseNotificationService,
|
||||
NotifyEntity,
|
||||
NotifyEntityFeature,
|
||||
migrate_notify_issue,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN as TIBBER_DOMAIN
|
||||
|
||||
|
||||
async def async_get_service(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> TibberNotificationService:
|
||||
"""Get the Tibber notification service."""
|
||||
tibber_connection: Tibber = hass.data[TIBBER_DOMAIN]
|
||||
return TibberNotificationService(tibber_connection.send_notification)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
@ -41,31 +24,6 @@ async def async_setup_entry(
|
||||
async_add_entities([TibberNotificationEntity(entry.entry_id)])
|
||||
|
||||
|
||||
class TibberNotificationService(BaseNotificationService):
|
||||
"""Implement the notification service for Tibber."""
|
||||
|
||||
def __init__(self, notify: Callable) -> None:
|
||||
"""Initialize the service."""
|
||||
self._notify = notify
|
||||
|
||||
async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||
"""Send a message to Tibber devices."""
|
||||
migrate_notify_issue(
|
||||
self.hass,
|
||||
TIBBER_DOMAIN,
|
||||
"Tibber",
|
||||
"2024.12.0",
|
||||
service_name=self._service_name,
|
||||
)
|
||||
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||
try:
|
||||
await self._notify(title=title, message=message)
|
||||
except TimeoutError as exc:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=TIBBER_DOMAIN, translation_key="send_message_timeout"
|
||||
) from exc
|
||||
|
||||
|
||||
class TibberNotificationEntity(NotifyEntity):
|
||||
"""Implement the notification entity service for Tibber."""
|
||||
|
||||
|
@ -19,12 +19,9 @@ async def test_entry_diagnostics(
|
||||
config_entry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
with (
|
||||
patch(
|
||||
with patch(
|
||||
"tibber.Tibber.update_info",
|
||||
return_value=None,
|
||||
),
|
||||
patch("homeassistant.components.tibber.discovery.async_load_platform"),
|
||||
):
|
||||
assert await async_setup_component(hass, "tibber", {})
|
||||
|
||||
|
@ -6,7 +6,6 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.recorder import Recorder
|
||||
from homeassistant.components.tibber import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
@ -19,18 +18,8 @@ async def test_notification_services(
|
||||
notify_state = hass.states.get("notify.tibber")
|
||||
assert notify_state is not None
|
||||
|
||||
# Assert legacy notify service hass been added
|
||||
assert hass.services.has_service("notify", DOMAIN)
|
||||
|
||||
# Test legacy notify service
|
||||
service = "tibber"
|
||||
service_data = {"message": "The message", "title": "A title"}
|
||||
await hass.services.async_call("notify", service, service_data, blocking=True)
|
||||
calls: MagicMock = mock_tibber_setup.send_notification
|
||||
|
||||
calls.assert_called_once_with(message="The message", title="A title")
|
||||
calls.reset_mock()
|
||||
|
||||
# Test notify entity service
|
||||
service = "send_message"
|
||||
service_data = {
|
||||
@ -44,15 +33,6 @@ async def test_notification_services(
|
||||
|
||||
calls.side_effect = TimeoutError
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
# Test legacy notify service
|
||||
await hass.services.async_call(
|
||||
"notify",
|
||||
service="tibber",
|
||||
service_data={"message": "The message", "title": "A title"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
# Test notify entity service
|
||||
await hass.services.async_call(
|
||||
|
@ -1,56 +0,0 @@
|
||||
"""Test loading of the Tibber config entry."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.components.recorder import Recorder
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_repair_flow(
|
||||
recorder_mock: Recorder,
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_tibber_setup: MagicMock,
|
||||
hass_client: ClientSessionGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the entry."""
|
||||
|
||||
# Test legacy notify service
|
||||
service = "tibber"
|
||||
service_data = {"message": "The message", "title": "A title"}
|
||||
await hass.services.async_call("notify", service, service_data, blocking=True)
|
||||
calls: MagicMock = mock_tibber_setup.send_notification
|
||||
|
||||
calls.assert_called_once_with(message="The message", title="A title")
|
||||
calls.reset_mock()
|
||||
|
||||
http_client = await hass_client()
|
||||
# Assert the issue is present
|
||||
assert issue_registry.async_get_issue(
|
||||
domain="notify",
|
||||
issue_id=f"migrate_notify_tibber_{service}",
|
||||
)
|
||||
assert len(issue_registry.issues) == 1
|
||||
|
||||
data = await start_repair_fix_flow(
|
||||
http_client, "notify", f"migrate_notify_tibber_{service}"
|
||||
)
|
||||
|
||||
flow_id = data["flow_id"]
|
||||
assert data["step_id"] == "confirm"
|
||||
|
||||
# Simulate the users confirmed the repair flow
|
||||
data = await process_repair_fix_flow(http_client, flow_id)
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Assert the issue is no longer present
|
||||
assert not issue_registry.async_get_issue(
|
||||
domain="notify",
|
||||
issue_id=f"migrate_notify_tibber_{service}",
|
||||
)
|
||||
assert len(issue_registry.issues) == 0
|
Loading…
x
Reference in New Issue
Block a user