Skip to content

Commit

Permalink
feat(vendor.dreame): Volume Control + Volume Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Feb 9, 2021
1 parent 4a47939 commit 1509be3
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 25 deletions.
2 changes: 1 addition & 1 deletion client/settings-sound-voice.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="left">
<ons-back-button>Settings</ons-back-button>
</div>
<div class="center">Sound Volume & Voice Pack</div>
<div class="center">Sound Volume</div>
<div class="right">
</div>
</ons-toolbar>
Expand Down
40 changes: 29 additions & 11 deletions lib/robots/dreame/DreameD9ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ const MIOT_SERVICES = Object.freeze({
}
}
},
AUDIO: {
SIID: 7,
PROPERTIES: {
VOLUME: {
PIID: 1
}
},
ACTIONS: {
LOCATE: {
AIID: 1
},
VOLUME_TEST: {
AIID: 2
}
}
},
MAIN_BRUSH: {
SIID: 9,
PROPERTIES: {
Expand Down Expand Up @@ -118,15 +134,6 @@ const MIOT_SERVICES = Object.freeze({
}
}
},

LOCATE: {
SIID: 7,
ACTIONS: {
LOCATE: {
AIID: 1
}
}
},
MAP: {
SIID: 6,
PROPERTIES: {
Expand Down Expand Up @@ -216,8 +223,8 @@ class DreameD9ValetudoRobot extends DreameValetudoRobot {

this.registerCapability(new capabilities.DreameLocateCapability({
robot: this,
siid: MIOT_SERVICES.LOCATE.SIID,
aiid: MIOT_SERVICES.LOCATE.ACTIONS.LOCATE.AIID
siid: MIOT_SERVICES.AUDIO.SIID,
aiid: MIOT_SERVICES.AUDIO.ACTIONS.LOCATE.AIID
}));

this.registerCapability(new capabilities.DreameZoneCleaningCapability({
Expand Down Expand Up @@ -308,6 +315,17 @@ class DreameD9ValetudoRobot extends DreameValetudoRobot {
}
});
this.registerCapability(this.consumableMonitoringCapability);

this.registerCapability(new capabilities.DreameSpeakerVolumeControlCapability({
robot: this,
siid: MIOT_SERVICES.AUDIO.SIID,
piid: MIOT_SERVICES.AUDIO.PROPERTIES.VOLUME.PIID
}));
this.registerCapability(new capabilities.DreameSpeakerTestCapability({
robot: this,
siid: MIOT_SERVICES.AUDIO.SIID,
aiid: MIOT_SERVICES.AUDIO.ACTIONS.VOLUME_TEST.AIID
}));
}

onMessage(msg) {
Expand Down
29 changes: 21 additions & 8 deletions lib/robots/dreame/capabilities/DreameBasicControlCapability.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,59 @@ class DreameBasicControlCapability extends BasicControlCapability {
}

async start() {
await this.robot.sendCommand("action",
const res = await this.robot.sendCommand("action",
{
did: this.robot.deviceId,
siid: this.miot_actions.start.siid,
aiid: this.miot_actions.start.aiid,
in: []
}
);
});

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}

async stop() {
await this.robot.sendCommand("action", {
const res = await this.robot.sendCommand("action", {
did: this.robot.deviceId,
siid: this.miot_actions.stop.siid,
aiid: this.miot_actions.stop.aiid,
in: []
});

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
);
}

async pause() {
await this.robot.sendCommand("action", {
const res = await this.robot.sendCommand("action", {
did: this.robot.deviceId,
siid: this.miot_actions.pause.siid,
aiid: this.miot_actions.pause.aiid,
in: []
});

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}

async home() {
await this.robot.sendCommand("action",
const res = await this.robot.sendCommand("action",
{
did: this.robot.deviceId,
siid: this.miot_actions.home.siid,
aiid: this.miot_actions.home.aiid,
in: []
}
);
}

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}
}

module.exports = DreameBasicControlCapability;
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ class DreameFanSpeedControlCapability extends FanSpeedControlCapability {
const matchedPreset = this.presets.find(p => p.name === preset);

if (matchedPreset) {
await this.robot.sendCommand("set_properties", [
const res = await this.robot.sendCommand("set_properties", [
{
did: this.robot.deviceId,
siid: this.siid,
piid: this.piid,
value: matchedPreset.value
}
]);

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
} else {
throw new Error("Invalid Preset");
}
Expand Down
6 changes: 5 additions & 1 deletion lib/robots/dreame/capabilities/DreameLocateCapability.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ class DreameLocateCapability extends LocateCapability {
* @returns {Promise<void>}
*/
async locate() {
await this.robot.sendCommand("action",
const res = await this.robot.sendCommand("action",
{
did: this.robot.deviceId,
siid: this.siid,
aiid: this.aiid
}
);

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DreameMapSegmentationCapability extends MapSegmentationCapability {
];
});

await this.robot.sendCommand("action",
const res = await this.robot.sendCommand("action",
{
did: this.robot.deviceId,
siid: this.miot_actions.start.siid,
Expand All @@ -60,6 +60,10 @@ class DreameMapSegmentationCapability extends MapSegmentationCapability {
]
}
);

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions lib/robots/dreame/capabilities/DreameSpeakerTestCapability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const SpeakerTestCapability = require("../../../core/capabilities/SpeakerTestCapability");

class DreameSpeakerTestCapability extends SpeakerTestCapability {

/**
* @param {object} options
* @param {import("../../../core/ValetudoRobot")|any} options.robot
*
* @param {number} options.siid MIOT Service ID
* @param {number} options.aiid MIOT Action ID
*/
constructor(options) {
super(options);

this.siid = options.siid;
this.aiid = options.aiid;
}

/**
* @returns {Promise<void>}
*/
async playTestSound() {
const res = await this.robot.sendCommand("action", {
did: this.robot.deviceId,
siid: this.siid,
aiid: this.aiid
});

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}

}

module.exports = DreameSpeakerTestCapability;
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const SpeakerVolumeControlCapability = require("../../../core/capabilities/SpeakerVolumeControlCapability");

class DreameSpeakerVolumeControlCapability extends SpeakerVolumeControlCapability {

/**
* @param {object} options
* @param {import("../../../core/ValetudoRobot")|any} options.robot
*
* @param {number} options.siid MIOT Service ID
* @param {number} options.piid MIOT Property ID
*/
constructor(options) {
super(options);

this.siid = options.siid;
this.piid = options.piid;
}


/**
* Returns the current voice volume as percentage
*
* @returns {Promise<number>}
*/
async getVolume() {
const res = await this.robot.sendCommand("get_properties", [
{
did: this.robot.deviceId,
siid: this.siid,
piid: this.piid
}
]);

if (Array.isArray(res) && res.length === 1) {
if (res[0].code === 0) {
return res[0].value;
} else {
throw new Error("Error code " + res[0].code);
}

} else {
throw new Error("Received invalid response");
}
}

/**
* Sets the speaker volume
*
* @param {number} value
* @returns {Promise<void>}
*/
async setVolume(value) {
const res = await this.robot.sendCommand("set_properties", [
{
did: this.robot.deviceId,
siid: this.siid,
piid: this.piid,
value: value
}
]);

if (Array.isArray(res) && res.length === 1) {
if (res[0].code !== 0) {
throw new Error("Error code " + res[0].code);
}
} else {
throw new Error("Received invalid response");
}
}

}

module.exports = DreameSpeakerVolumeControlCapability;
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DreameZoneCleaningCapability extends ZoneCleaningCapability {
]);
});

await this.robot.sendCommand("action",
const res = await this.robot.sendCommand("action",
{
did: this.robot.deviceId,
siid: this.miot_actions.start.siid,
Expand All @@ -71,6 +71,10 @@ class DreameZoneCleaningCapability extends ZoneCleaningCapability {
]
}
);

if (res.code !== 0) {
throw new Error("Error code " + res.code);
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/robots/dreame/capabilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ module.exports = {
DreameZoneCleaningCapability: require("./DreameZoneCleaningCapability"),
DreameMapSegmentationCapability: require("./DreameMapSegmentationCapability"),
DreameCombinedVirtualRestrictionsCapability: require("./DreameCombinedVirtualRestrictionsCapability"),
DreameConsumableMonitoringCapability: require("./DreameConsumableMonitoringCapability")
DreameConsumableMonitoringCapability: require("./DreameConsumableMonitoringCapability"),
DreameSpeakerVolumeControlCapability: require("./DreameSpeakerVolumeControlCapability"),
DreameSpeakerTestCapability: require("./DreameSpeakerTestCapability")
};

0 comments on commit 1509be3

Please sign in to comment.