Skip to content

Commit e40fbde

Browse files
committed
[MQTT] never publish force to the refresh/mode to prevent never ending polling
1 parent 43048ec commit e40fbde

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- MQTT
2929
- keep message fetch thread alive after connection failures
3030
- Make sure car state is updated after successful command
31+
- never publish `force` to the `refresh/mode` to prevent never ending polling
3132

3233
### Dependencies
3334
- Bump `version.picocli` from 4.7.3 to 4.7.4 (#29)

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,15 +608,20 @@ public void setRefreshPeriodInactive(long refreshPeriodInactive) {
608608

609609
public void setRefreshMode(RefreshMode refreshMode) {
610610
if (this.refreshMode == null || this.refreshMode != refreshMode) {
611-
612-
MqttMessage mqttMessage =
613-
new MqttMessage(refreshMode.getStringValue().getBytes(StandardCharsets.UTF_8));
614-
try {
615-
LOGGER.info("Setting refresh mode to {}", refreshMode.getStringValue());
616-
mqttMessage.setRetained(true);
617-
this.client.publish(this.mqttVINPrefix + "/" + REFRESH_MODE, mqttMessage);
618-
} catch (MqttException e) {
619-
throw new MqttGatewayException("Error publishing message: " + mqttMessage, e);
611+
LOGGER.info("Setting refresh mode to {}", refreshMode.getStringValue());
612+
613+
if (refreshMode != FORCE) {
614+
// never send force mode to MQTT.
615+
// If we get restarted while force mode is active, the configuration from MQTT
616+
// feature would enable force mode permanently and polling of the car never stops
617+
MqttMessage mqttMessage =
618+
new MqttMessage(refreshMode.getStringValue().getBytes(StandardCharsets.UTF_8));
619+
try {
620+
mqttMessage.setRetained(true);
621+
this.client.publish(this.mqttVINPrefix + "/" + REFRESH_MODE, mqttMessage);
622+
} catch (MqttException e) {
623+
throw new MqttGatewayException("Error publishing message: " + mqttMessage, e);
624+
}
620625
}
621626
}
622627
this.previousRefreshMode = this.refreshMode;

0 commit comments

Comments
 (0)