Skip to content

Commit

Permalink
Added change zone schedule ID support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmenchaca committed May 9, 2018
1 parent cdfffc6 commit 8e735cb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions icomfort3-scraper/lcc_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class IComfort3Zone(object):
SET_AWAY_PATH = 'Dashboard/SetAwayMode'
CANCEL_AWAY_PATH = 'Dashboard/CancelAwayMode'
CHANGE_SET_POINT = 'Dashboard/ChangeSetPoint'
MODE_SCHED_PATH = 'ModesSchedules/ModesSchedulesMenu'
CHANGE_ZONE_SCHED = 'ModesSchedules/ChangeZoneScheduleId'

def __init__(self, home_id, lcc_id, zone_id):
# static, pre-configured entries
Expand All @@ -100,6 +102,9 @@ def __init__(self, home_id, lcc_id, zone_id):
('refreshZonedetail', 'False') )
self.hd_url = IC3Session.create_url(IComfort3Zone.HD_REFERER_PATH,
details_referer_query)
mode_sched_query = ( ('zoneId', self.zone_id), ('lccId', self.lcc_id) )
self.ms_url = IC3Session.create_url(IComfort3Zone.MODE_SCHED_PATH,
mode_sched_query)


def __send_update_request(self, session):
Expand Down Expand Up @@ -215,3 +220,30 @@ def change_set_point(self, session, cool, heat):
return self.__parse_update(resp_json)


def change_zone_schedule_id(self, session, schedule_id):
""" Change the current zone Schedule by ID.
"""
session.request_url(self.ms_url, self.hd_url)
payload = [('lccId', self.lcc_id), ('zoneId', self.zone_id),
('scheduleId', schedule_id)]
heads = {}
heads['ADRUM'] = 'isAjax:true'
heads['Accept'] = 'application/json, text/javascript, */*; q=0.01'
heads['Accept-Language'] = 'en-US,en;q=0.9'
heads['Content-Type']='application/x-www-form-urlencoded; charset=UTF-8'
heads['Host'] = 'www.lennoxicomfort.com'
heads['X-Requested-With'] = 'XMLHttpRequest'
change_zs_url = IC3Session.create_url(IComfort3Zone.CHANGE_ZONE_SCHED)
resp = session.post_url(change_zs_url, post_data=payload, headers=heads,
referer_url=self.ms_url)
#print(resp.request.url)
#print(resp.request.headers)
#print(resp.status_code)
#print(resp.text)
resp.raise_for_status
return resp.status_code == 200

def change_system_mode_manual(self, session, schedule_id, period_id, mode):
""" Change to a manually controlled mode rather than a schedule.
"""

34 changes: 34 additions & 0 deletions icomfort3-scraper/test_change_zone_schedule_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python

import secrets
import time
from session import IComfort3Session
from lcc_zone import IComfort3Zone

s = IComfort3Session()
s.login(secrets.icomfort_username, secrets.icomfort_password)
homes = s.fetch_home_zones()

for home in homes:
for (lcc, zone) in homes[home]:
z = IComfort3Zone(home, lcc, zone)
s.set_context(home, lcc, zone)
print ("Home %s, lcc %s, zone %s" % (home, lcc, zone))
update = z.fetch_update(s)
print("Before Change Zone Schedule: %s" % update['ScheduleId'])
change = z.change_zone_schedule_id(s, 1)
after = z.fetch_update(s)
print("After Change Zone Schedule: %s" % update['ScheduleId'])

for home in homes:
for (lcc, zone) in homes[home]:
z = IComfort3Zone(home, lcc, zone)
s.set_context(home, lcc, zone)
print ("Home %s, lcc %s, zone %s" % (home, lcc, zone))
update = z.fetch_update(s)
print("Before Change Zone Schedule: %s" % update['ScheduleId'])
change = z.change_zone_schedule_id(s, 3)
after = z.fetch_update(s)
print("After Change Zone Schedule: %s" % update['ScheduleId'])

s.logout()

0 comments on commit 8e735cb

Please sign in to comment.