Skip to content

Commit

Permalink
Add charging-complete ServiceEvent
Browse files Browse the repository at this point in the history
and new state `chargePurposeReachedAndConservation`.

Fixes skodaconnect/homeassistant-myskoda#253
  • Loading branch information
dvx76 committed Nov 13, 2024
1 parent 6d1f7f3 commit e1e37b2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
9 changes: 6 additions & 3 deletions myskoda/models/service_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
class ServiceEventName(StrEnum):
"""List of known Service EventNames."""

CHANGE_SOC = "change-soc"
CHANGE_ACCESS = "change-access"
CHANGE_CHARGE_MODE = "change-charge-mode"
CHANGE_LIGHTS = "change-lights"
CLIMATISATION_COMPLETED = "climatisation-completed"
CHANGE_REMAINING_TIME = "change-remaining-time"
CHANGE_CHARGE_MODE = "change-charge-mode"
CHANGE_SOC = "change-soc"
CHARGING_COMPLETED = "charging-completed"
CHARGING_STATUS_CHANGED = "charging-status-changed"
CLIMATISATION_COMPLETED = "climatisation-completed"


@dataclass
Expand Down Expand Up @@ -75,6 +76,8 @@ def _deserialize_charging_state(value: str) -> ChargingState:
match value:
case "charging":
return ChargingState.CHARGING
case "chargePurposeReachedAndConservation":
return ChargingState.CONSERVING
case "chargePurposeReachedAndNotConservationCharging":
return ChargingState.READY_FOR_CHARGING
case "notReadyForCharging":
Expand Down
42 changes: 42 additions & 0 deletions tests/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ async def test_subscribe_event(
}
),
),
(
f"{base_topic}/service-event/charging",
json.dumps(
{
"version": 1,
"traceId": trace_id,
"timestamp": timestamp_str,
"producer": "SKODA_MHUB",
"name": "charging-completed",
"data": {
"mode": "manual",
"state": "chargePurposeReachedAndConservation",
"soc": "100",
"chargedRange": "500",
"timeToFinish": "0",
"userId": USER_ID,
"vin": VIN,
},
}
),
),
]

def on_event(event: Event) -> None:
Expand Down Expand Up @@ -210,4 +231,25 @@ def on_event(event: Event) -> None:
),
),
),
EventCharging(
vin=VIN,
user_id=USER_ID,
timestamp=ANY,
event=ServiceEventCharging(
version=1,
trace_id=trace_id,
timestamp=timestamp,
producer="SKODA_MHUB",
name=ServiceEventName.CHARGING_COMPLETED,
data=ServiceEventChargingData(
user_id=USER_ID,
vin=VIN,
charged_range=500,
soc=100,
state=ChargingState.CONSERVING,
mode=ChargeMode.MANUAL,
time_to_finish=0,
),
),
),
]

0 comments on commit e1e37b2

Please sign in to comment.