Skip to content

Commit acf83b0

Browse files
committed
Add a MISSING state for EvChargers in the EVChargerPool
This state is used to indicate that we are missing data from a certain ev charger. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 08d08fd commit acf83b0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/frequenz/sdk/timeseries/ev_charger_pool/_state_tracker.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class EVChargerState(Enum):
2828
"""State of individual ev charger."""
2929

3030
UNSPECIFIED = "UNSPECIFIED"
31+
MISSING = "MISSING"
32+
3133
IDLE = "IDLE"
3234
EV_PLUGGED = "EV_PLUGGED"
3335
EV_LOCKED = "EV_LOCKED"
@@ -43,11 +45,16 @@ def from_ev_charger_data(cls, data: EVChargerData) -> EVChargerState:
4345
Returns:
4446
An `EVChargerState` instance.
4547
"""
48+
if data.component_state == EVChargerComponentState.UNSPECIFIED:
49+
return EVChargerState.UNSPECIFIED
4650
if data.component_state in (
4751
EVChargerComponentState.AUTHORIZATION_REJECTED,
4852
EVChargerComponentState.ERROR,
4953
):
5054
return EVChargerState.ERROR
55+
56+
if data.cable_state == EVChargerCableState.UNSPECIFIED:
57+
return EVChargerState.UNSPECIFIED
5158
if data.cable_state == EVChargerCableState.EV_LOCKED:
5259
return EVChargerState.EV_LOCKED
5360
if data.cable_state == EVChargerCableState.EV_PLUGGED:
@@ -145,12 +152,10 @@ async def _run(self) -> None:
145152
*[api_client.ev_charger_data(cid) for cid in self._component_ids]
146153
)
147154

148-
latest_messages: list[EVChargerData] = await asyncio.gather(
149-
*[stream.receive() for stream in streams]
150-
)
155+
# Start with the `MISSING` state for all components. This will change as data
156+
# starts arriving from the individual components.
151157
self._states = {
152-
msg.component_id: EVChargerState.from_ev_charger_data(msg)
153-
for msg in latest_messages
158+
component_id: EVChargerState.MISSING for component_id in self._component_ids
154159
}
155160
self._merged_stream = Merge(*streams)
156161
sender = self._channel.new_sender()

0 commit comments

Comments
 (0)