Migrate legacy Ecobee notify service (#115592)

* Migrate legacy Ecobee notify service

* Correct comment

* Update homeassistant/components/ecobee/notify.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Use version to check latest entry being used

* Use 6 months of deprecation

* Add repair flow tests

* Only allow migrate_notify fix flow

* Simplify repair flow

* Use ecobee data to refrence entry

* Make entry attrubute puiblic

* Use hass.data ro retrieve entry.

* Only register issue when legacy service when it is use

* Remove backslash

* Use ws_client.send_json_auto_id

* Cleanup

* Import domain from notify integration

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update dependencies

* Use Issue_registry fixture

* remove `update_before_add` flag

* Update homeassistant/components/ecobee/notify.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/ecobee/notify.py

* Update tests/components/ecobee/conftest.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Fix typo and import

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Jan Bouwhuis 2024-04-23 22:53:13 +02:00 committed by GitHub
parent 0f60b404df
commit 8d2813fb8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 259 additions and 11 deletions

View file

@ -2,11 +2,23 @@
from __future__ import annotations
from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService
from functools import partial
from typing import Any
from homeassistant.components.notify import (
ATTR_TARGET,
BaseNotificationService,
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 .const import DOMAIN
from .entity import EcobeeBaseEntity
from .repairs import migrate_notify_issue
def get_service(
@ -18,18 +30,25 @@ def get_service(
if discovery_info is None:
return None
data = hass.data[DOMAIN]
data: EcobeeData = hass.data[DOMAIN]
return EcobeeNotificationService(data.ecobee)
class EcobeeNotificationService(BaseNotificationService):
"""Implement the notification service for the Ecobee thermostat."""
def __init__(self, ecobee):
def __init__(self, ecobee: Ecobee) -> None:
"""Initialize the service."""
self.ecobee = ecobee
def send_message(self, message="", **kwargs):
async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
"""Send a message and raise issue."""
migrate_notify_issue(self.hass)
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)
@ -39,3 +58,33 @@ class EcobeeNotificationService(BaseNotificationService):
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,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the ecobee thermostat."""
data: EcobeeData = hass.data[DOMAIN]
async_add_entities(
EcobeeNotifyEntity(data, index) for index in range(len(data.ecobee.thermostats))
)
class EcobeeNotifyEntity(EcobeeBaseEntity, NotifyEntity):
"""Implement the notification entity for the Ecobee thermostat."""
_attr_name = None
_attr_has_entity_name = True
def __init__(self, data: EcobeeData, thermostat_index: int) -> None:
"""Initialize the thermostat."""
super().__init__(data, thermostat_index)
self._attr_unique_id = (
f"{self.thermostat["identifier"]}_notify_{thermostat_index}"
)
def send_message(self, message: str) -> None:
"""Send a message."""
self.data.ecobee.send_message(self.thermostat_index, message)