Add service to set netatmo home heating schedule (#29244)

* Add service to set netatmo home heating schedule.

* handle NoDevice exeption; add service argument constant
This commit is contained in:
1v0dev 2019-12-06 18:45:27 +02:00 committed by cgtobi
parent 48aba426a9
commit b8434fdcfd
2 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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