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
Co-authored-by: A6blpka <46753414+A6blpka@users.noreply.github.com>
  • Loading branch information
Hypfer and A6blpka authored Nov 18, 2023
1 parent 868bd74 commit dbafa73
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 54 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
6 changes: 5 additions & 1 deletion backend/lib/robots/roborock/RoborockS7ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ class RoborockS7ValetudoRobot extends RoborockGen4ValetudoRobot {
liftModeId: 1
}));

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 @@ -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,11 +11,13 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
* @param {object} options
* @param {import("../RoborockValetudoRobot")} options.robot
* @param {boolean} [options.hasUltraDock]
* @param {RoborockDockType} [options.dockType]
*/
constructor(options) {
super(options);

this.hasUltraDock = 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 @@ -61,33 +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
}
}),
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 @@ -148,27 +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
},
{
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 @@ -203,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 dbafa73

Please sign in to comment.