diff --git a/homeassistant/components/ecobee/__init__.py b/homeassistant/components/ecobee/__init__.py index 7204dbf8de2..31a1e753fc6 100644 --- a/homeassistant/components/ecobee/__init__.py +++ b/homeassistant/components/ecobee/__init__.py @@ -5,13 +5,21 @@ 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 +from homeassistant.const import CONF_API_KEY, CONF_NAME, Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, discovery from homeassistant.helpers.typing import ConfigType from homeassistant.util import Throttle -from .const import _LOGGER, CONF_REFRESH_TOKEN, DATA_ECOBEE_CONFIG, DOMAIN, PLATFORMS +from .const import ( + _LOGGER, + ATTR_CONFIG_ENTRY_ID, + CONF_REFRESH_TOKEN, + DATA_ECOBEE_CONFIG, + DATA_HASS_CONFIG, + DOMAIN, + PLATFORMS, +) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=180) @@ -30,7 +38,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: migrating from the old ecobee integration. Otherwise, the user will have to continue setting up the integration via the config flow. """ + hass.data[DATA_ECOBEE_CONFIG] = config.get(DOMAIN, {}) + hass.data[DATA_HASS_CONFIG] = config if not hass.config_entries.async_entries(DOMAIN) and hass.data[DATA_ECOBEE_CONFIG]: # No config entry exists and configuration.yaml config exists, trigger the import flow. @@ -63,6 +73,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + 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 diff --git a/homeassistant/components/ecobee/const.py b/homeassistant/components/ecobee/const.py index b4e0c485e45..4a318f2be3c 100644 --- a/homeassistant/components/ecobee/const.py +++ b/homeassistant/components/ecobee/const.py @@ -20,8 +20,9 @@ _LOGGER = logging.getLogger(__package__) DOMAIN = "ecobee" DATA_ECOBEE_CONFIG = "ecobee_config" +DATA_HASS_CONFIG = "ecobee_hass_config" +ATTR_CONFIG_ENTRY_ID = "entry_id" -CONF_INDEX = "index" CONF_REFRESH_TOKEN = "refresh_token" ECOBEE_MODEL_TO_NAME = { diff --git a/homeassistant/components/ecobee/notify.py b/homeassistant/components/ecobee/notify.py index a8f53a027b3..75d1316f0e3 100644 --- a/homeassistant/components/ecobee/notify.py +++ b/homeassistant/components/ecobee/notify.py @@ -1,31 +1,33 @@ """Support for Ecobee Send Message service.""" -import voluptuous as vol -from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService -import homeassistant.helpers.config_validation as cv +from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService -from .const import CONF_INDEX, DOMAIN - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Optional(CONF_INDEX, default=0): cv.positive_int} -) +from .const import DOMAIN def get_service(hass, config, discovery_info=None): """Get the Ecobee notification service.""" + if discovery_info is None: + return None + data = hass.data[DOMAIN] - index = config.get(CONF_INDEX) - return EcobeeNotificationService(data, index) + return EcobeeNotificationService(data.ecobee) class EcobeeNotificationService(BaseNotificationService): """Implement the notification service for the Ecobee thermostat.""" - def __init__(self, data, thermostat_index): + def __init__(self, ecobee): """Initialize the service.""" - self.data = data - self.thermostat_index = thermostat_index + self.ecobee = ecobee def send_message(self, message="", **kwargs): """Send a message.""" - self.data.ecobee.send_message(self.thermostat_index, 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)