Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for local API #21

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 52 additions & 104 deletions chargeamps/base.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions chargeamps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
4 changes: 2 additions & 2 deletions chargeamps/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
99 changes: 99 additions & 0 deletions chargeamps/models.py
Original file line number Diff line number Diff line change
@@ -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
Loading