Skip to content

Commit

Permalink
add charging plug objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Jan 11, 2025
1 parent 389c750 commit 1385837
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/carconnectivity/charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from carconnectivity.objects import GenericObject
from carconnectivity.attributes import DateAttribute, EnumAttribute, SpeedAttribute, PowerAttribute
from carconnectivity.charging_connector import ChargingConnector

if TYPE_CHECKING:
from typing import Optional
Expand All @@ -23,6 +24,7 @@ def __init__(self, vehicle: Optional[ElectricVehicle] = None) -> None:
raise ValueError('Cannot create charging without vehicle')
super().__init__(object_id='charging', parent=vehicle)
self.delay_notifications = True
self.connector: ChargingConnector = ChargingConnector(charging=self)
self.state: EnumAttribute = EnumAttribute("state", parent=self)
self.type: EnumAttribute = EnumAttribute("type", parent=self)
self.rate: SpeedAttribute = SpeedAttribute("rate", parent=self)
Expand Down
91 changes: 91 additions & 0 deletions src/carconnectivity/charging_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
Module for connector.
"""
from __future__ import annotations
from typing import TYPE_CHECKING

from enum import Enum

from carconnectivity.objects import GenericObject
from carconnectivity.attributes import EnumAttribute
if TYPE_CHECKING:
from typing import Optional
from carconnectivity.charging import Charging


class ChargingConnector(GenericObject): # pylint: disable=too-many-instance-attributes
"""
A class to represent the charging connector of a vehicle.
"""
def __init__(self, charging: Optional[Charging] = None) -> None:
if charging is None:
raise ValueError('Cannot create connector without charging')
super().__init__(object_id='connector', parent=charging)
self.delay_notifications = True
self.connection_state: EnumAttribute = EnumAttribute("connection_state", parent=self)
self.lock_state: EnumAttribute = EnumAttribute("lock_state", parent=self)
self.external_power: EnumAttribute = EnumAttribute("lock_state", parent=self)
self.delay_notifications = False

def __str__(self) -> str:
return_string: str = 'Connector:\n'
if self.connection_state.enabled and self.connection_state.value is not None:
return_string += f'Connection State: {self.connection_state.value.value}\n'
if self.lock_state.enabled and self.lock_state.value is not None:
return_string += f'Lock State: {self.lock_state.value.value}\n'
if self.external_power.enabled and self.external_power.value is not None:
return_string += f'External Power: {self.external_power.value.value}\n'
return return_string

class ChargingConnectorConnectionState(Enum,):
"""
Enum representing the connection state of the connector.
Attributes:
CONNECTED (str): The connector is connected.
DISCONNECTED (str): The connector is disconnected.
INVALID (str): The connector state is invalid.
UNSUPPORTED (str): The connector state is unsupported.
UNKNOWN (str): The connector state is unknown.
"""
CONNECTED = 'connected'
DISCONNECTED = 'disconnected'
INVALID = 'invalid'
UNSUPPORTED = 'unsupported'
UNKNOWN = 'unknown unlock plug state'

class ChargingConnectorLockState(Enum,):
"""
Enum representing the lock state of a plug.
Attributes:
LOCKED (str): The plug is locked.
UNLOCKED (str): The plug is unlocked.
INVALID (str): The plug state is invalid.
UNSUPPORTED (str): The plug state is unsupported.
UNKNOWN (str): The plug state is unknown.
"""
LOCKED = 'locked'
UNLOCKED = 'unlocked'
INVALID = 'invalid'
UNSUPPORTED = 'unsupported'
UNKNOWN = 'unknown unlock plug state'

class ExternalPower(Enum,):
"""
Enum representing the state of external power.
Attributes:
AVAILABLE (str): External power is available.
ACTIVE (str): External power is used.
UNAVAILABLE (str): External power is unavailable.
INVALID (str): External power state is invalid.
UNSUPPORTED (str): External power is unsupported.
UNKNOWN (str): External power state is unknown.
"""
AVAILABLE = 'available'
ACTIVE = 'active'
UNAVAILABLE = 'unavailable'
INVALID = 'invalid'
UNSUPPORTED = 'unsupported'
UNKNOWN = 'unknown external power'

0 comments on commit 1385837

Please sign in to comment.