Skip to content

Commit faeabfe

Browse files
sfanoussfanous
authored andcommitted
Version 1.3.5
1 parent 0a068ec commit faeabfe

File tree

9 files changed

+796
-637
lines changed

9 files changed

+796
-637
lines changed

HISTORY.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,33 @@
22
33
Release History
44
===============
5-
1.3.0 (2020-04-02)
5+
1.3.5 (2020-04-03)
66
------------------
7+
* Code refactoring and cleanup
78

9+
1.3.0 (2020-04-02)
10+
------------------
811
* Uplift the implementation to include all update to the ecobee API since mid 2017
912

1013
1.2.1 (2017-06-01)
1114
------------------
12-
1315
* Internal __slots__ improvements
1416

1517
1.2.0 (2017-05-31)
1618
------------------
17-
1819
* Internal refactoring of EcobeeObject and EcobeeResponse
1920

2021

2122
1.1.1 (2017-05-31)
2223
------------------
23-
2424
* Miscellaneous minor internal changes to facilitate the automatic generation of PlantUML Class Diagrams
2525

2626

2727
1.1.0 (2017-05-24)
2828
------------------
29-
3029
* Added ecobee API operations that are only accessible by EMS and Utility accounts
3130

3231

3332
1.0.0 (2017-05-12)
3433
------------------
35-
3634
* First public release supporting all ecobee API operations except those that are only accessible by EMS and Utility accounts

pyecobee/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@
9797
from pyecobee.responses import EcobeeThermostatsSummaryResponse
9898
from pyecobee.responses import EcobeeTokensResponse
9999
from pyecobee.service import EcobeeService
100-
from pyecobee.utilities import dictionary_to_object
101-
from pyecobee.utilities import object_to_dictionary
100+
from pyecobee.utilities import Utilities
102101

103102
try: # Python 2.X
104103
from logging import NullHandler

pyecobee/ecobee_object.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44
class EcobeeObject(object):
55
__slots__ = []
66

7-
def slots(self):
8-
return chain.from_iterable(getattr(cls, '__slots__', []) for cls in type(self).__mro__)
7+
attribute_name_map = {}
8+
9+
attribute_type_map = {}
10+
11+
def __repr__(self):
12+
return '{0}('.format(self.__class__.__name__) + ', '.join(
13+
['{0}={1!r}'.format(attribute_name[1:], getattr(self, attribute_name))
14+
for attribute_name in self.slots()]) + ')'
15+
16+
def __str__(self):
17+
return '{0}('.format(self.__class__.__name__) + ', '.join(
18+
['{0}={1!s}'.format(type(self).attribute_name_map[attribute_name[1:]], getattr(self, attribute_name))
19+
for attribute_name in self.slots()]) + ')'
920

1021
def pretty_format(self, indent=2, level=0, sort_attributes=True):
1122
"""
@@ -18,16 +29,20 @@ def pretty_format(self, indent=2, level=0, sort_attributes=True):
1829
"""
1930
pretty_formatted = ['{0}(\n'.format(self.__class__.__name__)]
2031
level = level + 1
32+
2133
for (i, attribute_name) in enumerate(sorted(self.slots()) if sort_attributes else self.slots()):
2234
if i:
2335
pretty_formatted.append(',\n')
36+
2437
if isinstance(getattr(self, attribute_name), list):
2538
pretty_formatted.append('{0}{1}=[\n'.format(' ' * (indent * level),
2639
self.attribute_name_map[attribute_name[1:]]))
2740
level = level + 1
41+
2842
for (j, list_entry) in enumerate(getattr(self, attribute_name)):
2943
if j:
3044
pretty_formatted.append(',\n')
45+
3146
if hasattr(list_entry, 'pretty_format'):
3247
pretty_formatted.append('{0}{1}'.format(' ' * (indent * level),
3348
list_entry.pretty_format(indent,
@@ -36,23 +51,31 @@ def pretty_format(self, indent=2, level=0, sort_attributes=True):
3651
else:
3752
if isinstance(list_entry, list):
3853
pretty_formatted.append('{0}[\n'.format(' ' * (indent * level)))
54+
3955
level = level + 1
56+
4057
for (k, sub_list_entry) in enumerate(list_entry):
4158
if k:
4259
pretty_formatted.append(',\n')
60+
4361
pretty_formatted.append('{0}{1}'.format(' ' * (indent * level), sub_list_entry))
62+
4463
if list_entry:
4564
pretty_formatted.append('\n')
65+
4666
level = level - 1
4767
pretty_formatted.append('{0}]'.format(' ' * (indent * level)))
4868
else:
4969
pretty_formatted.append('{0}{1}'.format(' ' * (indent * level), list_entry))
70+
5071
if getattr(self, attribute_name):
5172
pretty_formatted.append('\n')
73+
5274
level = level - 1
5375
pretty_formatted.append('{0}]'.format(' ' * (indent * level)))
5476
else:
5577
pretty_formatted.append(' ' * (indent * level))
78+
5679
if hasattr(getattr(self, attribute_name), 'pretty_format'):
5780
pretty_formatted.append('{0}={1!s}'.format(self.attribute_name_map[attribute_name[1:]],
5881
getattr(self, attribute_name).pretty_format(
@@ -62,16 +85,11 @@ def pretty_format(self, indent=2, level=0, sort_attributes=True):
6285
else:
6386
pretty_formatted.append('{0}={1!s}'.format(self.attribute_name_map[attribute_name[1:]],
6487
getattr(self, attribute_name)))
88+
6589
level = level - 1
6690
pretty_formatted.append('\n{0})'.format(' ' * (indent * level)))
67-
return ''.join(pretty_formatted)
6891

69-
def __repr__(self):
70-
return '{0}('.format(self.__class__.__name__) + ', '.join(
71-
['{0}={1!r}'.format(attribute_name[1:], getattr(self, attribute_name)) for attribute_name in
72-
self.slots()]) + ')'
92+
return ''.join(pretty_formatted)
7393

74-
def __str__(self):
75-
return '{0}('.format(self.__class__.__name__) + ', '.join(
76-
['{0}={1!s}'.format(type(self).attribute_name_map[attribute_name[1:]], getattr(self, attribute_name)) for
77-
attribute_name in self.slots()]) + ')'
94+
def slots(self):
95+
return chain.from_iterable(getattr(cls, '__slots__', []) for cls in type(self).__mro__)

pyecobee/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def status_message(self):
2020

2121

2222
class EcobeeAuthorizationException(EcobeeException):
23-
attribute_type_map = {'error': 'six.text_type', 'error_description': 'six.text_type', 'error_uri': 'six.text_type'}
23+
attribute_type_map = {'error': 'six.text_type', 'error_description': 'six.text_type',
24+
'error_uri': 'six.text_type'}
2425

2526
def __init__(self, message, error, error_description, error_uri):
2627
super(EcobeeAuthorizationException, self).__init__(message)

pyecobee/responses.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def status(self):
3030
class EcobeeAuthorizeResponse(EcobeeObject):
3131
__slots__ = ['_ecobee_pin', '_code', '_scope', '_expires_in', '_interval']
3232

33-
attribute_name_map = {'ecobee_pin': 'ecobeePin', 'ecobeePin': 'ecobee_pin', 'code': 'code', 'scope': 'scope',
34-
'expires_in': 'expires_in', 'interval': 'interval'}
33+
attribute_name_map = {'ecobee_pin': 'ecobeePin', 'ecobeePin': 'ecobee_pin', 'code': 'code',
34+
'scope': 'scope', 'expires_in': 'expires_in', 'interval': 'interval'}
3535

3636
attribute_type_map = {'ecobee_pin': 'six.text_type', 'code': 'six.text_type', 'scope': 'six.text_type',
3737
'expires_in': 'int', 'interval': 'int'}
@@ -106,8 +106,8 @@ def interval(self):
106106
class EcobeeCreateRuntimeReportJobResponse(EcobeeStatusResponse):
107107
__slots__ = ['_job_id', '_job_status']
108108

109-
attribute_name_map = {'job_id': 'jobId', 'jobId': 'job_id', 'job_status': 'jobStatus', 'jobStatus': 'job_status',
110-
'status': 'status'}
109+
attribute_name_map = {'job_id': 'jobId', 'jobId': 'job_id', 'job_status': 'jobStatus',
110+
'jobStatus': 'job_status', 'status': 'status'}
111111

112112
attribute_type_map = {'job_id': 'six.text_type', 'job_status': 'six.text_type', 'status': 'Status'}
113113

@@ -147,9 +147,11 @@ def job_status(self):
147147
class EcobeeErrorResponse(EcobeeObject):
148148
__slots__ = ['_error', '_error_description', '_error_uri']
149149

150-
attribute_name_map = {'error': 'error', 'error_description': 'error_description', 'error_uri': 'error_uri'}
150+
attribute_name_map = {'error': 'error', 'error_description': 'error_description',
151+
'error_uri': 'error_uri'}
151152

152-
attribute_type_map = {'error': 'six.text_type', 'error_description': 'six.text_type', 'error_uri': 'six.text_type'}
153+
attribute_type_map = {'error': 'six.text_type', 'error_description': 'six.text_type',
154+
'error_uri': 'six.text_type'}
153155

154156
def __init__(self, error, error_description, error_uri):
155157
"""
@@ -225,8 +227,8 @@ def groups(self):
225227
class EcobeeIssueDemandResponsesResponse(EcobeeStatusResponse):
226228
__slots__ = ['_demand_response_ref']
227229

228-
attribute_name_map = {'demand_response_ref': 'demandResponseRef', 'demandResponseRef': 'demand_response_ref',
229-
'status': 'status'}
230+
attribute_name_map = {'demand_response_ref': 'demandResponseRef',
231+
'demandResponseRef': 'demand_response_ref', 'status': 'status'}
230232

231233
attribute_type_map = {'demand_response_ref': 'six.text_type', 'status': 'Status'}
232234

@@ -254,7 +256,8 @@ def demand_response_ref(self):
254256
class EcobeeListDemandResponsesResponse(EcobeeStatusResponse):
255257
__slots__ = ['_demand_response_list']
256258

257-
attribute_name_map = {'demand_response_list': 'drList', 'drList': 'demand_response_list', 'status': 'status'}
259+
attribute_name_map = {'demand_response_list': 'drList', 'drList': 'demand_response_list',
260+
'status': 'status'}
258261

259262
attribute_type_map = {'demand_response_list': 'List[DemandResponse]', 'status': 'Status'}
260263

@@ -408,15 +411,17 @@ class EcobeeRuntimeReportsResponse(EcobeeStatusResponse):
408411
__slots__ = ['_start_date', '_start_interval', '_end_date', '_end_interval', '_columns', '_report_list',
409412
'_sensor_list']
410413

411-
attribute_name_map = {'start_date': 'startDate', 'startDate': 'start_date', 'start_interval': 'startInterval',
412-
'startInterval': 'start_interval', 'end_date': 'endDate', 'endDate': 'end_date',
413-
'end_interval': 'endInterval', 'endInterval': 'end_interval', 'columns': 'columns',
414-
'report_list': 'reportList', 'reportList': 'report_list', 'sensor_list': 'sensorList',
414+
attribute_name_map = {'start_date': 'startDate', 'startDate': 'start_date',
415+
'start_interval': 'startInterval', 'startInterval': 'start_interval',
416+
'end_date': 'endDate', 'endDate': 'end_date', 'end_interval': 'endInterval',
417+
'endInterval': 'end_interval', 'columns': 'columns', 'report_list': 'reportList',
418+
'reportList': 'report_list', 'sensor_list': 'sensorList',
415419
'sensorList': 'sensor_list', 'status': 'status'}
416420

417421
attribute_type_map = {'start_date': 'six.text_type', 'start_interval': 'int', 'end_date': 'six.text_type',
418-
'end_interval': 'int', 'columns': 'six.text_type', 'report_list': 'List[RuntimeReport]',
419-
'sensor_list': 'List[RuntimeSensorReport]', 'status': 'Status'}
422+
'end_interval': 'int', 'columns': 'six.text_type',
423+
'report_list': 'List[RuntimeReport]', 'sensor_list': 'List[RuntimeSensorReport]',
424+
'status': 'Status'}
420425

421426
def __init__(self, start_date, start_interval, end_date, end_interval, columns, report_list, sensor_list, status):
422427
"""
@@ -514,8 +519,8 @@ def sensor_list(self):
514519
class EcobeeThermostatResponse(EcobeeStatusResponse):
515520
__slots__ = ['_page', '_thermostat_list']
516521

517-
attribute_name_map = {'page': 'page', 'thermostat_list': 'thermostatList', 'thermostatList': 'thermostat_list',
518-
'status': 'status'}
522+
attribute_name_map = {'page': 'page', 'thermostat_list': 'thermostatList',
523+
'thermostatList': 'thermostat_list', 'status': 'status'}
519524

520525
attribute_type_map = {'page': 'Page', 'thermostat_list': 'List[Thermostat]', 'status': 'Status'}
521526

@@ -611,8 +616,8 @@ def status_list(self):
611616
class EcobeeTokensResponse(EcobeeObject):
612617
__slots__ = ['_access_token', '_token_type', '_expires_in', '_refresh_token', '_scope']
613618

614-
attribute_name_map = {'access_token': 'access_token', 'token_type': 'token_type', 'expires_in': 'expires_in',
615-
'refresh_token': 'refresh_token', 'scope': 'scope'}
619+
attribute_name_map = {'access_token': 'access_token', 'token_type': 'token_type',
620+
'expires_in': 'expires_in', 'refresh_token': 'refresh_token', 'scope': 'scope'}
616621

617622
attribute_type_map = {'access_token': 'six.text_type', 'token_type': 'six.text_type', 'expires_in': 'int',
618623
'refresh_token': 'six.text_type', 'scope': 'six.text_type'}

0 commit comments

Comments
 (0)