66
77import java .nio .charset .StandardCharsets ;
88import java .time .Clock ;
9- import java .time .ZonedDateTime ;
9+ import java .time .OffsetDateTime ;
1010import java .time .temporal .ChronoUnit ;
1111import java .util .HashMap ;
1212import java .util .Map ;
@@ -27,10 +27,10 @@ public class VehicleState {
2727 private final IMqttClient client ;
2828 private final String mqttVINPrefix ;
2929 private Supplier <Clock > clockSupplier ;
30- private ZonedDateTime lastCarActivity ;
31- private ZonedDateTime lastSuccessfulRefresh ;
32- private ZonedDateTime lastCarShutdown ;
33- private ZonedDateTime lastVehicleMessage ;
30+ private OffsetDateTime lastCarActivity ;
31+ private OffsetDateTime lastSuccessfulRefresh ;
32+ private OffsetDateTime lastCarShutdown ;
33+ private OffsetDateTime lastVehicleMessage ;
3434 // treat HV battery as active, if we don't have any other information
3535 private boolean hvBatteryActive = true ;
3636 private Long refreshPeriodActive ;
@@ -48,7 +48,7 @@ protected VehicleState(
4848 this .client = client ;
4949 this .mqttVINPrefix = mqttAccountPrefix + "/" + VEHICLES + "/" + vin ;
5050 this .clockSupplier = clockSupplier ;
51- lastCarShutdown = ZonedDateTime .now (clockSupplier .get ());
51+ lastCarShutdown = OffsetDateTime .now (clockSupplier .get ());
5252 }
5353
5454 public String getMqttVINPrefix () {
@@ -373,8 +373,7 @@ public void handleVehicleStatusMessage(
373373 }
374374
375375 msg =
376- new MqttMessage (
377- SaicMqttGateway .toJSON (ZonedDateTime .now (getClock ())).getBytes (StandardCharsets .UTF_8 ));
376+ new MqttMessage (OffsetDateTime .now (getClock ()).toString ().getBytes (StandardCharsets .UTF_8 ));
378377 msg .setQos (0 );
379378 msg .setRetained (true );
380379 client .publish (mqttVINPrefix + "/" + REFRESH_LAST_VEHICLE_STATE , msg );
@@ -466,19 +465,18 @@ public void handleChargeStatusMessage(
466465 client .publish (mqttVINPrefix + "/" + DRIVETRAIN_SOC , msg );
467466
468467 msg =
469- new MqttMessage (
470- SaicMqttGateway .toJSON (ZonedDateTime .now (getClock ())).getBytes (StandardCharsets .UTF_8 ));
468+ new MqttMessage (OffsetDateTime .now (getClock ()).toString ().getBytes (StandardCharsets .UTF_8 ));
471469 msg .setQos (0 );
472470 msg .setRetained (true );
473471 client .publish (mqttVINPrefix + "/" + REFRESH_LAST_CHARGE_STATE , msg );
474472 }
475473
476- public void notifyCarActivityTime (ZonedDateTime now , boolean force ) throws MqttException {
474+ public void notifyCarActivityTime (OffsetDateTime now , boolean force ) throws MqttException {
477475 // if the car activity changed, notify the channel
478476 if (lastCarActivity == null || force || lastCarActivity .isBefore (now )) {
479477 lastCarActivity = now ;
480478 MqttMessage msg =
481- new MqttMessage (SaicMqttGateway . toJSON ( lastCarActivity ).getBytes (StandardCharsets .UTF_8 ));
479+ new MqttMessage (lastCarActivity . toString ( ).getBytes (StandardCharsets .UTF_8 ));
482480 msg .setQos (0 );
483481 msg .setRetained (true );
484482 client .publish (mqttVINPrefix + "/" + REFRESH_LAST_ACTIVITY , msg );
@@ -522,19 +520,19 @@ public boolean shouldRefresh() {
522520 if (hvBatteryActive
523521 || lastCarShutdown
524522 .plus (refreshPeriodAfterShutdown , ChronoUnit .SECONDS )
525- .isAfter (ZonedDateTime .now (getClock ()))) {
523+ .isAfter (OffsetDateTime .now (getClock ()))) {
526524 return lastSuccessfulRefresh .isBefore (
527- ZonedDateTime .now (getClock ()).minus (refreshPeriodActive , ChronoUnit .SECONDS ));
525+ OffsetDateTime .now (getClock ()).minus (refreshPeriodActive , ChronoUnit .SECONDS ));
528526 } else {
529527 return lastSuccessfulRefresh .isBefore (
530- ZonedDateTime .now (getClock ()).minus (refreshPeriodInactive , ChronoUnit .SECONDS ));
528+ OffsetDateTime .now (getClock ()).minus (refreshPeriodInactive , ChronoUnit .SECONDS ));
531529 }
532530 }
533531 }
534532
535533 public void setHVBatteryActive (boolean hvBatteryActive ) throws MqttException {
536534 if (!hvBatteryActive && this .hvBatteryActive ) {
537- this .lastCarShutdown = ZonedDateTime .now (getClock ());
535+ this .lastCarShutdown = OffsetDateTime .now (getClock ());
538536 }
539537 this .hvBatteryActive = hvBatteryActive ;
540538
@@ -545,7 +543,7 @@ public void setHVBatteryActive(boolean hvBatteryActive) throws MqttException {
545543 client .publish (mqttVINPrefix + "/" + DRIVETRAIN_HV_BATTERY_ACTIVE , msg );
546544
547545 if (hvBatteryActive ) {
548- notifyCarActivityTime (ZonedDateTime .now (getClock ()), true );
546+ notifyCarActivityTime (OffsetDateTime .now (getClock ()), true );
549547 }
550548 }
551549
@@ -617,7 +615,7 @@ public RefreshMode getRefreshMode() {
617615 }
618616
619617 public void markSuccessfulRefresh () {
620- this .lastSuccessfulRefresh = ZonedDateTime .now (getClock ());
618+ this .lastSuccessfulRefresh = OffsetDateTime .now (getClock ());
621619 }
622620
623621 public void setRefreshPeriodAfterShutdown (long refreshPeriodAfterShutdown ) {
0 commit comments