-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c683636
commit fbf772d
Showing
4 changed files
with
541 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/carconnectivity_connectors/volkswagen/climatization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.