Skip to content

Commit

Permalink
Merge pull request #7 from daernsinstantfortress/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
daernsinstantfortress committed Oct 30, 2023
2 parents 66fdf27 + 142963e commit 479b88a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/access_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
from weconnect_cupra.api.cupra.elements.enums import MaximumChargeCurrent, UnlockPlugState
weConnect = weconnect_cupra.WeConnect(username=args.username, password=args.password,
updateAfterLogin=False, loginOnInit=False,
service=service)
service=service, tokenfile='token.txt')

print('# Login')
weConnect.login()
Expand Down
4 changes: 2 additions & 2 deletions image_extra_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pillow~=9.1.1
ascii_magic~=1.6.0
pillow~=10.0.0
ascii_magic~=2.1.1
2 changes: 1 addition & 1 deletion weconnect_cupra/__version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.50.03'
__version__ = '0.50.05'
26 changes: 25 additions & 1 deletion weconnect_cupra/api/cupra/elements/access_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def update(self, fromDict, ignoreAttributes=None): # noqa: C901
else:
self.doors[doorDict['name']] = AccessStatus.Door(fromDict=doorDict, parent=self.doors)

if 'hood' in fromDict['value']:
doorDict = fromDict['value']['hood']

if 'name' not in doorDict:
doorDict['name'] = 'hood'

if 'name' in doorDict:
if doorDict['name'] in self.doors:
self.doors[doorDict['name']].update(fromDict=doorDict)
else:
self.doors[doorDict['name']] = AccessStatus.Door(fromDict=doorDict, parent=self.doors)

if 'windows' in fromDict['value'] and fromDict['value']['windows'] is not None:
for windowName in fromDict['value']['windows']:

Expand Down Expand Up @@ -141,6 +153,8 @@ def __str__(self):
string += f'\n\tLights: {self.lightsStatus.value.value}'
if self.doorLockStatus is not None and self.doorLockStatus.enabled:
string += f'\n\tDoor locks: {self.doorLockStatus.value.value}'
if self.overallStatus is not None and self.overallStatus.enabled:
string += f'\n\tOverall Status: {self.overallStatus.value.value}'

return string

Expand Down Expand Up @@ -180,7 +194,7 @@ def update(self, fromDict):
AccessControlState.LockState.UNKNOWN, lastUpdateFromCar=None, fromServer=True)
else:
self.lockState.setValueWithCarTime(
AAccessControlState.LockState.UNKNOWN, lastUpdateFromCar=None, fromServer=True)
AccessControlState.LockState.UNKNOWN, lastUpdateFromCar=None, fromServer=True)


if 'open' in fromDict:
Expand All @@ -197,6 +211,16 @@ def update(self, fromDict):
self.openState.setValueWithCarTime(
AccessControlState.OpenState.UNKNOWN, lastUpdateFromCar=None, fromServer=True)

# Fudge because the Cupra Born always returns that the hood is unlocked, so we force it locked
if self.id == 'hood':
if self.openState.value == AccessControlState.OpenState.OPEN:
self.lockState.setValueWithCarTime(
AccessControlState.LockState.UNLOCKED, lastUpdateFromCar=None, fromServer=True)
else:
self.lockState.setValueWithCarTime(
AccessControlState.LockState.LOCKED, lastUpdateFromCar=None, fromServer=True)


for key, value in {key: value for key, value in fromDict.items() if key not in ['locked', 'open', 'name']}.items():
LOG.warning('%s: Unknown attribute %s with value %s', self.getGlobalAddress(), key, value)

Expand Down
4 changes: 2 additions & 2 deletions weconnect_cupra/api/cupra/elements/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __setClimatizationControlChange(self, value): # noqa: C901

# Do API request to set run state
controlResponse = self.vehicle.fetcher.post(
url=f'https://ola.prod.code.seat.cloud.vwgroup.com/vehicles/{self.vehicle.vin.value}/climatisation/requests/{control.value}',
url=f'https://ola.prod.code.seat.cloud.vwgroup.com/v1/vehicles/{self.vehicle.vin.value}/climatisation/requests/{control.value}',
allow_redirects=True,
headers={
"accept": '*/*',
Expand Down Expand Up @@ -156,7 +156,7 @@ def __setChargingControlChange(self, value): # noqa: C901

# Do API request
controlResponse = self.vehicle.fetcher.post(
url=f'https://ola.prod.code.seat.cloud.vwgroup.com/vehicles/{self.vehicle.vin.value}/charging/requests/{value.value}',
url=f'https://ola.prod.code.seat.cloud.vwgroup.com/v1/vehicles/{self.vehicle.vin.value}/charging/requests/{value.value}',
data='{}',
allow_redirects=True,
headers={
Expand Down
2 changes: 1 addition & 1 deletion weconnect_cupra/api/cupra/elements/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False, #
settings_key='odometerStatus')

status_dict = self.fetcher.fetchData(
f'https://ola.prod.code.seat.cloud.vwgroup.com/v1/vehicles/{self.vin.value}/status')
f'https://ola.prod.code.seat.cloud.vwgroup.com/v2/vehicles/{self.vin.value}/status')

self.assign_properties_to_domain(
klass=AccessStatus,
Expand Down
2 changes: 2 additions & 0 deletions weconnect_cupra/elements/generic_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def __str__(self) -> str:
returnString: str = f'[{self.id}]'
if self.carCapturedTimestamp.enabled and self.carCapturedTimestamp.value is not None:
returnString += f' (last captured {self.carCapturedTimestamp.value.isoformat()})'
if self.carCapturedTimestamp.lastUpdateFromServer:
returnString += f' (last updated {self.carCapturedTimestamp.lastUpdateFromServer.isoformat()})'
if self.error.enabled:
returnString += '\n\tError: ' + ''.join(['\t' + line for line in str(self.error).splitlines(True)])
for request in self.requests.values():
Expand Down
51 changes: 36 additions & 15 deletions weconnect_cupra/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@

import shutil

from PIL import Image # type: ignore
import ascii_magic
SUPPORT_IMAGES = False
try:
from PIL import Image # type: ignore
SUPPORT_IMAGES = True
except ImportError:
pass

SUPPORT_ASCII_IMAGES = False
try:
import ascii_magic # type: ignore
SUPPORT_ASCII_IMAGES = True
except ImportError:
pass


def robustTimeParse(timeString: str) -> datetime:
Expand All @@ -32,26 +43,36 @@ def toBool(value: Any) -> bool:
raise ValueError('Not a valid boolean value (True/False)')


def imgToASCIIArt(img: Image, columns: int = 0, mode: ascii_magic.Modes = ascii_magic.Modes.TERMINAL) -> str:
bbox = img.getbbox()
if SUPPORT_ASCII_IMAGES:
class ASCIIModes(Enum):
TERMINAL = 'TERMINAL'
ASCII = 'ASCII'
HTML = 'HTML'

# Crop the image to the contents of the bounding box
image = img.crop(bbox)
def imgToASCIIArt(img: Image, columns: int = 0, mode=ASCIIModes.TERMINAL) -> str:
bbox = img.getbbox()

# Determine the width and height of the cropped image
(width, height) = image.size
# Crop the image to the contents of the bounding box
image = img.crop(bbox)

# Create a new image object for the output image
cropped_image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
# Determine the width and height of the cropped image
(width, height) = image.size

# Paste the cropped image onto the new image
cropped_image.paste(image, (0, 0))
# Create a new image object for the output image
cropped_image = Image.new("RGBA", (width, height), (0, 0, 0, 0))

if columns == 0:
columns = shutil.get_terminal_size()[0]
# Paste the cropped image onto the new image
cropped_image.paste(image, (0, 0))

return ascii_magic.from_image(cropped_image, columns=columns, mode=mode)
if columns == 0:
columns = shutil.get_terminal_size()[0]

if mode == ASCIIModes.ASCII:
return ascii_magic.from_pillow_image(cropped_image).to_ascii(columns=columns, monochrome=True)
if mode == ASCIIModes.HTML:
return ascii_magic.from_pillow_image(cropped_image).to_html(columns=columns)
return ascii_magic.from_pillow_image(cropped_image).to_ascii(columns=columns)


def celsiusToKelvin(value):
return value + 273.15
Expand Down

0 comments on commit 479b88a

Please sign in to comment.