Skip to content

Commit

Permalink
feat(mqtt): Optionally expose PetObstacleAvoidance, CarpetModeControl…
Browse files Browse the repository at this point in the history
… and CarpetSensorModeControl capabilities
  • Loading branch information
Hypfer committed Nov 16, 2024
1 parent 8f22341 commit 2cc0ab5
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 2 deletions.
5 changes: 4 additions & 1 deletion backend/lib/doc/Configuration.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@
"TotalStatisticsCapability",
"SpeakerVolumeControlCapability",
"KeyLockCapability",
"ObstacleAvoidanceControlCapability"
"ObstacleAvoidanceControlCapability",
"PetObstacleAvoidanceControlCapability",
"CarpetModeControlCapability",
"CarpetSensorModeControlCapability"
]
}
}
Expand Down
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;
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;
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;
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ class SimpleToggleCapabilityMqttHandle extends CapabilityMqttHandle {
const CAPABILITIES_TO_FRIENDLY_NAME_MAPPING = {
[capabilities.KeyLockCapability.TYPE]: "Lock Keys",
[capabilities.ObstacleAvoidanceControlCapability.TYPE]: "Obstacle Avoidance",
[capabilities.PetObstacleAvoidanceControlCapability.TYPE]: "Pet Obstacle Avoidance",
[capabilities.CarpetModeControlCapability.TYPE]: "Carpet Mode",
};

const CAPABILITIES_TO_ICON_MAPPING = {
[capabilities.KeyLockCapability.TYPE]: "mdi:lock",
[capabilities.ObstacleAvoidanceControlCapability.TYPE]: "mdi:cable-data",
[capabilities.PetObstacleAvoidanceControlCapability.TYPE]: "mdi:paw",
[capabilities.CarpetModeControlCapability.TYPE]: "mdi:access-point",
};

module.exports = SimpleToggleCapabilityMqttHandle;
3 changes: 3 additions & 0 deletions backend/lib/mqtt/capabilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ module.exports = {
AutoEmptyDockManualTriggerCapabilityMqttHandle: require("./AutoEmptyDockManualTriggerCapabilityMqttHandle"),
BasicControlCapabilityMqttHandle: require("./BasicControlCapabilityMqttHandle"),
CapabilityMqttHandle: require("./CapabilityMqttHandle"),
CarpetModeControlCapabilityMqttHandle: require("./CarpetModeControlCapabilityMqttHandle"),
CarpetSensorModeControlCapabilityMqttHandle: require("./CarpetSensorModeControlCapabilityMqttHandle"),
ConsumableMonitoringCapabilityMqttHandle: require("./ConsumableMonitoringCapabilityMqttHandle"),
CurrentStatisticsCapabilityMqttHandle: require("./CurrentStatisticsCapabilityMqttHandle"),
GoToLocationCapabilityMqttHandle: require("./GoToLocationCapabilityMqttHandle"),
KeyLockCapabilityMqttHandle: require("./KeyLockCapabilityMqttHandle"),
LocateCapabilityMqttHandle: require("./LocateCapabilityMqttHandle"),
MapSegmentationCapabilityMqttHandle: require("./MapSegmentationCapabilityMqttHandle"),
ObstacleAvoidanceControlCapabilityMqttHandle: require("./ObstacleAvoidanceControlCapabilityMqttHandle"),
PetObstacleAvoidanceControlCapabilityMqttHandle: require("./PetObstacleAvoidanceControlCapabilityMqttHandle"),
PresetSelectionCapabilityMqttHandle: require("./PresetSelectionCapabilityMqttHandle"),
SpeakerVolumeControlCapabilityMqttHandle: require("./SpeakerVolumeControlCapabilityMqttHandle"),
TotalStatisticsCapabilityMqttHandle: require("./TotalStatisticsCapabilityMqttHandle"),
Expand Down
5 changes: 4 additions & 1 deletion backend/lib/mqtt/handles/HandleMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const CAPABILITY_TYPE_TO_HANDLE_MAPPING = {
[capabilities.TotalStatisticsCapability.TYPE]: capabilityHandles.TotalStatisticsCapabilityMqttHandle,
[capabilities.SpeakerVolumeControlCapability.TYPE]: capabilityHandles.SpeakerVolumeControlCapabilityMqttHandle,
[capabilities.KeyLockCapability.TYPE]: capabilityHandles.KeyLockCapabilityMqttHandle,
[capabilities.ObstacleAvoidanceControlCapability.TYPE]: capabilityHandles.ObstacleAvoidanceControlCapabilityMqttHandle
[capabilities.ObstacleAvoidanceControlCapability.TYPE]: capabilityHandles.ObstacleAvoidanceControlCapabilityMqttHandle,
[capabilities.PetObstacleAvoidanceControlCapability.TYPE]: capabilityHandles.PetObstacleAvoidanceControlCapabilityMqttHandle,
[capabilities.CarpetModeControlCapability.TYPE]: capabilityHandles.CarpetModeControlCapabilityMqttHandle,
[capabilities.CarpetSensorModeControlCapability.TYPE]: capabilityHandles.CarpetSensorModeControlCapabilityMqttHandle,
};

const STATUS_ATTR_TO_HANDLE_MAPPING = [
Expand Down

1 comment on commit 2cc0ab5

@janengelmohr
Copy link

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 :)

Please sign in to comment.