Skip to content

Commit 67fcf2a

Browse files
author
steinbach
committed
robust against null data in response
1 parent 558a745 commit 67fcf2a

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5-
- no unreleased changes so far
5+
### Fixed
6+
- Make robust against null data in response
67

78
## [0.10.0] - 2021-06-28
89
### Changed

weconnect/elements.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def update( # noqa: C901 # pylint: disable=too-many-branches
9494
else:
9595
self.nickname.enabled = False
9696

97-
if updateCapabilities and 'capabilities' in fromDict:
97+
if updateCapabilities and 'capabilities' in fromDict and fromDict['capabilities'] is not None:
9898
for capDict in fromDict['capabilities']:
9999
if 'id' in capDict:
100100
if capDict['id'] in self.capabilities:
@@ -116,7 +116,7 @@ def update( # noqa: C901 # pylint: disable=too-many-branches
116116
else:
117117
self.images.enabled = False
118118

119-
if 'coUsers' in fromDict:
119+
if 'coUsers' in fromDict and fromDict['coUsers'] is not None:
120120
for user in fromDict['coUsers']:
121121
if 'id' in user:
122122
usersWithId = [x for x in self.coUsers if x.id.value == user['id']]
@@ -721,7 +721,7 @@ def update(self, fromDict, ignoreAttributes=None): # noqa: C901
721721
else:
722722
self.overallStatus.enabled = False
723723

724-
if 'doors' in fromDict:
724+
if 'doors' in fromDict and fromDict['doors'] is not None:
725725
for doorDict in fromDict['doors']:
726726
if 'name' in doorDict:
727727
if doorDict['name'] in self.doors:
@@ -735,7 +735,7 @@ def update(self, fromDict, ignoreAttributes=None): # noqa: C901
735735
self.doors.clear()
736736
self.doors.enabled = False
737737

738-
if 'windows' in fromDict:
738+
if 'windows' in fromDict and fromDict['windows'] is not None:
739739
for windowDict in fromDict['windows']:
740740
if 'name' in windowDict:
741741
if windowDict['name'] in self.windows:
@@ -1430,7 +1430,7 @@ def update(self, fromDict, ignoreAttributes=None):
14301430
ignoreAttributes = ignoreAttributes or []
14311431
LOG.debug('Update window heating status from dict')
14321432

1433-
if 'windowHeatingStatus' in fromDict:
1433+
if 'windowHeatingStatus' in fromDict and fromDict['windowHeatingStatus'] is not None:
14341434
for windowDict in fromDict['windowHeatingStatus']:
14351435
if 'windowLocation' in windowDict:
14361436
if windowDict['windowLocation'] in self.windows:
@@ -1518,7 +1518,7 @@ def update(self, fromDict, ignoreAttributes=None):
15181518
ignoreAttributes = ignoreAttributes or []
15191519
LOG.debug('Update light status from dict')
15201520

1521-
if 'lights' in fromDict:
1521+
if 'lights' in fromDict and fromDict['lights'] is not None:
15221522
for lightDict in fromDict['lights']:
15231523
if 'name' in lightDict:
15241524
if lightDict['name'] in self.lights:
@@ -1729,7 +1729,7 @@ def update(self, fromDict, ignoreAttributes=None):
17291729
ignoreAttributes = ignoreAttributes or []
17301730
LOG.debug('Update capability status from dict')
17311731

1732-
if 'capabilities' in fromDict:
1732+
if 'capabilities' in fromDict and fromDict['capabilities'] is not None:
17331733
for capDict in fromDict['capabilities']:
17341734
if 'id' in capDict:
17351735
if capDict['id'] in self.capabilities:
@@ -1772,7 +1772,7 @@ def update(self, fromDict, ignoreAttributes=None):
17721772
ignoreAttributes = ignoreAttributes or []
17731773
LOG.debug('Update climatization timer from dict')
17741774

1775-
if 'timers' in fromDict:
1775+
if 'timers' in fromDict and fromDict['timers'] is not None:
17761776
for climatizationTimerDict in fromDict['timers']:
17771777
if 'id' in climatizationTimerDict:
17781778
if climatizationTimerDict['id'] in self.timers:
@@ -1889,7 +1889,7 @@ def update(self, fromDict):
18891889
else:
18901890
self.startTime.enabled = False
18911891

1892-
if 'recurringOn' in fromDict:
1892+
if 'recurringOn' in fromDict and fromDict['recurringOn'] is not None:
18931893
for day, state in fromDict['recurringOn'].items():
18941894
if day in self.recurringOn:
18951895
self.recurringOn[day].setValueWithCarTime(state, lastUpdateFromCar=None, fromServer=True)

weconnect/weconnect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__( # noqa: C901
7373
self.__token = {'type': None, 'token': None, 'expires': None}
7474
self.__aToken = {'type': None, 'token': None, 'expires': None}
7575
self.__rToken = {'type': None, 'token': None, 'expires': None}
76-
self.__userId = None
76+
self.__userId = None # pylint: disable=unused-private-member
7777
self.__session = requests.Session()
7878
self.__refreshTimer = None
7979
self.__vehicles = AddressableDict(localAddress='vehicles', parent=self)
@@ -283,7 +283,7 @@ def login(self): # noqa: C901 # pylint: disable=R0914, R0912, too-many-statemen
283283
if 'updated' in params and params['updated'] == 'dataprivacy':
284284
raise AuthentificationError('You have to login at myvolkswagen.de and accept the terms and conditions')
285285
raise APICompatibilityError('No user id provided')
286-
self.__userId = params['userId']
286+
self.__userId = params['userId'] # pylint: disable=unused-private-member
287287

288288
# Now follow the forwarding until forwarding URL starts with 'weconnect://authenticated#'
289289
afterLogingUrl = login3Response.headers['Location']

0 commit comments

Comments
 (0)