pycupra 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pycupra/__version__.py CHANGED
@@ -3,4 +3,4 @@ pycupra - A Python 3 library for interacting with the My Cupra/My Seat portal.
3
3
 
4
4
  For more details and documentation, visit the github page at https://github.com/WulfgarW/pycupra
5
5
  """
6
- __version__ = "0.0.7"
6
+ __version__ = "0.0.9"
pycupra/connection.py CHANGED
@@ -136,6 +136,10 @@ class Connection:
136
136
  _LOGGER.info(f'Init PyCupra library, version {lib_version}')
137
137
  _LOGGER.debug(f'Using service {self._session_base}')
138
138
 
139
+ self._sessionRequestCounter = 0
140
+ self._sessionRequestTimestamp = datetime.now(tz= None)
141
+ self._sessionRequestCounterHistory = {}
142
+
139
143
 
140
144
  def _clear_cookies(self):
141
145
  self._session._cookie_jar._cookies.clear()
@@ -604,6 +608,19 @@ class Connection:
604
608
  """Perform a HTTP query"""
605
609
  if self._session_fulldebug:
606
610
  _LOGGER.debug(f'HTTP {method} "{url}"')
611
+ try:
612
+ if datetime.now(tz=None).date() != self._sessionRequestTimestamp.date():
613
+ # A new day has begun. Store _sessionRequestCounter in history and reset timestamp and counter
614
+ self._sessionRequestCounterHistory[self._sessionRequestTimestamp.strftime('%Y-%m-%d')]=self._sessionRequestCounter
615
+ _LOGGER.info(f'History of the number of API calls:')
616
+ for key, value in self._sessionRequestCounterHistory.items:
617
+ _LOGGER.info(f' Date: {key}: {value} API calls')
618
+
619
+ self._sessionRequestTimestamp= datetime.now(tz=None)
620
+ self._sessionRequestCounter = 0
621
+ except Exception as e:
622
+ _LOGGER.error(f'Error while preparing output of API call history. Error: {e}')
623
+ self._sessionRequestCounter = self._sessionRequestCounter + 1
607
624
  async with self._session.request(
608
625
  method,
609
626
  url,
pycupra/vehicle.py CHANGED
@@ -74,6 +74,9 @@ class Vehicle:
74
74
  'transactionHistoryHonkFlash': {'active': False, 'reason': 'not supported'},
75
75
  }
76
76
 
77
+ self._last_full_update = datetime.now(tz=None) - timedelta(seconds=1200)
78
+
79
+
77
80
  #### API get and set functions ####
78
81
  # Init and update vehicle data
79
82
  async def discover(self):
@@ -104,7 +107,8 @@ class Vehicle:
104
107
  self._relevantCapabilties[id].update(data)
105
108
 
106
109
 
107
- await self.get_trip_statistic()
110
+ #await self.get_trip_statistic() # in full update
111
+
108
112
  # Get URLs for model image
109
113
  self._modelimages = await self.get_modelimageurl()
110
114
 
@@ -129,10 +133,11 @@ class Vehicle:
129
133
  await asyncio.gather(
130
134
  self.get_charger(),
131
135
  self.get_basiccardata(),
136
+ self.get_statusreport(),
132
137
  return_exceptions=True
133
138
  )
134
139
 
135
- fullUpdateExpired = datetime.now(timezone.utc) - timedelta(seconds= 1100)
140
+ fullUpdateExpired = datetime.now(tz=None) - timedelta(seconds= 1100)
136
141
  if hasattr(self, '_last_full_update'):
137
142
  _LOGGER.debug(f'last_full_update= {self._last_full_update}, fullUpdateExpired= {fullUpdateExpired}.')
138
143
  if updateType!=1 and (hasattr(self, '_last_full_update') and self._last_full_update>fullUpdateExpired):
@@ -143,9 +148,9 @@ class Vehicle:
143
148
  await asyncio.gather(
144
149
  self.get_preheater(),
145
150
  self.get_climater(),
146
- #self.get_trip_statistic(), # commented out, because getting the trip statistic in discover() should be sufficient
151
+ self.get_trip_statistic(),
147
152
  self.get_position(),
148
- self.get_statusreport(),
153
+ self.get_maintenance(),
149
154
  self.get_vehicleHealthWarnings(),
150
155
  self.get_departure_timers(),
151
156
  self.get_departure_profiles(),
@@ -153,8 +158,9 @@ class Vehicle:
153
158
  #self.get_modelimageurl(), #commented out, because getting the images discover() should be sufficient
154
159
  return_exceptions=True
155
160
  )
156
- self._last_full_update = datetime.now(timezone.utc)
161
+ self._last_full_update = datetime.now(tz=None)
157
162
  _LOGGER.debug(f'Performed full update for vehicle with VIN {self.vin}.')
163
+ _LOGGER.debug(f'So far about {self._connection._sessionRequestCounter} API calls since {self._connection._sessionRequestTimestamp}.')
158
164
  except:
159
165
  raise SeatException("Update failed")
160
166
  return True
@@ -247,6 +253,9 @@ class Vehicle:
247
253
  self._states.update(data)
248
254
  else:
249
255
  _LOGGER.debug('Could not fetch status report')
256
+
257
+ async def get_maintenance(self):
258
+ """Fetch maintenance data if function is enabled."""
250
259
  if self._relevantCapabilties.get('vehicleHealthInspection', {}).get('active', False):
251
260
  data = await self._connection.getMaintenance(self.vin, self._apibase)
252
261
  if data:
@@ -1002,7 +1011,25 @@ class Vehicle:
1002
1011
  'status': response.get('state', 'Unknown'),
1003
1012
  'id': response.get('id', 0),
1004
1013
  }
1005
- return True
1014
+ # Update the lock data and check, if they have changed as expected
1015
+ retry = 0
1016
+ actionSuccessful = False
1017
+ while not actionSuccessful and retry < 2:
1018
+ await asyncio.sleep(15)
1019
+ await self.get_statusreport()
1020
+ if action == 'lock':
1021
+ if self.door_locked:
1022
+ actionSuccessful = True
1023
+ else:
1024
+ if not self.door_locked:
1025
+ actionSuccessful = True
1026
+ retry = retry +1
1027
+ if actionSuccessful:
1028
+ _LOGGER.debug('POST request for lock/unlock successful. New status as expected.')
1029
+ self._requests.get('lock', {}).pop('id')
1030
+ return True
1031
+ _LOGGER.error('Response to POST request seemed successful but the lock status did not change as expected.')
1032
+ return False
1006
1033
  except (SeatInvalidRequestException, SeatException):
1007
1034
  raise
1008
1035
  except Exception as error:
@@ -1259,7 +1286,8 @@ class Vehicle:
1259
1286
  @property
1260
1287
  def is_last_full_update_supported(self):
1261
1288
  """Return when last full update for vehicle took place."""
1262
- return True
1289
+ if hasattr(self,'_last_full_update'):
1290
+ return True
1263
1291
 
1264
1292
  # Service information
1265
1293
  @property
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pycupra
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A library to read and send vehicle data via Cupra/Seat portal using the same API calls as the MyCupra/MySeat mobile app.
5
5
  Home-page: https://github.com/WulfgarW/pycupra
6
6
  Author: WulfgarW
@@ -0,0 +1,13 @@
1
+ pycupra/__init__.py,sha256=VPzUfKd5mBFD1UERNV61FbGHih5dQPupLgIfYtmIUi4,230
2
+ pycupra/__version__.py,sha256=4zEieEZtA29wLX4UeSljs9SWOL-1Feo5CB4ZC3aPdrY,207
3
+ pycupra/connection.py,sha256=fNjyrj6nBLOfEpKcygDs47UFlWjmR4tgJa1KPLLNZLU,82411
4
+ pycupra/const.py,sha256=VEYH8TUsJGJwBwloaajwoElYd0qxE7oesvoagvDdE-4,10161
5
+ pycupra/dashboard.py,sha256=Dqs4qDF-rEoYXoS7NrNsvRMsCGzoAjVUEbfTSOdDAXo,41310
6
+ pycupra/exceptions.py,sha256=Nq_F79GP8wjHf5lpvPy9TbSIrRHAJrFMo0T1N9TcgSQ,2917
7
+ pycupra/utilities.py,sha256=cH4MiIzT2WlHgmnl_E7rR0R5LvCXfDNvirJolct50V8,2563
8
+ pycupra/vehicle.py,sha256=Xdd07m-KKDaV7fA4c9hF5ohSg0y_UPoiR8o9ykfJyzE,123464
9
+ pycupra-0.0.9.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
10
+ pycupra-0.0.9.dist-info/METADATA,sha256=vXsQzwLRLEE0qYRyabQPpvAVsokywfRS0UDg3NlC1L4,2578
11
+ pycupra-0.0.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
12
+ pycupra-0.0.9.dist-info/top_level.txt,sha256=9Lbj_jG4JvpGwt6K3AwhWFc0XieDnuHFOP4x44wSXSQ,8
13
+ pycupra-0.0.9.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- pycupra/__init__.py,sha256=VPzUfKd5mBFD1UERNV61FbGHih5dQPupLgIfYtmIUi4,230
2
- pycupra/__version__.py,sha256=sE47EQF8GjjvZy9jhhygnhK2JLO76vFrSBB6HfkoIW4,207
3
- pycupra/connection.py,sha256=LK1v3Eb37lbVKIbQWIjn4xAIAFJqxXwlguX5iq2Ylm8,81393
4
- pycupra/const.py,sha256=VEYH8TUsJGJwBwloaajwoElYd0qxE7oesvoagvDdE-4,10161
5
- pycupra/dashboard.py,sha256=Dqs4qDF-rEoYXoS7NrNsvRMsCGzoAjVUEbfTSOdDAXo,41310
6
- pycupra/exceptions.py,sha256=Nq_F79GP8wjHf5lpvPy9TbSIrRHAJrFMo0T1N9TcgSQ,2917
7
- pycupra/utilities.py,sha256=cH4MiIzT2WlHgmnl_E7rR0R5LvCXfDNvirJolct50V8,2563
8
- pycupra/vehicle.py,sha256=cEg7wG4WX6p4MfShRGZZ955cqvYERI6CmfWSN5NanSQ,122147
9
- pycupra-0.0.7.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
10
- pycupra-0.0.7.dist-info/METADATA,sha256=0W-3PCD7jSDrUtYauZKSzFfSe_dzbTqREQjNxlv28Qo,2578
11
- pycupra-0.0.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
12
- pycupra-0.0.7.dist-info/top_level.txt,sha256=9Lbj_jG4JvpGwt6K3AwhWFc0XieDnuHFOP4x44wSXSQ,8
13
- pycupra-0.0.7.dist-info/RECORD,,