carconnectivity-connector-seatcupra 0.1a2__py3-none-any.whl → 0.1a3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: carconnectivity-connector-seatcupra
3
- Version: 0.1a2
3
+ Version: 0.1a3
4
4
  Summary: CarConnectivity connector for Seat and Cupra services
5
5
  Author: Till Steinbach
6
6
  License: MIT License
@@ -1,8 +1,8 @@
1
1
  carconnectivity_connectors/seatcupra/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- carconnectivity_connectors/seatcupra/_version.py,sha256=Ef3bGV58pr38At7Z3T5w6O9Yfnm9fPuFoS1_rJQZJLs,508
2
+ carconnectivity_connectors/seatcupra/_version.py,sha256=xpGveoYLp11VothNw4ctnawA60va2R4V5tLdgWtxWZ0,508
3
3
  carconnectivity_connectors/seatcupra/capability.py,sha256=Oe9tC_u69bj6VmOuNJ21RKoETe2j3QyZCoz-VgcZPQ0,4523
4
4
  carconnectivity_connectors/seatcupra/charging.py,sha256=kcCJJddZxUXFoayYMpq3lzdnrPp5yexnGBfDB-zQrmE,3336
5
- carconnectivity_connectors/seatcupra/connector.py,sha256=0M_gF9QiKQoiOUwRbFXcoOvVZCS4VrxT65W90l6KZV0,61402
5
+ carconnectivity_connectors/seatcupra/connector.py,sha256=U4j5fCJYfVCb_5aBDp9m2F8swDL3Vz63CW-jrtIWiSw,66248
6
6
  carconnectivity_connectors/seatcupra/vehicle.py,sha256=O6_JNTSwl82EZIix_DNf8eTj4A1rxPwTO1IeN3daAR8,3233
7
7
  carconnectivity_connectors/seatcupra/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  carconnectivity_connectors/seatcupra/auth/auth_util.py,sha256=Y81h8fGOMSMgPtE4wI_TI9WgE_s43uaPjRLBBINhj4g,4433
@@ -12,8 +12,8 @@ carconnectivity_connectors/seatcupra/auth/session_manager.py,sha256=NizIuY-pvkVB
12
12
  carconnectivity_connectors/seatcupra/auth/vw_web_session.py,sha256=hgsCdXugVnSgvLta4hBNtoNgMhAA83paAYO2fUOOFyM,10657
13
13
  carconnectivity_connectors/seatcupra/auth/helpers/blacklist_retry.py,sha256=f3wsiY5bpHDBxp7Va1Mv9nKJ4u3qnCHZZmDu78_AhMk,1251
14
14
  carconnectivity_connectors/seatcupra/ui/connector_ui.py,sha256=SNYnlcGJpbWhuLiIHD2l6H9IfSiMz3IgmvXsdossDnE,1412
15
- carconnectivity_connector_seatcupra-0.1a2.dist-info/LICENSE,sha256=PIwI1alwDyOfvEQHdGCm2u9uf_mGE8030xZDfun0xTo,1071
16
- carconnectivity_connector_seatcupra-0.1a2.dist-info/METADATA,sha256=7gAeWjXp1y-KkPw1JemIM1ncGwsPNuYzaHpWP6WPsDc,5386
17
- carconnectivity_connector_seatcupra-0.1a2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
18
- carconnectivity_connector_seatcupra-0.1a2.dist-info/top_level.txt,sha256=KqA8GviZsDH4PtmnwSQsz0HB_w-TWkeEHLIRNo5dTaI,27
19
- carconnectivity_connector_seatcupra-0.1a2.dist-info/RECORD,,
15
+ carconnectivity_connector_seatcupra-0.1a3.dist-info/LICENSE,sha256=PIwI1alwDyOfvEQHdGCm2u9uf_mGE8030xZDfun0xTo,1071
16
+ carconnectivity_connector_seatcupra-0.1a3.dist-info/METADATA,sha256=JuFFjlEF1M3633J-O80Mi-anX0iHHznBaBLuZTBWkbo,5386
17
+ carconnectivity_connector_seatcupra-0.1a3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
18
+ carconnectivity_connector_seatcupra-0.1a3.dist-info/top_level.txt,sha256=KqA8GviZsDH4PtmnwSQsz0HB_w-TWkeEHLIRNo5dTaI,27
19
+ carconnectivity_connector_seatcupra-0.1a3.dist-info/RECORD,,
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.1a2'
20
+ __version__ = version = '0.1a3'
21
21
  __version_tuple__ = version_tuple = (0, 1)
@@ -365,6 +365,8 @@ class Connector(BaseConnector):
365
365
  vehicle.climatization.commands.add_command(climatisation_start_stop_command)
366
366
  else:
367
367
  vehicle.capabilities.clear_capabilities()
368
+ if isinstance(vehicle, SeatCupraVehicle):
369
+ vehicle = self.fetch_image(vehicle)
368
370
  else:
369
371
  raise APIError('Could not fetch vehicle data, VIN missing')
370
372
  for vin in set(garage.list_vehicle_vins()) - seen_vehicle_vins:
@@ -794,6 +796,61 @@ class Connector(BaseConnector):
794
796
  print(data)
795
797
  return vehicle
796
798
 
799
+ def fetch_image(self, vehicle: SeatCupraVehicle, no_cache: bool = False) -> SeatCupraVehicle:
800
+ if SUPPORT_IMAGES:
801
+ url: str = f'https://ola.prod.code.seat.cloud.vwgroup.com/v1/vehicles/{vehicle.vin.value}/renders'
802
+ data = self._fetch_data(url, session=self.session, allow_http_error=True)
803
+ if data is not None: # pylint: disable=too-many-nested-blocks
804
+ for image_id, image_url in data.items():
805
+ if image_id == 'isDefault':
806
+ continue
807
+ img = None
808
+ cache_date = None
809
+ if self.active_config['max_age'] is not None and self.session.cache is not None and image_url in self.session.cache:
810
+ img, cache_date_string = self.session.cache[image_url]
811
+ img = base64.b64decode(img) # pyright: ignore[reportPossiblyUnboundVariable]
812
+ img = Image.open(io.BytesIO(img)) # pyright: ignore[reportPossiblyUnboundVariable]
813
+ cache_date = datetime.fromisoformat(cache_date_string)
814
+ if img is None or self.active_config['max_age'] is None \
815
+ or (cache_date is not None and cache_date < (datetime.utcnow() - timedelta(seconds=self.active_config['max_age']))):
816
+ try:
817
+ image_download_response = requests.get(image_url, stream=True)
818
+ if image_download_response.status_code == requests.codes['ok']:
819
+ img = Image.open(image_download_response.raw) # pyright: ignore[reportPossiblyUnboundVariable]
820
+ if self.session.cache is not None:
821
+ buffered = io.BytesIO() # pyright: ignore[reportPossiblyUnboundVariable]
822
+ img.save(buffered, format="PNG")
823
+ img_str = base64.b64encode(buffered.getvalue()).decode("utf-8") # pyright: ignore[reportPossiblyUnboundVariable]
824
+ self.session.cache[image_url] = (img_str, str(datetime.utcnow()))
825
+ elif image_download_response.status_code == requests.codes['unauthorized']:
826
+ LOG.info('Server asks for new authorization')
827
+ self.session.login()
828
+ image_download_response = self.session.get(image_url, stream=True)
829
+ if image_download_response.status_code == requests.codes['ok']:
830
+ img = Image.open(image_download_response.raw) # pyright: ignore[reportPossiblyUnboundVariable]
831
+ if self.session.cache is not None:
832
+ buffered = io.BytesIO() # pyright: ignore[reportPossiblyUnboundVariable]
833
+ img.save(buffered, format="PNG")
834
+ img_str = base64.b64encode(buffered.getvalue()).decode("utf-8") # pyright: ignore[reportPossiblyUnboundVariable]
835
+ self.session.cache[image_url] = (img_str, str(datetime.utcnow()))
836
+ except requests.exceptions.ConnectionError as connection_error:
837
+ raise RetrievalError(f'Connection error: {connection_error}') from connection_error
838
+ except requests.exceptions.ChunkedEncodingError as chunked_encoding_error:
839
+ raise RetrievalError(f'Error: {chunked_encoding_error}') from chunked_encoding_error
840
+ except requests.exceptions.ReadTimeout as timeout_error:
841
+ raise RetrievalError(f'Timeout during read: {timeout_error}') from timeout_error
842
+ except requests.exceptions.RetryError as retry_error:
843
+ raise RetrievalError(f'Retrying failed: {retry_error}') from retry_error
844
+ if img is not None:
845
+ vehicle._car_images[image_id] = img # pylint: disable=protected-access
846
+ if image_id == 'side':
847
+ if 'car_picture' in vehicle.images.images:
848
+ vehicle.images.images['car_picture']._set_value(img) # pylint: disable=protected-access
849
+ else:
850
+ vehicle.images.images['car_picture'] = ImageAttribute(name="car_picture", parent=vehicle.images,
851
+ value=img, tags={'carconnectivity'})
852
+ return vehicle
853
+
797
854
  def _record_elapsed(self, elapsed: timedelta) -> None:
798
855
  """
799
856
  Records the elapsed time.