Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vendor.viomi): Fix consumables and implement reset capability #1367

Merged
merged 1 commit into from Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,31 +26,31 @@ class ViomiConsumableMonitoringCapability extends ConsumableMonitoringCapability
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.MAIN,
remaining: {
value: Math.round(Math.max(0, 360*60 - (rawConsumables.mainBrush / 60))),
value: Math.round(Math.max(0, (360 - rawConsumables.mainBrush) * 60)),
unit: ConsumableStateAttribute.UNITS.MINUTES
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.SIDE_RIGHT,
remaining: {
value: Math.round(Math.max(0, 180*60 - (rawConsumables.sideBrush / 60))),
value: Math.round(Math.max(0, (180 - rawConsumables.sideBrush) * 60)),
unit: ConsumableStateAttribute.UNITS.MINUTES
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.FILTER,
subType: ConsumableStateAttribute.SUB_TYPE.MAIN,
remaining: {
value: Math.round(Math.max(0, 180*60 - (rawConsumables.filter / 60))),
value: Math.round(Math.max(0, (180 - rawConsumables.filter) * 60)),
unit: ConsumableStateAttribute.UNITS.MINUTES
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.MOP, // According to python-miio, unverified
subType: ConsumableStateAttribute.SUB_TYPE.MAIN,
remaining: {
value: Math.round(Math.max(0, 180*60 - (rawConsumables.mop / 60))),
value: Math.round(Math.max(0, (180 - rawConsumables.mop) * 60)),
unit: ConsumableStateAttribute.UNITS.MINUTES
}
}),
Expand All @@ -72,7 +72,40 @@ class ViomiConsumableMonitoringCapability extends ConsumableMonitoringCapability
* @returns {Promise<void>}
*/
async resetConsumable(type, subType) {
throw new Error("Not implemented");
let idx;

switch (type) {
case ConsumableStateAttribute.TYPE.BRUSH:
switch (subType) {
case ConsumableStateAttribute.SUB_TYPE.MAIN:
idx = 1;
break;
case ConsumableStateAttribute.SUB_TYPE.SIDE_RIGHT:
idx = 2;
break;
}
break;
case ConsumableStateAttribute.TYPE.FILTER:
switch (subType) {
case ConsumableStateAttribute.SUB_TYPE.MAIN:
idx = 3;
break;
}
break;
case ConsumableStateAttribute.TYPE.MOP:
switch (subType) {
case ConsumableStateAttribute.SUB_TYPE.MAIN:
idx = 4;
break;
}
break;
}

if (idx) {
await this.robot.sendCommand("set_consumables", [idx, 0], {});
} else {
throw new Error("No such consumable");
}
}

getProperties() {
Expand Down