-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add charge override deletion and fetching connection status
* Add getting connection status from API: * `Client.async_get_connection_status` - @mattrayner * Add support for charge override deletion: * Add `Client.async_delete_charge_override` - @mattrayner
- Loading branch information
1 parent
135b3b3
commit 015db17
Showing
12 changed files
with
533 additions
and
10 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
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
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
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,166 @@ | ||
"""Connectivity State class, represents a 'Connectivity State' from the podpoint apis""" | ||
|
||
from datetime import datetime, timedelta | ||
from typing import Dict, Any, List | ||
from dataclasses import dataclass, field | ||
from .helpers.functions import lazy_convert_to_datetime, lazy_iso_format_datetime | ||
import json | ||
|
||
# { | ||
# "ppid": "PSL-266056", | ||
# "evses": [{ | ||
# "id": 1, | ||
# "connectivityState": { | ||
# "protocol": "POW", | ||
# "connectivityStatus": "ONLINE", | ||
# "signalStrength": -68, | ||
# "lastMessageAt": "2024-04-05T18:36:29Z", | ||
# "connectionStartedAt": "2024-04-05T18:26:26.819Z", | ||
# "connectionQuality": 3 | ||
# }, | ||
# "connectors": [{ | ||
# "id": 1, | ||
# "door": "A", | ||
# "chargingState": "SUSPENDED_EV" | ||
# }], | ||
# "architecture": "arch3", | ||
# "energyOfferStatus": { | ||
# "isOfferingEnergy": true, | ||
# "reason": "CHARGE_SCHEDULE", | ||
# "until": null, | ||
# "randomDelay": null, | ||
# "doNotCache": false | ||
# } | ||
# }], | ||
# "connectedComponents": ["evses"] | ||
# } | ||
|
||
@dataclass | ||
class Evse: | ||
"""Represents a Location within a charge from pod point""" | ||
|
||
def __init__(self, data: Dict[str, Any]): | ||
self.id: int = data.get('id', None) | ||
self.architecture: str = data.get('architecture', None) | ||
|
||
connectivity_state_data = data.get('connectivityState', {}) | ||
self.connectivity_state = self.ConnectivityState(data=connectivity_state_data) | ||
|
||
connectors_data = data.get('connectors', []) | ||
self.connectors = [] | ||
for connector in connectors_data: | ||
self.connectors.append(self.Connector(data=connector)) | ||
|
||
energy_offer_status_data = data.get('energyOfferStatus', {}) | ||
self.energy_offer_status = self.EnergyOfferStatus(data=energy_offer_status_data) | ||
|
||
@property | ||
def dict(self): | ||
return { | ||
"id": self.id, | ||
"architecture": self.architecture, | ||
"connectivityState": self.connectivity_state.dict, | ||
"connectors": [connector.dict for connector in self.connectors], | ||
"energyOfferStatus": self.energy_offer_status.dict | ||
} | ||
|
||
def to_json(self): | ||
"""JSON representation of a ConnectivityState object""" | ||
return json.dumps(self.dict, ensure_ascii=False) | ||
|
||
@dataclass | ||
class ConnectivityState: | ||
"""Represents a Location within a charge from pod point""" | ||
|
||
def __init__(self, data: Dict[str, Any]): | ||
self.protocol: str = data.get('protocol', None) | ||
self.connectivity_status: str = data.get('connectivityStatus', None) | ||
self.signal_strength:int = data.get('signalStrength', None) | ||
self.last_message_at: datetime = lazy_convert_to_datetime(data.get('lastMessageAt', None)) | ||
self.connection_started_at: datetime = lazy_convert_to_datetime(data.get('connectionStartedAt', None)) | ||
self.connection_quality: int = data.get('connectionQuality', None) | ||
|
||
@property | ||
def dict(self): | ||
return { | ||
"protocol": self.protocol, | ||
"connectivityStatus": self.connectivity_status, | ||
"signalStrength": self.signal_strength, | ||
"lastMessageAt": lazy_iso_format_datetime(self.last_message_at), | ||
"connectionStartedAt": lazy_iso_format_datetime(self.connection_started_at), | ||
"connectionQuality": self.connection_quality | ||
} | ||
|
||
def to_json(self): | ||
"""JSON representation of a ConnectivityState object""" | ||
return json.dumps(self.dict, ensure_ascii=False) | ||
|
||
@dataclass | ||
class Connector: | ||
"""Represents a Location within a charge from pod point""" | ||
|
||
def __init__(self, data: Dict[str, Any]): | ||
self.id: int = data.get('id', None) | ||
self.door: str = data.get('door', None) | ||
self.charging_state: str = data.get('chargingState', None) | ||
|
||
@property | ||
def dict(self): | ||
return { | ||
"id": self.id, | ||
"door": self.door, | ||
"chargingState": self.charging_state | ||
} | ||
|
||
def to_json(self): | ||
"""JSON representation of a ConnectivityState object""" | ||
return json.dumps(self.dict, ensure_ascii=False) | ||
|
||
@dataclass | ||
class EnergyOfferStatus: | ||
"""Represents a Location within a charge from pod point""" | ||
|
||
def __init__(self, data: Dict[str, Any]): | ||
self.is_offering_energy: bool = data.get('isOfferingEnergy', None) | ||
self.reason: str = data.get('reason', None) | ||
self.until: datetime = lazy_convert_to_datetime(data.get('until', None)) | ||
self.random_delay = data.get('randomDelay', None) | ||
self.do_not_cache: bool = data.get('doNotCache', None) | ||
|
||
@property | ||
def dict(self): | ||
return { | ||
"isOfferingEnergy": self.is_offering_energy, | ||
"reason": self.reason, | ||
"until": lazy_iso_format_datetime(self.until), | ||
"randomDelay": self.random_delay, | ||
"doNotCache": self.do_not_cache | ||
} | ||
|
||
def to_json(self): | ||
"""JSON representation of a ConnectivityState object""" | ||
return json.dumps(self.dict, ensure_ascii=False) | ||
|
||
|
||
class ConnectivityStatus: | ||
"""Representation of a Connectivity State from pod point""" | ||
|
||
def __init__(self, data: Dict[str, Any]): | ||
self.ppid: int = data.get('ppid', None) | ||
self.connected_components: List[str] = data.get('connectedComponents', []) | ||
|
||
self.evses: List[Evse] = [] | ||
for evse in data.get('evses', []): | ||
self.evses.append(Evse(data=evse)) | ||
|
||
@property | ||
def dict(self) -> Dict[str, Any]: | ||
return { | ||
"ppid": self.ppid, | ||
"connected_components": self.connected_components, | ||
"evses": [evse.dict for evse in self.evses] | ||
} | ||
|
||
def to_json(self): | ||
"""JSON representation of a ConnectivityState object""" | ||
return json.dumps(self.dict, ensure_ascii=False) |
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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Version for the podpointclient library""" | ||
|
||
__version__ = "1.5.0" | ||
__version__ = "1.6.0a1" |
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,28 @@ | ||
{ | ||
"ppid": "PSL-123456", | ||
"evses": [{ | ||
"id": 1, | ||
"connectivityState": { | ||
"protocol": "POW", | ||
"connectivityStatus": "ONLINE", | ||
"signalStrength": -68, | ||
"lastMessageAt": "2024-04-05T18:26:28Z", | ||
"connectionStartedAt": "2024-04-05T18:26:26.819Z", | ||
"connectionQuality": 3 | ||
}, | ||
"connectors": [{ | ||
"id": 1, | ||
"door": "A", | ||
"chargingState": "SUSPENDED_EV" | ||
}], | ||
"architecture": "arch3", | ||
"energyOfferStatus": { | ||
"isOfferingEnergy": true, | ||
"reason": "CHARGE_SCHEDULE", | ||
"until": null, | ||
"randomDelay": null, | ||
"doNotCache": false | ||
} | ||
}], | ||
"connectedComponents": ["evses"] | ||
} |
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
Oops, something went wrong.