@@ -26,7 +26,7 @@ public class VehicleState {
2626 private static final Logger LOGGER = LoggerFactory .getLogger (VehicleState .class );
2727 private final IMqttClient client ;
2828 private final String mqttVINPrefix ;
29- private Supplier <Clock > clockSupplier ;
29+ private final Supplier <Clock > clockSupplier ;
3030 private OffsetDateTime lastCarActivity ;
3131 private OffsetDateTime lastSuccessfulRefresh ;
3232 private OffsetDateTime lastCarShutdown ;
@@ -40,7 +40,7 @@ public class VehicleState {
4040 private RefreshMode previousRefreshMode ;
4141
4242 public VehicleState (IMqttClient client , String mqttAccountPrefix , String vin ) {
43- this (client , mqttAccountPrefix , vin , () -> Clock . systemDefaultZone () );
43+ this (client , mqttAccountPrefix , vin , Clock :: systemDefaultZone );
4444 }
4545
4646 protected VehicleState (
@@ -427,6 +427,17 @@ public void handleChargeStatusMessage(
427427 msg .setRetained (true );
428428 client .publish (mqttVINPrefix + "/" + DRIVETRAIN_VOLTAGE , msg );
429429
430+ int remainingChargingTime = 0 ;
431+ if (chargingStatusResponseMessage .getApplicationData ().getChargeStatus ().getChargingGunState ()
432+ && current < 0 ) {
433+ remainingChargingTime =
434+ chargingStatusResponseMessage .getApplicationData ().getChrgngRmnngTime () * 60 ;
435+ }
436+ msg = new MqttMessage ((String .valueOf (remainingChargingTime )).getBytes (StandardCharsets .UTF_8 ));
437+ msg .setQos (0 );
438+ msg .setRetained (true );
439+ client .publish (mqttVINPrefix + "/" + DRIVETRAIN_REMAINING_CHARGING_TIME , msg );
440+
430441 double power = current * voltage / 1000d ;
431442 msg = new MqttMessage ((String .valueOf (power )).getBytes (StandardCharsets .UTF_8 ));
432443 msg .setQos (0 );
@@ -671,23 +682,23 @@ public void configure(String topic, MqttMessage message) {
671682 break ;
672683 case REFRESH_PERIOD_ACTIVE :
673684 try {
674- long value = Long .valueOf (message .toString ());
685+ long value = Long .parseLong (message .toString ());
675686 setRefreshPeriodActive (value );
676687 } catch (NumberFormatException e ) {
677688 throw new MqttGatewayException ("Error setting value for payload: " + message );
678689 }
679690 break ;
680691 case REFRESH_PERIOD_INACTIVE :
681692 try {
682- long value = Long .valueOf (message .toString ());
693+ long value = Long .parseLong (message .toString ());
683694 setRefreshPeriodInactive (value );
684695 } catch (NumberFormatException e ) {
685696 throw new MqttGatewayException ("Error setting value for payload: " + message );
686697 }
687698 break ;
688699 case REFRESH_PERIOD_INACTIVE_GRACE :
689700 try {
690- long value = Long .valueOf (message .toString ());
701+ long value = Long .parseLong (message .toString ());
691702 setRefreshPeriodAfterShutdown (value );
692703 } catch (NumberFormatException e ) {
693704 throw new MqttGatewayException ("Error setting value for payload: " + message );
0 commit comments