-
-
Notifications
You must be signed in to change notification settings - Fork 38k
Add Rachio Flex Schedules #33533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rachio Flex Schedules #33533
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.components.switch import SwitchDevice | ||
| from homeassistant.helpers.dispatcher import async_dispatcher_connect | ||
|
|
||
|
|
@@ -68,13 +69,13 @@ def _create_entities(hass, config_entry): | |
| entities.append(RachioStandbySwitch(controller)) | ||
| zones = controller.list_zones() | ||
| schedules = controller.list_schedules() | ||
| flex_schedules = controller.list_flex_schedules() | ||
| current_schedule = controller.current_schedule | ||
| for zone in zones: | ||
| _LOGGER.debug("Rachio setting up zone: %s", zone) | ||
| entities.append(RachioZone(person, controller, zone, current_schedule)) | ||
| for sched in schedules: | ||
| _LOGGER.debug("Added schedule: %s", sched) | ||
| for sched in schedules + flex_schedules: | ||
| entities.append(RachioSchedule(person, controller, sched, current_schedule)) | ||
| _LOGGER.debug("Added %s", entities) | ||
| return entities | ||
|
|
||
|
|
||
|
|
@@ -178,7 +179,6 @@ class RachioZone(RachioSwitch): | |
| def __init__(self, person, controller, data, current_schedule): | ||
| """Initialize a new Rachio Zone.""" | ||
| self._id = data[KEY_ID] | ||
| _LOGGER.debug("zone_data: %s", data) | ||
| self._zone_name = data[KEY_NAME] | ||
| self._zone_number = data[KEY_ZONE_NUMBER] | ||
| self._zone_enabled = data[KEY_ENABLED] | ||
|
|
@@ -295,21 +295,16 @@ class RachioSchedule(RachioSwitch): | |
|
|
||
| def __init__(self, person, controller, data, current_schedule): | ||
| """Initialize a new Rachio Schedule.""" | ||
| self._id = data[KEY_ID] | ||
| self._schedule_id = data[KEY_ID] | ||
| self._schedule_name = data[KEY_NAME] | ||
| self._duration = data[KEY_DURATION] | ||
| self._schedule_enabled = data[KEY_ENABLED] | ||
| self._summary = data[KEY_SUMMARY] | ||
| self._current_schedule = current_schedule | ||
| super().__init__(controller, poll=False) | ||
| self._state = self.schedule_id == self._current_schedule.get(KEY_SCHEDULE_ID) | ||
| self._state = self._schedule_id == self._current_schedule.get(KEY_SCHEDULE_ID) | ||
| self._undo_dispatcher = None | ||
|
|
||
| @property | ||
| def schedule_id(self) -> str: | ||
| """How the Rachio API refers to the schedule.""" | ||
| return self._id | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| """Return the friendly name of the schedule.""" | ||
|
|
@@ -318,20 +313,25 @@ def name(self) -> str: | |
| @property | ||
| def unique_id(self) -> str: | ||
| """Return a unique id by combining controller id and schedule.""" | ||
| return f"{self._controller.controller_id}-schedule-{self.schedule_id}" | ||
| return f"{self._controller.controller_id}-schedule-{self._schedule_id}" | ||
|
|
||
| @property | ||
| def icon(self) -> str: | ||
| """Return the icon to display.""" | ||
| return "mdi:water" | ||
|
|
||
| @property | ||
| def duration(self) -> str: | ||
| """Return the duration of each schedule.""" | ||
| return f"{round(self._duration / 60)} minutes" | ||
|
|
||
| @property | ||
| def device_state_attributes(self) -> dict: | ||
| """Return the optional state attributes.""" | ||
| return { | ||
| ATTR_SCHEDULE_SUMMARY: self._summary, | ||
| ATTR_SCHEDULE_ENABLED: self.schedule_is_enabled, | ||
| ATTR_SCHEDULE_DURATION: self._duration / 60, | ||
| ATTR_SCHEDULE_DURATION: self.duration, | ||
| } | ||
|
|
||
| @property | ||
|
|
@@ -342,9 +342,12 @@ def schedule_is_enabled(self) -> bool: | |
| def turn_on(self, **kwargs) -> None: | ||
| """Start this schedule.""" | ||
|
|
||
| self._controller.rachio.schedulerule.start(self.schedule_id) | ||
| self._controller.rachio.schedulerule.start(self._schedule_id) | ||
| _LOGGER.debug( | ||
| "Schedule %s started on %s", self.name, self._controller.name, | ||
| "Schedule %s started on %s for %s", | ||
| self.name, | ||
| self._controller.name, | ||
| self.duration, | ||
|
brg468 marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| def turn_off(self, **kwargs) -> None: | ||
|
|
@@ -354,13 +357,14 @@ def turn_off(self, **kwargs) -> None: | |
| def _poll_update(self, data=None) -> bool: | ||
| """Poll the API to check whether the schedule is running.""" | ||
| self._current_schedule = self._controller.current_schedule | ||
| return self.schedule_id == self._current_schedule.get(KEY_SCHEDULE_ID) | ||
| return self._schedule_id == self._current_schedule.get(KEY_SCHEDULE_ID) | ||
|
|
||
| def _handle_update(self, *args, **kwargs) -> None: | ||
| @callback | ||
| async def _handle_update(self, *args, **kwargs) -> None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A coroutine function can't be a callback.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @MartinHjelmare @brg468 Do you want to do a PR for this?, or I can take care of it needed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had any other changes you were planning go ahead, if not I can do it in a bit.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on fixing something in homekit so you'll probably get to it before I do. |
||
| """Handle incoming webhook schedule data.""" | ||
| # Schedule ID not passed when running individual zones, so we catch that error | ||
| try: | ||
| if args[0][KEY_SCHEDULE_ID] == self.schedule_id: | ||
| if args[0][KEY_SCHEDULE_ID] == self._schedule_id: | ||
| if args[0][KEY_SUBTYPE] in [SUBTYPE_SCHEDULE_STARTED]: | ||
| self._state = True | ||
| elif args[0][KEY_SUBTYPE] in [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.