[miio] Fix cleaning record for newer vacuums (#15944)

* [miio] Fix cleaning record for newer vacuums

Fixes Roborock Q7Max Historical Cleaning record missing

closing #15490

---------

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2023-11-28 00:10:27 +01:00 committed by GitHub
parent 6e58b1ed22
commit 4d13a6d20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View File

@ -539,7 +539,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
} }
private void updateHistoryRecord(HistoryRecordDTO historyRecordDTO) { private void updateHistoryRecord(HistoryRecordDTO historyRecordDTO) {
JsonObject historyRecord = new JsonObject(); JsonObject historyRecord = GSON.toJsonTree(historyRecordDTO).getAsJsonObject();
if (historyRecordDTO.getStart() != null) { if (historyRecordDTO.getStart() != null) {
historyRecord.addProperty("start", historyRecordDTO.getStart().split("\\+")[0]); historyRecord.addProperty("start", historyRecordDTO.getStart().split("\\+")[0]);
updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(historyRecordDTO.getStart().split("\\+")[0])); updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(historyRecordDTO.getStart().split("\\+")[0]));
@ -703,6 +703,13 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
if (response.getResult().isJsonArray() && response.getResult().getAsJsonArray().size() > 0 if (response.getResult().isJsonArray() && response.getResult().getAsJsonArray().size() > 0
&& response.getResult().getAsJsonArray().get(0).isJsonArray()) { && response.getResult().getAsJsonArray().get(0).isJsonArray()) {
updateHistoryRecordLegacy(response.getResult().getAsJsonArray().get(0).getAsJsonArray()); updateHistoryRecordLegacy(response.getResult().getAsJsonArray().get(0).getAsJsonArray());
} else if (response.getResult().isJsonArray() && response.getResult().getAsJsonArray().size() > 0
&& response.getResult().getAsJsonArray().get(0).isJsonObject()) {
final HistoryRecordDTO historyRecordDTO = GSON.fromJson(
response.getResult().getAsJsonArray().get(0).getAsJsonObject(), HistoryRecordDTO.class);
if (historyRecordDTO != null) {
updateHistoryRecord(historyRecordDTO);
}
} else if (response.getResult().isJsonObject()) { } else if (response.getResult().isJsonObject()) {
final HistoryRecordDTO historyRecordDTO = GSON.fromJson(response.getResult().getAsJsonObject(), final HistoryRecordDTO historyRecordDTO = GSON.fromJson(response.getResult().getAsJsonObject(),
HistoryRecordDTO.class); HistoryRecordDTO.class);
@ -710,7 +717,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
updateHistoryRecord(historyRecordDTO); updateHistoryRecord(historyRecordDTO);
} }
} else { } else {
logger.debug("Could not extract cleaning history record from: {}", response); logger.debug("Could not extract cleaning history record from: {}", response.getResult());
} }
break; break;
case GET_MAP: case GET_MAP:
@ -734,11 +741,9 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
case GET_FW_FEATURES: case GET_FW_FEATURES:
case GET_CUSTOMIZED_CLEAN_MODE: case GET_CUSTOMIZED_CLEAN_MODE:
case GET_MULTI_MAP_LIST: case GET_MULTI_MAP_LIST:
case SET_COLLECT_DUST: case SET_COLLECT_DUST:
case SET_CLEAN_MOP_START: case SET_CLEAN_MOP_START:
case SET_CLEAN_MOP_STOP: case SET_CLEAN_MOP_STOP:
for (RobotCababilities cmd : FEATURES_CHANNELS) { for (RobotCababilities cmd : FEATURES_CHANNELS) {
if (response.getCommand().getCommand().contentEquals(cmd.getCommand())) { if (response.getCommand().getCommand().contentEquals(cmd.getCommand())) {
updateState(cmd.getChannel(), new StringType(response.getResult().toString())); updateState(cmd.getChannel(), new StringType(response.getResult().toString()));

View File

@ -27,6 +27,9 @@ public class HistoryRecordDTO {
@SerializedName("start") @SerializedName("start")
@Expose @Expose
private String start; private String start;
@SerializedName("begin")
@Expose
private String begin;
@SerializedName("end") @SerializedName("end")
@Expose @Expose
private String end; private String end;
@ -45,6 +48,9 @@ public class HistoryRecordDTO {
@SerializedName("finished") @SerializedName("finished")
@Expose @Expose
private Integer finished; private Integer finished;
@SerializedName("complete")
@Expose
private Integer complete;
@SerializedName("start_type") @SerializedName("start_type")
@Expose @Expose
private Integer startType; private Integer startType;
@ -57,9 +63,12 @@ public class HistoryRecordDTO {
@SerializedName("dust_collection_status") @SerializedName("dust_collection_status")
@Expose @Expose
private Integer dustCollectionStatus; private Integer dustCollectionStatus;
@SerializedName("map_flag")
@Expose
private Integer mapFlag;
public final String getStart() { public final String getStart() {
return start; return start != null ? start : begin;
} }
public final void setStart(String start) { public final void setStart(String start) {
@ -107,7 +116,7 @@ public class HistoryRecordDTO {
} }
public final Integer getFinished() { public final Integer getFinished() {
return finished; return finished != null ? finished : complete;
} }
public final void setFinished(Integer finished) { public final void setFinished(Integer finished) {
@ -145,4 +154,12 @@ public class HistoryRecordDTO {
public final void setDustCollectionStatus(Integer dustCollectionStatus) { public final void setDustCollectionStatus(Integer dustCollectionStatus) {
this.dustCollectionStatus = dustCollectionStatus; this.dustCollectionStatus = dustCollectionStatus;
} }
public final Integer getMapFlag() {
return mapFlag;
}
public final void setMapFlag(Integer mapFlag) {
this.mapFlag = mapFlag;
}
} }