Skip to content

Commit

Permalink
feat(vendor.dreame): D9 error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jan 30, 2021
1 parent e986687 commit 669f192
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 16 deletions.
58 changes: 45 additions & 13 deletions lib/robots/dreame/DreameD9ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class DreameD9ValetudoRobot extends DreameValetudoRobot {

this.lastMapPoll = new Date(0);

this.mode = 0; //Idle
this.errorCode = "0";
this.stateNeedsUpdate = false;

this.registerCapability(new capabilities.DreameBasicControlCapability({
robot: this,
miot_actions: {
Expand Down Expand Up @@ -399,21 +403,15 @@ class DreameD9ValetudoRobot extends DreameValetudoRobot {
case MIOT_SERVICES.VACUUM_2.SIID: {
switch (elem.piid) {
case MIOT_SERVICES.VACUUM_2.PROPERTIES.MODE.PIID: {
let statusValue = DreameValetudoRobot.STATUS_MAP[elem.value].value;
let statusFlag = DreameValetudoRobot.STATUS_MAP[elem.value].flag;
let statusMetaData = {};

const newState = new stateAttrs.StatusStateAttribute({
value: statusValue,
flag: statusFlag,
metaData: statusMetaData
});
this.mode = elem.value;

this.state.upsertFirstMatchingAttribute(newState);
this.stateNeedsUpdate = true;
break;
}
case MIOT_SERVICES.VACUUM_2.PROPERTIES.ERROR_CODE.PIID: {
this.errorCode = elem.value;

if (newState.isActiveState) {
this.pollMap();
}
this.stateNeedsUpdate = true;
break;
}
case MIOT_SERVICES.VACUUM_2.PROPERTIES.FAN_SPEED.PIID: {
Expand Down Expand Up @@ -454,6 +452,40 @@ class DreameD9ValetudoRobot extends DreameValetudoRobot {
}
});


if (this.stateNeedsUpdate === true) {
let newState;
let statusValue;
let statusFlag;
let statusMetaData = {};

if (this.errorCode === "0") {
statusValue = DreameValetudoRobot.STATUS_MAP[this.mode].value;
statusFlag = DreameValetudoRobot.STATUS_MAP[this.mode].flag;
} else {
statusValue = stateAttrs.StatusStateAttribute.VALUE.ERROR;

statusMetaData.error_code = this.errorCode;
statusMetaData.error_description = DreameValetudoRobot.GET_ERROR_CODE_DESCRIPTION(this.errorCode);
}

newState = new stateAttrs.StatusStateAttribute({
value: statusValue,
flag: statusFlag,
metaData: statusMetaData
});

this.state.upsertFirstMatchingAttribute(newState);

if (newState.isActiveState) {
this.pollMap();
}

this.stateNeedsUpdate = false;
}



this.emitStateUpdated();
}

Expand Down
55 changes: 55 additions & 0 deletions lib/robots/dreame/DreameValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,60 @@ DreameValetudoRobot.FAN_SPEEDS = {
[stateAttrs.IntensityStateAttribute.VALUE.MAX]: 3
};

//TODO: Refactor to something like ValetudoErrorCodes
DreameValetudoRobot.ERROR_CODES = {
"0": "No error",
"1": "Wheel lost floor contact. Robot is on the verge of falling",
"2": "Obstacle sensor dirty",
"3": "Stuck front bumper",
"4": "Tilted robot",
"5": "Stuck front bumper",
"6": "Wheel lost floor contact. Robot is on the verge of falling",
"7": "Internal error",
"8": "Dustbin missing",
"11": "Filter jammed",
"12": "Main brush jammed",
"13": "Side brush jammed",
"14": "Filter jammed",
"15": "Robot stuck or trapped",
"16": "Robot stuck or trapped",
"17": "Robot stuck or trapped",
"18": "Robot stuck or trapped",
"20": "Low battery",
"21": "Charging error",
"23": "Internal error",
"24": "Camera dirty",
"25": "Internal error",
"26": "Camera dirty",
"28": "Charging station without power",
"29": "Battery temperature out of operating range",
"30": "Internal error",
"31": "Robot stuck or trapped",
"32": "Robot stuck or trapped",
"33": "Internal error",
"34": "Internal error",
"35": "Internal error",
"36": "Internal error",
"37": "Internal error",
"38": "Internal error",
"39": "Internal error",
"40": "Internal error",
"41": "Magnetic interference",
"47": "Cannot reach target",
"48": "LDS jammed",
"49": "LDS bumper jammed",
"51": "Filter jammed",
"54": "Wall sensor dirty",
"-2": "Stuck inside restricted area"
};

DreameValetudoRobot.GET_ERROR_CODE_DESCRIPTION = (errorCodeId) => {
if (DreameValetudoRobot.ERROR_CODES[errorCodeId] !== undefined) {
return DreameValetudoRobot.ERROR_CODES[errorCodeId];
} else {
return "UNKNOWN ERROR CODE " + errorCodeId;
}
};


module.exports = DreameValetudoRobot;
6 changes: 3 additions & 3 deletions lib/robots/roborock/RoborockValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ const ERROR_CODES = {
17: "Side brush error. Reboot required",
18: "Fan error. Reboot required",
19: "Charging station without power",
21: "LDS cover error",
21: "LDS bumper jammed",
22: "Charging contacts dirty",
23: "Charging station dirty",
24: "Stuck inside restricted zone",
24: "Stuck inside restricted area",
25: "Camera dirty",
26: "Wall sensor dirty",
29: "Animal excrements detected"
Expand All @@ -416,7 +416,7 @@ const GET_ERROR_CODE_DESCRIPTION = (errorCodeId) => {
if (ERROR_CODES[errorCodeId] !== undefined) {
return ERROR_CODES[errorCodeId];
} else {
return "UNKNOWN ERROR CODE";
return "UNKNOWN ERROR CODE " + errorCodeId;
}
};

Expand Down

0 comments on commit 669f192

Please sign in to comment.