This commit is contained in:
brg468
2020-03-29 16:36:35 -04:00
parent f7f6629200
commit d4d65ae532
2 changed files with 19 additions and 12 deletions

View File

@@ -95,7 +95,11 @@ SUBTYPE_ZONE_CYCLING = "ZONE_CYCLING"
SUBTYPE_ZONE_CYCLING_COMPLETED = "ZONE_CYCLING_COMPLETED" SUBTYPE_ZONE_CYCLING_COMPLETED = "ZONE_CYCLING_COMPLETED"
# Webhook callbacks # Webhook callbacks
LISTEN_EVENT_TYPES = ["DEVICE_STATUS_EVENT", "ZONE_STATUS_EVENT", "SCHEDULE_STATUS_EVENT"] LISTEN_EVENT_TYPES = [
"DEVICE_STATUS_EVENT",
"ZONE_STATUS_EVENT",
"SCHEDULE_STATUS_EVENT",
]
WEBHOOK_CONST_ID = "homeassistant.rachio:" WEBHOOK_CONST_ID = "homeassistant.rachio:"
WEBHOOK_PATH = URL_API + DOMAIN WEBHOOK_PATH = URL_API + DOMAIN
SIGNAL_RACHIO_UPDATE = DOMAIN + "_update" SIGNAL_RACHIO_UPDATE = DOMAIN + "_update"
@@ -297,7 +301,6 @@ class RachioIro:
for event_type in self.rachio.notification.getWebhookEventType()[1]: for event_type in self.rachio.notification.getWebhookEventType()[1]:
if event_type[KEY_NAME] in LISTEN_EVENT_TYPES: if event_type[KEY_NAME] in LISTEN_EVENT_TYPES:
event_types.append({"id": event_type[KEY_ID]}) event_types.append({"id": event_type[KEY_ID]})
# Register to listen to these events from the device # Register to listen to these events from the device
url = self.rachio.webhook_url url = self.rachio.webhook_url
@@ -344,7 +347,7 @@ class RachioIro:
return zone return zone
return None return None
def list_schedules(self) -> list: def list_schedules(self) -> list:
"""Return a list of schedules.""" """Return a list of schedules."""
return self._schedules return self._schedules

View File

@@ -278,6 +278,7 @@ class RachioZone(RachioSwitch):
self.hass, SIGNAL_RACHIO_ZONE_UPDATE, self._handle_update self.hass, SIGNAL_RACHIO_ZONE_UPDATE, self._handle_update
) )
class RachioSchedule(RachioSwitch): class RachioSchedule(RachioSwitch):
"""Representation of one fixed schedule on the Rachio Iro.""" """Representation of one fixed schedule on the Rachio Iro."""
@@ -319,8 +320,11 @@ class RachioSchedule(RachioSwitch):
@property @property
def state_attributes(self) -> dict: def state_attributes(self) -> dict:
"""Return the optional state attributes.""" """Return the optional state attributes."""
return {ATTR_SCHEDULE_SUMMARY: self._summary, ATTR_SCHEDULE_ENABLED: self.schedule_is_enabled, return {
ATTR_SCHEDULE_DURATION: self._duration /60} ATTR_SCHEDULE_SUMMARY: self._summary,
ATTR_SCHEDULE_ENABLED: self.schedule_is_enabled,
ATTR_SCHEDULE_DURATION: self._duration / 60,
}
@property @property
def schedule_is_enabled(self) -> bool: def schedule_is_enabled(self) -> bool:
@@ -329,12 +333,10 @@ class RachioSchedule(RachioSwitch):
def turn_on(self, **kwargs) -> None: def turn_on(self, **kwargs) -> None:
"""Start this schedule.""" """Start this schedule."""
self._controller.rachio.schedulerule.start(self.schedule_id) self._controller.rachio.schedulerule.start(self.schedule_id)
_LOGGER.debug( _LOGGER.debug(
"Schedule %s started on %s", "Schedule %s started on %s", self.name, self._controller.name,
self.name,
self._controller.name,
) )
def turn_off(self, **kwargs) -> None: def turn_off(self, **kwargs) -> None:
@@ -348,12 +350,15 @@ class RachioSchedule(RachioSwitch):
def _handle_update(self, *args, **kwargs) -> None: def _handle_update(self, *args, **kwargs) -> None:
"""Handle incoming webhook schedule data.""" """Handle incoming webhook schedule data."""
#Schedule ID not passed when running indvidual zones, so we catch that error # Schedule ID not passed when running indvidual zones, so we catch that error
try: 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]: if args[0][KEY_SUBTYPE] in [SUBTYPE_SCHEDULE_STARTED]:
self._state = True self._state = True
elif args[0][KEY_SUBTYPE] in [SUBTYPE_SCHEDULE_STOPPED, SUBTYPE_SCHEDULE_COMPLETED]: elif args[0][KEY_SUBTYPE] in [
SUBTYPE_SCHEDULE_STOPPED,
SUBTYPE_SCHEDULE_COMPLETED,
]:
self._state = False self._state = False
except KeyError: except KeyError:
pass pass
@@ -365,4 +370,3 @@ class RachioSchedule(RachioSwitch):
async_dispatcher_connect( async_dispatcher_connect(
self.hass, SIGNAL_RACHIO_SCHEDULE_UPDATE, self._handle_update self.hass, SIGNAL_RACHIO_SCHEDULE_UPDATE, self._handle_update
) )