Skip to content
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 support to get/set a schedule for a zone #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Author: Chris Jewell <[email protected]>
Modified: Gareth Jeanne <[email protected]>
Wolfgang Malgadey <[email protected]>
Wolfgang Malgadey <[email protected]>
Matt Clayton <[email protected]>
68 changes: 68 additions & 0 deletions PyTado/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import urllib.parse
import urllib.error

from enum import IntEnum
from http.cookiejar import CookieJar


Expand All @@ -21,6 +22,12 @@ class Tado:
t.getClimate(1) # Get climate, zone 1.
"""

"""Constants needed for get/set Schedule and Timetable"""
class Timetable(IntEnum):
ONE_DAY = 0
THREE_DAY = 1
SEVEN_DAY = 2

_debugCalls = False

# Instance-wide constant info
Expand Down Expand Up @@ -213,6 +220,67 @@ def getClimate(self, zone):
return {'temperature' : data['insideTemperature']['celsius'],
'humidity' : data['humidity']['percentage']}

def getTimetable(self, zone):
"""Get the Timetable type currently active"""
# pylint: disable=C0103

cmd = 'zones/%i/schedule/activeTimetable' % (zone)

data = self._apiCall(cmd, "GET", {}, True)

if "id" in data:
return Tado.Timetable(data["id"])

raise Exception('Returned data did not contain "id" : '+str(data))

def setTimetable(self, zone, id):
"""Set the Timetable type currently active
id = 0 : ONE_DAY (MONDAY_TO_SUNDAY)
id = 1 : THREE_DAY (MONDAY_TO_FRIDAY, SATURDAY, SUNDAY)
id = 3 : SEVEN_DAY (MONDAY, TUESDAY, WEDNESDAY ...)"""
# pylint: disable=C0103

# Type checking
if not isinstance(id, Tado.Timetable):
raise TypeError('id must be an instance of Tado.Timetable')

cmd = 'zones/%i/schedule/activeTimetable' % (zone)

data = self._apiCall(cmd, "PUT", {'id': id }, True)
return data

def getSchedule(self, zone, id, day=None):
"""Get the JSON representation of the schedule for a zone
a Zone has 3 different schedules, one for each timetable
(see setTimetable) """
# pylint: disable=C0103

# Type checking
if not isinstance(id, Tado.Timetable):
raise TypeError('id must be an instance of Tado.Timetable')

if day:
cmd = 'zones/%i/schedule/timetables/%i/blocks/%s' % (zone,id,day)
else:
cmd = 'zones/%i/schedule/timetables/%i/blocks' % (zone,id)

data = self._apiCall(cmd, "GET", {}, True)
return data


def setSchedule(self, zone, id, day, data):
"""Set the schedule for a zone, day is required"""
# pylint: disable=C0103

# Type checking
if not isinstance(id, Tado.Timetable):
raise TypeError('id must be an instance of Tado.Timetable')

cmd = 'zones/%i/schedule/timetables/%i/blocks/%s' % (zone,id,day)

data = self._apiCall(cmd, "PUT", data, True)
return data

def getWeather(self):
"""Gets outside weather data"""
# pylint: disable=C0103
Expand Down