Skip to content

Commit 43048ec

Browse files
authored
[MQTT] added topic drivetrain/remainingChargingTime
1 parent 26413f4 commit 43048ec

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- ASN.1 Types for `OTA_ChrgCtrlReq` and `OTA_ChrgCtrlStsResp`
1111
- MQTT
1212
- support starting/stopping charging via setting `drivetrain/charging`
13+
- added topic `drivetrain/remainingChargingTime`
1314

1415
### Changed
1516
- MQTT

saic-java-mqtt-gateway/src/main/java/net/heberling/ismart/mqtt/MqttGatewayTopics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class MqttGatewayTopics {
2828
public static final String DRIVETRAIN_RUNNING = DRIVETRAIN + "/running";
2929
public static final String DRIVETRAIN_SOC = DRIVETRAIN + "/soc";
3030
public static final String DRIVETRAIN_VOLTAGE = DRIVETRAIN + "/voltage";
31+
public static final String DRIVETRAIN_REMAINING_CHARGING_TIME =
32+
DRIVETRAIN + "/remainingChargingTime";
3133
public static final String INFO = "info";
3234
public static final String INFO_CONFIGURATION = INFO + "/configuration";
3335
public static final String INFO_LAST_MESSAGE = INFO + "/lastMessage";

saic-java-mqtt-gateway/src/main/java/net/heberling/ismart/mqtt/VehicleState.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)