From b8434fdcfda3a93ef568d7f31ad669baa65272d9 Mon Sep 17 00:00:00 2001 From: 1v0dev <56637685+1v0dev@users.noreply.github.com> Date: Fri, 6 Dec 2019 18:45:27 +0200 Subject: [PATCH] Add service to set netatmo home heating schedule (#29244) * Add service to set netatmo home heating schedule. * handle NoDevice exeption; add service argument constant --- homeassistant/components/netatmo/__init__.py | 24 +++++++++++++++++++ .../components/netatmo/services.yaml | 7 ++++++ 2 files changed, 31 insertions(+) diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py index de371f97e28..9edeb0937a1 100644 --- a/homeassistant/components/netatmo/__init__.py +++ b/homeassistant/components/netatmo/__init__.py @@ -30,6 +30,7 @@ CONF_WEBHOOKS = "webhooks" SERVICE_ADDWEBHOOK = "addwebhook" SERVICE_DROPWEBHOOK = "dropwebhook" +SERVICE_SETSCHEDULE = "set_schedule" NETATMO_AUTH = None NETATMO_WEBHOOK_URL = None @@ -63,6 +64,7 @@ ATTR_IS_KNOWN = "is_known" ATTR_FACE_URL = "face_url" ATTR_SNAPSHOT_URL = "snapshot_url" ATTR_VIGNETTE_URL = "vignette_url" +ATTR_SCHEDULE = "schedule" MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5) MIN_TIME_BETWEEN_EVENT_UPDATES = timedelta(seconds=5) @@ -87,6 +89,8 @@ SCHEMA_SERVICE_ADDWEBHOOK = vol.Schema({vol.Optional(CONF_URL): cv.string}) SCHEMA_SERVICE_DROPWEBHOOK = vol.Schema({}) +SCHEMA_SERVICE_SETSCHEDULE = vol.Schema({vol.Required(ATTR_SCHEDULE): cv.string}) + def setup(hass, config): """Set up the Netatmo devices.""" @@ -106,6 +110,12 @@ def setup(hass, config): _LOGGER.error("Unable to connect to Netatmo API") return False + try: + home_data = pyatmo.HomeData(auth) + except pyatmo.NoDevice: + home_data = None + _LOGGER.debug("No climate device. Disable %s service", SERVICE_SETSCHEDULE) + # Store config to be used during entry setup hass.data[DATA_NETATMO_AUTH] = auth @@ -151,6 +161,20 @@ def setup(hass, config): schema=SCHEMA_SERVICE_DROPWEBHOOK, ) + def _service_setschedule(service): + """Service to change current home schedule.""" + schedule_name = service.data.get(ATTR_SCHEDULE) + home_data.switchHomeSchedule(schedule=schedule_name) + _LOGGER.info("Set home schedule to %s", schedule_name) + + if home_data is not None: + hass.services.register( + DOMAIN, + SERVICE_SETSCHEDULE, + _service_setschedule, + schema=SCHEMA_SERVICE_SETSCHEDULE, + ) + return True diff --git a/homeassistant/components/netatmo/services.yaml b/homeassistant/components/netatmo/services.yaml index a928f4765e0..d8fa223780a 100644 --- a/homeassistant/components/netatmo/services.yaml +++ b/homeassistant/components/netatmo/services.yaml @@ -28,3 +28,10 @@ set_light_off: entity_id: description: Entity id. example: 'camera.living_room' + +set_schedule: + description: Set the home heating schedule + fields: + schedule: + description: Schedule name + example: Standard \ No newline at end of file