diff --git a/chargeamps/base.py b/chargeamps/base.py index e1c8795..4f461d1 100644 --- a/chargeamps/base.py +++ b/chargeamps/base.py @@ -1,104 +1,52 @@ -"""Base class and data classes for ChargeAmps API""" - -from abc import ABCMeta -from dataclasses import dataclass -from datetime import datetime -from typing import List, Optional - -from dataclasses_json import LetterCase, dataclass_json - -from .utils import datetime_field - - -class ChargeAmpsClient(metaclass=ABCMeta): # noqa - pass - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargePointConnector: - charge_point_id: str - connector_id: int - type: str - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargePoint: - id: str - name: str - password: str - type: str - is_loadbalanced: bool - firmware_version: str - hardware_version: str - connectors: List[ChargePointConnector] - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargePointMeasurement: - phase: str - current: float - voltage: float - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargePointConnectorStatus: - charge_point_id: str - connector_id: int - total_consumption_kwh: float - status: str - measurements: Optional[List[ChargePointMeasurement]] - start_time: Optional[datetime] = datetime_field() - end_time: Optional[datetime] = datetime_field() - session_id: Optional[str] = None - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargePointStatus: - id: str - status: str - connector_statuses: List[ChargePointConnectorStatus] - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=False) -class ChargePointSettings: - id: str - dimmer: str - down_light: bool - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=False) -class ChargePointConnectorSettings: - charge_point_id: str - connector_id: int - mode: str - rfid_lock: bool - cable_lock: bool - max_current: Optional[float] = None - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class ChargingSession: - id: str - charge_point_id: str - connector_id: int - session_type: str - total_consumption_kwh: float - start_time: Optional[datetime] = datetime_field() - end_time: Optional[datetime] = datetime_field() - - -@dataclass_json(letter_case=LetterCase.CAMEL) -@dataclass(frozen=True) -class StartAuth: - rfid_length: int - rfid_format: str - rfid: str - external_transaction_id: str +"""Base class for ChargeAmps API""" + +from abc import ABCMeta, abstractmethod + +from .models import ( + ChargePoint, + ChargePointConnectorSettings, + ChargePointSettings, + ChargePointStatus, +) + + +class ChargeAmpsClient(metaclass=ABCMeta): + @abstractmethod + async def shutdown(self): + pass + + @abstractmethod + async def get_chargepoints(self) -> list[ChargePoint]: + """Get all owned chargepoints""" + pass + + @abstractmethod + async def get_chargepoint_status(self, charge_point_id: str) -> ChargePointStatus: + """Get charge point status""" + pass + + @abstractmethod + async def get_chargepoint_settings( + self, charge_point_id: str + ) -> ChargePointSettings: + """Get chargepoint settings""" + pass + + @abstractmethod + async def set_chargepoint_settings(self, settings: ChargePointSettings) -> None: + """Set chargepoint settings""" + pass + + @abstractmethod + async def get_chargepoint_connector_settings( + self, charge_point_id: str, connector_id: int + ) -> ChargePointConnectorSettings: + """Get all owned chargepoints""" + pass + + @abstractmethod + async def set_chargepoint_connector_settings( + self, settings: ChargePointConnectorSettings + ) -> None: + """Get all owned chargepoints""" + pass diff --git a/chargeamps/cli.py b/chargeamps/cli.py index 7433ebe..f74ccd7 100644 --- a/chargeamps/cli.py +++ b/chargeamps/cli.py @@ -324,11 +324,7 @@ async def main_loop() -> None: def main() -> None: - loop = asyncio.get_event_loop() - try: - loop.run_until_complete(main_loop()) - finally: - loop.close() + asyncio.run(main_loop()) if __name__ == "__main__": diff --git a/chargeamps/external.py b/chargeamps/external.py index 376a892..f3213d7 100644 --- a/chargeamps/external.py +++ b/chargeamps/external.py @@ -9,8 +9,8 @@ import jwt from aiohttp import ClientResponse, ClientSession -from .base import ( - ChargeAmpsClient, +from .base import ChargeAmpsClient +from .models import ( ChargePoint, ChargePointConnectorSettings, ChargePointSettings, diff --git a/chargeamps/models.py b/chargeamps/models.py new file mode 100644 index 0000000..7744912 --- /dev/null +++ b/chargeamps/models.py @@ -0,0 +1,99 @@ +"""Base class and data classes for ChargeAmps API""" + +from dataclasses import dataclass +from datetime import datetime +from typing import Optional + +from dataclasses_json import LetterCase, dataclass_json + +from .utils import datetime_field + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargePointConnector: + charge_point_id: str + connector_id: int + type: str + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargePoint: + id: str + name: str + password: str + type: str + is_loadbalanced: bool + firmware_version: str + hardware_version: str + connectors: list[ChargePointConnector] + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargePointMeasurement: + phase: str + current: float + voltage: float + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargePointConnectorStatus: + charge_point_id: str + connector_id: int + total_consumption_kwh: float + status: str + measurements: Optional[list[ChargePointMeasurement]] + start_time: Optional[datetime] = datetime_field() + end_time: Optional[datetime] = datetime_field() + session_id: Optional[str] = None + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargePointStatus: + id: str + status: str + connector_statuses: list[ChargePointConnectorStatus] + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=False) +class ChargePointSettings: + id: str + dimmer: str + down_light: bool + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=False) +class ChargePointConnectorSettings: + charge_point_id: str + connector_id: int + mode: str + rfid_lock: bool + cable_lock: bool + max_current: Optional[float] = None + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class ChargingSession: + id: str + charge_point_id: str + connector_id: int + session_type: str + total_consumption_kwh: float + start_time: Optional[datetime] = datetime_field() + end_time: Optional[datetime] = datetime_field() + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass(frozen=True) +class StartAuth: + rfid_length: int + rfid_format: str + rfid: str + external_transaction_id: str