Skip to content

Commit

Permalink
feat(vendor.roborock): Dock dustbin consumable for all auto-empty docks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Nov 18, 2023
1 parent 46d55c0 commit eebaf7b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 66 deletions.
2 changes: 1 addition & 1 deletion backend/lib/robots/roborock/RoborockG10SValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RoborockG10SValetudoRobot extends RoborockGen4ValetudoRobot {

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
hasUltraDock: true
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.ULTRA
}));

this.registerCapability(new capabilities.RoborockCarpetSensorModeControlCapability({
Expand Down
6 changes: 5 additions & 1 deletion backend/lib/robots/roborock/RoborockQ7MaxValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class RoborockQ7MaxValetudoRobot extends RoborockGen4ValetudoRobot {
})
}));

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.AUTO_EMPTY
}));

[
capabilities.RoborockConsumableMonitoringCapability,
capabilities.RoborockAutoEmptyDockAutoEmptyControlCapability,
capabilities.RoborockAutoEmptyDockManualTriggerCapability,
capabilities.RoborockKeyLockCapability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RoborockS7ProUltraValetudoRobot extends RoborockGen4ValetudoRobot {

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
hasUltraDock: true
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.ULTRA
}));

this.registerCapability(new capabilities.RoborockCarpetSensorModeControlCapability({
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/robots/roborock/RoborockS7ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RoborockS7ValetudoRobot extends RoborockGen4ValetudoRobot {

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
hasDock: true
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.AUTO_EMPTY
}));

[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RoborockS8ProUltraValetudoRobot extends RoborockGen4ValetudoRobot {

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
hasUltraDock: true
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.ULTRA
}));

this.registerCapability(new capabilities.RoborockCarpetSensorModeControlCapability({
Expand Down
6 changes: 5 additions & 1 deletion backend/lib/robots/roborock/RoborockS8ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ class RoborockS8ValetudoRobot extends RoborockGen4ValetudoRobot {
liftModeId: 3
}));

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
dockType: capabilities.RoborockConsumableMonitoringCapability.DOCK_TYPE.AUTO_EMPTY
}));

[
capabilities.RoborockConsumableMonitoringCapability,
capabilities.RoborockAutoEmptyDockAutoEmptyControlCapability,
capabilities.RoborockAutoEmptyDockManualTriggerCapability,
capabilities.RoborockKeyLockCapability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
* @param {object} options
* @param {import("../RoborockValetudoRobot")} options.robot
* @param {boolean} [options.hasUltraDock]
* @param {boolean} [options.hasDock]
* @param {RoborockDockType} [options.dockType]
*/
constructor(options) {
super(options);

this.hasUltraDock = options.hasUltraDock;
this.hasDock = options.hasDock || this. options.hasUltraDock;
this.dockType = options.dockType ?? RoborockConsumableMonitoringCapability.DOCK_TYPE.CHARGING;
}
/**
* This function polls the current consumables state and stores the attributes in our robotState
Expand Down Expand Up @@ -63,38 +63,47 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
}),
];

if (this.hasUltraDock) {
consumables.push(
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].cleaning_brush_work_times, 300),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.FILTER,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].strainer_work_times, 150),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
);
}

if (this.hasDock) {
consumables.push(
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].dust_collection_work_times, 60),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
);
switch (this.dockType) {
case RoborockConsumableMonitoringCapability.DOCK_TYPE.ULTRA:
consumables.push(
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].cleaning_brush_work_times, 300),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.FILTER,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].strainer_work_times, 150),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].dust_collection_work_times, 60),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
);
break;
case RoborockConsumableMonitoringCapability.DOCK_TYPE.AUTO_EMPTY:
consumables.push(
new ConsumableStateAttribute({
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
remaining: {
value: CONVERT_TO_PERCENT_REMAINING(data[0].dust_collection_work_times, 60),
unit: ConsumableStateAttribute.UNITS.PERCENT
}
}),
);
break;
}

consumables.forEach(c => {
Expand Down Expand Up @@ -155,32 +164,38 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
}
];

if (this.hasUltraDock) {
availableConsumables.push(
{
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
{
type: ConsumableStateAttribute.TYPE.FILTER,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
);
}

if (this.hasDock) {
availableConsumables.push(
{
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
);
switch (this.dockType) {
case RoborockConsumableMonitoringCapability.DOCK_TYPE.ULTRA:
availableConsumables.push(
{
type: ConsumableStateAttribute.TYPE.BRUSH,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
{
type: ConsumableStateAttribute.TYPE.FILTER,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
{
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
);
break;
case RoborockConsumableMonitoringCapability.DOCK_TYPE.AUTO_EMPTY:
availableConsumables.push(
{
type: ConsumableStateAttribute.TYPE.BIN,
subType: ConsumableStateAttribute.SUB_TYPE.DOCK,
unit: ConsumableStateAttribute.UNITS.PERCENT,
maxValue: 100
},
);
}

return {
Expand Down Expand Up @@ -215,4 +230,14 @@ const CONSUMABLE_TYPE_MAP = Object.freeze({
}
});

/**
* @typedef {string} RoborockDockType
* @enum {string}
*/
RoborockConsumableMonitoringCapability.DOCK_TYPE = Object.freeze({
ULTRA: "ultra",
AUTO_EMPTY: "auto_empty",
CHARGING: "charging"
});

module.exports = RoborockConsumableMonitoringCapability;

0 comments on commit eebaf7b

Please sign in to comment.