mirror of
https://github.com/Hypfer/Valetudo.git
synced 2025-10-26 11:27:27 +00:00
feat(vendor.dreame): DreamePendingMapChangeHandlingCapability
This commit is contained in:
parent
d27e3b1f62
commit
d972121d93
@ -494,6 +494,24 @@ class DreameGen2ValetudoRobot extends DreameValetudoRobot {
|
||||
piid: MIOT_SERVICES.VACUUM_2.PROPERTIES.CARPET_MODE.PIID
|
||||
}));
|
||||
|
||||
this.registerCapability(new capabilities.DreamePendingMapChangeHandlingCapability({
|
||||
robot: this,
|
||||
miot_actions: {
|
||||
map_edit: {
|
||||
siid: MIOT_SERVICES.MAP.SIID,
|
||||
aiid: MIOT_SERVICES.MAP.ACTIONS.EDIT.AIID
|
||||
}
|
||||
},
|
||||
miot_properties: {
|
||||
mapDetails: {
|
||||
piid: MIOT_SERVICES.MAP.PROPERTIES.MAP_DETAILS.PIID
|
||||
},
|
||||
actionResult: {
|
||||
piid: MIOT_SERVICES.MAP.PROPERTIES.ACTION_RESULT.PIID
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
this.state.upsertFirstMatchingAttribute(new entities.state.attributes.AttachmentStateAttribute({
|
||||
type: entities.state.attributes.AttachmentStateAttribute.TYPE.WATERTANK,
|
||||
attached: false
|
||||
|
||||
@ -43,6 +43,7 @@ class DreameMapParser {
|
||||
|
||||
const layers = [];
|
||||
const entities = [];
|
||||
const metaData = {};
|
||||
|
||||
if (parsedHeader.robot_position.valid === true) {
|
||||
entities.push(
|
||||
@ -152,6 +153,10 @@ class DreameMapParser {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (rismResult?.metaData?.dreamePendingMapChange !== undefined) {
|
||||
metaData.dreamePendingMapChange = rismResult.metaData.dreamePendingMapChange;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,12 +226,23 @@ class DreameMapParser {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalData.suw > 0) {
|
||||
/*
|
||||
6 = New Map in Single-map
|
||||
5 = New Map in Multi-map
|
||||
|
||||
other values TBD
|
||||
*/
|
||||
metaData.dreamePendingMapChange = true;
|
||||
}
|
||||
} else {
|
||||
//Just a header
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Map.ValetudoMap({
|
||||
metaData: metaData,
|
||||
size: {
|
||||
x: MAX_X,
|
||||
y: MAX_Y
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
const PendingMapChangeHandlingCapability = require("../../../core/capabilities/PendingMapChangeHandlingCapability");
|
||||
|
||||
|
||||
/**
|
||||
* @extends PendingMapChangeHandlingCapability<import("../DreameValetudoRobot")>
|
||||
*/
|
||||
class DreamePendingMapChangeHandlingCapability extends PendingMapChangeHandlingCapability {
|
||||
/**
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {import("../DreameValetudoRobot")} options.robot
|
||||
*
|
||||
* @param {object} options.miot_actions
|
||||
* @param {object} options.miot_actions.map_edit
|
||||
* @param {number} options.miot_actions.map_edit.siid
|
||||
* @param {number} options.miot_actions.map_edit.aiid
|
||||
*
|
||||
* @param {object} options.miot_properties
|
||||
* @param {object} options.miot_properties.mapDetails
|
||||
* @param {number} options.miot_properties.mapDetails.piid
|
||||
*
|
||||
* @param {object} options.miot_properties.actionResult
|
||||
* @param {number} options.miot_properties.actionResult.piid
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
this.miot_actions = options.miot_actions;
|
||||
this.miot_properties = options.miot_properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async hasPendingChange() {
|
||||
return this.robot?.state?.map?.metaData?.dreamePendingMapChange === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async acceptChange() {
|
||||
return this.commitChoice(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async rejectChange() {
|
||||
return this.commitChoice(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {number} choice
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async commitChoice(choice) {
|
||||
await this.robot.sendCommand("action",
|
||||
{
|
||||
did: this.robot.deviceId,
|
||||
siid: this.miot_actions.map_edit.siid,
|
||||
aiid: this.miot_actions.map_edit.aiid,
|
||||
in: [
|
||||
{
|
||||
piid: this.miot_properties.mapDetails.piid,
|
||||
value: JSON.stringify({cw: choice})
|
||||
}
|
||||
]
|
||||
}
|
||||
).then(res => {
|
||||
if (
|
||||
res && res.siid === this.miot_actions.map_edit.siid &&
|
||||
res.aiid === this.miot_actions.map_edit.aiid &&
|
||||
Array.isArray(res.out) && res.out.length === 1 &&
|
||||
res.out[0].piid === this.miot_properties.actionResult.piid
|
||||
) {
|
||||
switch (res.out[0].value) {
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
throw new Error("Got error " + res.out[0].value + " while committing choice.");
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
this.robot.pollMap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DreamePendingMapChangeHandlingCapability;
|
||||
@ -13,6 +13,7 @@ module.exports = {
|
||||
DreameMapSegmentEditCapability: require("./DreameMapSegmentEditCapability"),
|
||||
DreameMapSegmentRenameCapability: require("./DreameMapSegmentRenameCapability"),
|
||||
DreameMapSegmentationCapability: require("./DreameMapSegmentationCapability"),
|
||||
DreamePendingMapChangeHandlingCapability: require("./DreamePendingMapChangeHandlingCapability"),
|
||||
DreamePersistentMapControlCapability: require("./DreamePersistentMapControlCapability"),
|
||||
DreameSpeakerTestCapability: require("./DreameSpeakerTestCapability"),
|
||||
DreameSpeakerVolumeControlCapability: require("./DreameSpeakerVolumeControlCapability"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user