Remove deprecated notify service in ecobee (#128177)

This commit is contained in:
G Johansson 2024-10-11 18:21:28 +02:00 committed by GitHub
parent 39e63aee0c
commit a85d7af9e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 4 additions and 160 deletions

View File

@ -6,15 +6,14 @@ from pyecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN, Ecobee, ExpiredTokenE
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_NAME, Platform
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import Throttle
from .const import (
_LOGGER,
ATTR_CONFIG_ENTRY_ID,
CONF_REFRESH_TOKEN,
DATA_ECOBEE_CONFIG,
DATA_HASS_CONFIG,
@ -73,18 +72,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
# The legacy Ecobee notify.notify service is deprecated
# was with HA Core 2024.5.0 and will be removed with HA core 2024.11.0
hass.async_create_task(
discovery.async_load_platform(
hass,
Platform.NOTIFY,
DOMAIN,
{CONF_NAME: entry.title, ATTR_CONFIG_ENTRY_ID: entry.entry_id},
hass.data[DATA_HASS_CONFIG],
)
)
return True

View File

@ -2,66 +2,16 @@
from __future__ import annotations
from functools import partial
from typing import Any
from homeassistant.components.notify import (
ATTR_TARGET,
BaseNotificationService,
NotifyEntity,
migrate_notify_issue,
)
from homeassistant.components.notify import NotifyEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import Ecobee, EcobeeData
from . import EcobeeData
from .const import DOMAIN
from .entity import EcobeeBaseEntity
def get_service(
hass: HomeAssistant,
config: ConfigType,
discovery_info: DiscoveryInfoType | None = None,
) -> EcobeeNotificationService | None:
"""Get the Ecobee notification service."""
if discovery_info is None:
return None
data: EcobeeData = hass.data[DOMAIN]
return EcobeeNotificationService(data.ecobee)
class EcobeeNotificationService(BaseNotificationService):
"""Implement the notification service for the Ecobee thermostat."""
def __init__(self, ecobee: Ecobee) -> None:
"""Initialize the service."""
self.ecobee = ecobee
async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
"""Send a message and raise issue."""
migrate_notify_issue(
self.hass, DOMAIN, "Ecobee", "2024.11.0", service_name=self._service_name
)
await self.hass.async_add_executor_job(
partial(self.send_message, message, **kwargs)
)
def send_message(self, message: str = "", **kwargs: Any) -> None:
"""Send a message."""
targets = kwargs.get(ATTR_TARGET)
if not targets:
raise ValueError("Missing required argument: target")
for target in targets:
thermostat_index = int(target)
self.ecobee.send_message(thermostat_index, message)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -2,13 +2,11 @@
from unittest.mock import MagicMock
from homeassistant.components.ecobee import DOMAIN
from homeassistant.components.notify import (
DOMAIN as NOTIFY_DOMAIN,
SERVICE_SEND_MESSAGE,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from .common import setup_platform
@ -34,24 +32,3 @@ async def test_notify_entity_service(
)
await hass.async_block_till_done()
mock_ecobee.send_message.assert_called_with(THERMOSTAT_ID, "It is too cold!")
async def test_legacy_notify_service(
hass: HomeAssistant,
mock_ecobee: MagicMock,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the legacy notify service."""
await setup_platform(hass, NOTIFY_DOMAIN)
assert hass.services.has_service(NOTIFY_DOMAIN, DOMAIN)
await hass.services.async_call(
NOTIFY_DOMAIN,
DOMAIN,
service_data={"message": "It is too cold!", "target": THERMOSTAT_ID},
blocking=True,
)
await hass.async_block_till_done()
mock_ecobee.send_message.assert_called_with(THERMOSTAT_ID, "It is too cold!")
mock_ecobee.send_message.reset_mock()
assert len(issue_registry.issues) == 1

View File

@ -1,70 +0,0 @@
"""Test repairs for Ecobee integration."""
from unittest.mock import MagicMock
from homeassistant.components.ecobee import DOMAIN
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from .common import setup_platform
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator
THERMOSTAT_ID = 0
async def test_ecobee_notify_repair_flow(
hass: HomeAssistant,
mock_ecobee: MagicMock,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the ecobee notify service repair flow is triggered."""
await setup_platform(hass, NOTIFY_DOMAIN)
await async_process_repairs_platforms(hass)
http_client = await hass_client()
# Simulate legacy service being used
assert hass.services.has_service(NOTIFY_DOMAIN, DOMAIN)
await hass.services.async_call(
NOTIFY_DOMAIN,
DOMAIN,
service_data={"message": "It is too cold!", "target": THERMOSTAT_ID},
blocking=True,
)
await hass.async_block_till_done()
mock_ecobee.send_message.assert_called_with(THERMOSTAT_ID, "It is too cold!")
mock_ecobee.send_message.reset_mock()
# Assert the issue is present
assert issue_registry.async_get_issue(
domain="notify",
issue_id=f"migrate_notify_{DOMAIN}_{DOMAIN}",
)
assert len(issue_registry.issues) == 1
data = await start_repair_fix_flow(
http_client, "notify", f"migrate_notify_{DOMAIN}_{DOMAIN}"
)
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
# Test confirm step in repair flow
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_{DOMAIN}_{DOMAIN}",
)
assert len(issue_registry.issues) == 0