Skip to content

Commit

Permalink
Add climatization and Spin commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Jan 31, 2025
1 parent c683636 commit fbf772d
Show file tree
Hide file tree
Showing 4 changed files with 541 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, session_user, cache, accept_terms_on_login=False, **kwargs):
'application/signed-exchange;v=b3',
'accept-language': 'en-US,en;q=0.9',
'accept-encoding': 'gzip, deflate',
'x-requested-with': 'de.volkswagen.carnet.eu.eremote',
'x-requested-with': 'com.volkswagen.weconnect',
'upgrade-insecure-requests': '1',
})

Expand Down
45 changes: 45 additions & 0 deletions src/carconnectivity_connectors/volkswagen/climatization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Module for charging for skoda vehicles.
"""
from __future__ import annotations
from typing import TYPE_CHECKING

from carconnectivity.climatization import Climatization
from carconnectivity.objects import GenericObject
from carconnectivity.vehicle import ElectricVehicle
from carconnectivity.attributes import BooleanAttribute
from carconnectivity.units import Temperature

if TYPE_CHECKING:
from typing import Optional


class VolkswagenClimatization(Climatization): # pylint: disable=too-many-instance-attributes
"""
VolkswagenClimatization class for handling Volkswagen vehicle climatization information.
This class extends the Climatization class and includes an enumeration of various
climatization states specific to Volkswagen vehicles.
"""
def __init__(self, vehicle: ElectricVehicle | None = None, origin: Optional[Climatization] = None) -> None:
if origin is not None:
super().__init__(origin=origin)
self.settings: Climatization.Settings = VolkswagenClimatization.Settings(origin=origin.settings)
else:
super().__init__(vehicle=vehicle)
self.settings: Climatization.Settings = VolkswagenClimatization.Settings(origin=self.settings)

class Settings(Climatization.Settings):
"""
This class represents the settings for a skoda car climatiation.
"""
def __init__(self, parent: Optional[GenericObject] = None, origin: Optional[Climatization.Settings] = None) -> None:
if origin is not None:
super().__init__(origin=origin)
else:
super().__init__(parent=parent)
self.unit_in_car: Optional[Temperature] = None
self.front_zone_left_enabled: BooleanAttribute = BooleanAttribute(parent=self, name='front_zone_left_enabled')
self.front_zone_right_enabled: BooleanAttribute = BooleanAttribute(parent=self, name='front_zone_right_enabled')
self.rear_zone_left_enabled: BooleanAttribute = BooleanAttribute(parent=self, name='rear_zone_left_enabled')
self.rear_zone_right_enabled: BooleanAttribute = BooleanAttribute(parent=self, name='rear_zone_right_enabled')
72 changes: 72 additions & 0 deletions src/carconnectivity_connectors/volkswagen/command_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""This module defines the classes that represent attributes in the CarConnectivity system."""
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Union

from enum import Enum
import argparse
import logging

from carconnectivity.commands import GenericCommand
from carconnectivity.objects import GenericObject
from carconnectivity.errors import SetterError
from carconnectivity.util import ThrowingArgumentParser

if TYPE_CHECKING:
from carconnectivity.objects import Optional

LOG: logging.Logger = logging.getLogger("carconnectivity.connectors.volkswagen")


class SpinCommand(GenericCommand):
"""
SpinCommand is a command class for verifying the spin
"""
def __init__(self, name: str = 'spin', parent: Optional[GenericObject] = None) -> None:
super().__init__(name=name, parent=parent)

@property
def value(self) -> Optional[Union[str, Dict]]:
return super().value

@value.setter
def value(self, new_value: Optional[Union[str, Dict]]) -> None:
if isinstance(new_value, str):
parser = ThrowingArgumentParser(prog='', add_help=False, exit_on_error=False)
parser.add_argument('command', help='Command to execute', type=SpinCommand.Command,
choices=list(SpinCommand.Command))
parser.add_argument('--spin', dest='spin', help='Spin to be used instead of spin from config or .netrc', type=str, required=False,
default=None)
try:
args = parser.parse_args(new_value.split(sep=' '))
except argparse.ArgumentError as e:
raise SetterError(f'Invalid format for SpinCommand: {e.message} {parser.format_usage()}') from e

newvalue_dict = {}
newvalue_dict['command'] = args.command
if args.spin is not None:
newvalue_dict['spin'] = args.spin
new_value = newvalue_dict
elif isinstance(new_value, dict):
if 'command' in new_value and isinstance(new_value['command'], str):
if new_value['command'] in SpinCommand.Command:
new_value['command'] = SpinCommand.Command(new_value['command'])
else:
raise ValueError('Invalid value for SpinCommand. '
f'Command must be one of {SpinCommand.Command}')
if self._is_changeable:
for hook in self._on_set_hooks:
new_value = hook(self, new_value)
self._set_value(new_value)
else:
raise TypeError('You cannot set this attribute. Attribute is not mutable.')

class Command(Enum):
"""
Enum class representing different commands for SPIN.
"""
VERIFY = 'verify'

def __str__(self) -> str:
return self.value
Loading

0 comments on commit fbf772d

Please sign in to comment.