Skip to content

Commit

Permalink
Add additional properties to ConnectivityStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrayner committed Apr 7, 2024
1 parent 1bcca12 commit 9e9775d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* `Client.async_get_connection_status` - @mattrayner
* Add support for charge override deletion:
* Add `Client.async_delete_charge_override` - @mattrayner
* Add `ConnectivityStatus` - @mattrayner

## v1.5.0

Expand Down
65 changes: 65 additions & 0 deletions podpointclient/connectivity_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,71 @@ def dict(self) -> Dict[str, Any]:
"evses": [evse.dict for evse in self.evses]
}

@property
def connectivity_status(self):
"""Return the connectivity status of the first evse"""
evse = self.evses[0]
if evse is None:
return None

connectivity_state = evse.connectivity_state
if connectivity_state is None:
return None

return connectivity_state.connectivity_status

@property
def connectivity_status(self):
"""Return the connectivity status of the first evse"""
evse = self.evses[0]
if evse is None:
return None

connectivity_state = evse.connectivity_state
if connectivity_state is None:
return None

return connectivity_state.connectivity_status

@property
def last_message_at(self):
"""Return the last message at of the first evse"""
evse = self.evses[0]
if evse is None:
return None

connectivity_state = evse.connectivity_state
if connectivity_state is None:
return None

return connectivity_state.last_message_at

@property
def charging_state(self):
"""Return the charging state of the first evse"""
evse = self.evses[0]
if evse is None:
return None

connector = evse.connectors[0]
if connector is None:
return None

return connector.charging_state

@property
def offering_energy(self):
"""Return the offering energy of the first evse"""
evse = self.evses[0]
if evse is None:
return None

energy_offer_status = evse.energy_offer_status
if energy_offer_status is None:
return None

return energy_offer_status.is_offering_energy

def to_json(self):
"""JSON representation of a ConnectivityState object"""
return json.dumps(self.dict, ensure_ascii=False)
2 changes: 1 addition & 1 deletion podpointclient/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version for the podpointclient library"""

__version__ = "1.6.0a1"
__version__ = "1.6.0a2"
8 changes: 8 additions & 0 deletions tests/test_connectivity_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ def test_connectivity_state_to_json(connectivity_state_data):
cs = ConnectivityStatus(connectivity_state_data)
json_data = cs.to_json()
assert isinstance(json_data, str)


def test_connectivity_status_properties(connectivity_state_data):
cs = ConnectivityStatus(connectivity_state_data)
assert cs.connectivity_status == "ONLINE"
assert cs.last_message_at == datetime(2024, 4, 5, 18, 36, 29, tzinfo=timezone.utc)
assert cs.charging_state == "SUSPENDED_EV"
assert cs.offering_energy is True

0 comments on commit 9e9775d

Please sign in to comment.