mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
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:
parent
48aba426a9
commit
b8434fdcfd
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user