-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vendor.dreame): Volume Control + Volume Test
- Loading branch information
Showing
10 changed files
with
183 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/robots/dreame/capabilities/DreameSpeakerTestCapability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
73 changes: 73 additions & 0 deletions
73
lib/robots/dreame/capabilities/DreameSpeakerVolumeControlCapability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters