-
-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mqtt): Optionally expose PetObstacleAvoidance, CarpetModeControl…
… and CarpetSensorModeControl capabilities
- Loading branch information
Showing
7 changed files
with
101 additions
and
2 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
8 changes: 8 additions & 0 deletions
8
backend/lib/mqtt/capabilities/CarpetModeControlCapabilityMqttHandle.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,8 @@ | ||
const SimpleToggleCapabilityMqttHandle = require("./SimpleToggleCapabilityMqttHandle"); | ||
|
||
|
||
class CarpetModeControlCapabilityMqttHandle extends SimpleToggleCapabilityMqttHandle {} | ||
|
||
CarpetModeControlCapabilityMqttHandle.OPTIONAL = true; | ||
|
||
module.exports = CarpetModeControlCapabilityMqttHandle; |
70 changes: 70 additions & 0 deletions
70
backend/lib/mqtt/capabilities/CarpetSensorModeControlCapabilityMqttHandle.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,70 @@ | ||
const CapabilityMqttHandle = require("./CapabilityMqttHandle"); | ||
|
||
const ComponentType = require("../homeassistant/ComponentType"); | ||
const DataType = require("../homie/DataType"); | ||
const EntityCategory = require("../homeassistant/EntityCategory"); | ||
const InLineHassComponent = require("../homeassistant/components/InLineHassComponent"); | ||
const PropertyMqttHandle = require("../handles/PropertyMqttHandle"); | ||
|
||
class CarpetSensorModeControlCapabilityMqttHandle extends CapabilityMqttHandle { | ||
/** | ||
* @param {object} options | ||
* @param {import("../handles/RobotMqttHandle")} options.parent | ||
* @param {import("../MqttController")} options.controller MqttController instance | ||
* @param {import("../../core/ValetudoRobot")} options.robot | ||
* @param {import("../../core/capabilities/CarpetSensorModeControlCapability")} options.capability | ||
*/ | ||
constructor(options) { | ||
super(Object.assign(options, { | ||
friendlyName: "Carpet Sensor Mode" | ||
})); | ||
this.capability = options.capability; | ||
|
||
this.registerChild( | ||
new PropertyMqttHandle({ | ||
parent: this, | ||
controller: this.controller, | ||
topicName: "mode", | ||
friendlyName: "Carpet Sensor Mode", | ||
datatype: DataType.ENUM, | ||
format: this.capability.getProperties().supportedModes.join(","), | ||
setter: async (value) => { | ||
await this.capability.setMode(value); | ||
}, | ||
getter: async () => { | ||
return await this.capability.getMode(); | ||
}, | ||
helpText: "This handle allows setting the Carpet Sensor Mode. " + | ||
"It accepts the preset payloads specified in `$format` or in the HAss json attributes.", | ||
helpMayChange: { | ||
"Enum payloads": "Different robot models have different Carpet Sensor Modes. " + | ||
"Always check `$format`/`json_attributes` during startup." | ||
} | ||
}).also((prop) => { | ||
this.controller.withHass((hass) => { | ||
prop.attachHomeAssistantComponent( | ||
new InLineHassComponent({ | ||
hass: hass, | ||
robot: this.robot, | ||
name: this.capability.getType(), | ||
friendlyName: "Carpet Sensor Mode", | ||
componentType: ComponentType.SELECT, | ||
autoconf: { | ||
state_topic: prop.getBaseTopic(), | ||
value_template: "{{ value }}", | ||
command_topic: prop.getBaseTopic() + "/set", | ||
options: this.capability.getProperties().supportedModes, | ||
icon: "mdi:waves", | ||
entity_category: EntityCategory.CONFIG, | ||
} | ||
}) | ||
); | ||
}); | ||
}) | ||
); | ||
} | ||
} | ||
|
||
CarpetSensorModeControlCapabilityMqttHandle.OPTIONAL = true; | ||
|
||
module.exports = CarpetSensorModeControlCapabilityMqttHandle; |
8 changes: 8 additions & 0 deletions
8
backend/lib/mqtt/capabilities/PetObstacleAvoidanceControlCapabilityMqttHandle.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,8 @@ | ||
const SimpleToggleCapabilityMqttHandle = require("./SimpleToggleCapabilityMqttHandle"); | ||
|
||
|
||
class PetObstacleAvoidanceControlCapabilityMqttHandle extends SimpleToggleCapabilityMqttHandle {} | ||
|
||
PetObstacleAvoidanceControlCapabilityMqttHandle.OPTIONAL = true; | ||
|
||
module.exports = PetObstacleAvoidanceControlCapabilityMqttHandle; |
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
2cc0ab5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! Now my home automation routine can finally be completed without nasty hacks :)