-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mqtt): Publish ValetudoGoToLocations & ValetudoZonePresets
- Loading branch information
Showing
6 changed files
with
253 additions
and
98 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
67 changes: 67 additions & 0 deletions
67
lib/mqtt/attributeHandlers/capability/GoToLocationCapabilityBasedAttributeMqttHandler.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,67 @@ | ||
const CapabilityBasedAttributeMqttHandler = require("./CapabilityBasedAttributeMqttHandler"); | ||
|
||
class GoToLocationCapabilityBasedAttributeMqttHandler extends CapabilityBasedAttributeMqttHandler { | ||
/** | ||
* @public | ||
* | ||
* @param {object} options | ||
* @param {string} options.topicPrefix | ||
* @param {string} options.autoconfPrefix | ||
* @param {string} options.identifier | ||
* @param {object} options.deviceSpecification | ||
* @param {string} options.availabilityTopic There's only one because there can only be one LWT | ||
*/ | ||
getAutoConfData(options) { | ||
return { | ||
topic: options.autoconfPrefix + "/sensor/" + options.identifier + "/GoToLocationCapability/config", | ||
payload: { | ||
availability_topic: options.availabilityTopic, | ||
device: options.deviceSpecification, | ||
name: "ValetudoGoToLocations", | ||
state_topic: this.getStateTopic({ | ||
topicPrefix: options.topicPrefix, | ||
identifier: options.identifier | ||
}), | ||
unique_id: options.identifier + "_GoToLocationCapability", | ||
icon: "mdi:map-marker-outline", | ||
value_template: "{{value_json.state}}", | ||
json_attributes_topic: this.getStateTopic({ | ||
topicPrefix: options.topicPrefix, | ||
identifier: options.identifier | ||
}), | ||
json_attributes_template: "{{value_json.attributes | to_json}}" | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @public | ||
* | ||
* | ||
* @param {object} options | ||
* @param {string} options.topicPrefix | ||
* @param {string} options.identifier | ||
*/ | ||
getStateTopic(options) { | ||
return options.topicPrefix + "/" + options.identifier + "/GoToLocationCapability/presets"; | ||
} | ||
|
||
/** | ||
* @public | ||
* @abstract | ||
* | ||
* @returns {Promise<Array | boolean | object | number | string>} | ||
*/ | ||
async getPayload() { | ||
const presetsFromConfig = this.capability.robot.config.get("goToLocationPresets") || {}; | ||
|
||
return { | ||
state: Object.keys(presetsFromConfig).length, | ||
attributes: { | ||
presets: presetsFromConfig | ||
} | ||
}; | ||
} | ||
} | ||
|
||
module.exports = GoToLocationCapabilityBasedAttributeMqttHandler; |
67 changes: 67 additions & 0 deletions
67
lib/mqtt/attributeHandlers/capability/ZoneCleaningCapabilityBasedAttributeMqttHandler.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,67 @@ | ||
const CapabilityBasedAttributeMqttHandler = require("./CapabilityBasedAttributeMqttHandler"); | ||
|
||
class ZoneCleaningCapabilityBasedAttributeMqttHandler extends CapabilityBasedAttributeMqttHandler { | ||
/** | ||
* @public | ||
* | ||
* @param {object} options | ||
* @param {string} options.topicPrefix | ||
* @param {string} options.autoconfPrefix | ||
* @param {string} options.identifier | ||
* @param {object} options.deviceSpecification | ||
* @param {string} options.availabilityTopic There's only one because there can only be one LWT | ||
*/ | ||
getAutoConfData(options) { | ||
return { | ||
topic: options.autoconfPrefix + "/sensor/" + options.identifier + "/ZoneCleaningCapability/config", | ||
payload: { | ||
availability_topic: options.availabilityTopic, | ||
device: options.deviceSpecification, | ||
name: "ValetudoZonePresets", | ||
state_topic: this.getStateTopic({ | ||
topicPrefix: options.topicPrefix, | ||
identifier: options.identifier | ||
}), | ||
unique_id: options.identifier + "_ZoneCleaningCapability", | ||
icon: "mdi:square-outline", | ||
value_template: "{{value_json.state}}", | ||
json_attributes_topic: this.getStateTopic({ | ||
topicPrefix: options.topicPrefix, | ||
identifier: options.identifier | ||
}), | ||
json_attributes_template: "{{value_json.attributes | to_json}}" | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @public | ||
* | ||
* | ||
* @param {object} options | ||
* @param {string} options.topicPrefix | ||
* @param {string} options.identifier | ||
*/ | ||
getStateTopic(options) { | ||
return options.topicPrefix + "/" + options.identifier + "/ZoneCleaningCapability/presets"; | ||
} | ||
|
||
/** | ||
* @public | ||
* @abstract | ||
* | ||
* @returns {Promise<Array | boolean | object | number | string>} | ||
*/ | ||
async getPayload() { | ||
const presetsFromConfig = this.capability.robot.config.get("zonePresets") || {}; | ||
|
||
return { | ||
state: Object.keys(presetsFromConfig).length, | ||
attributes: { | ||
presets: presetsFromConfig | ||
} | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ZoneCleaningCapabilityBasedAttributeMqttHandler; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module.exports = { | ||
"WifiConfigurationCapabilityBasedAttributeMqttHandler": require("./WifiConfigurationCapabilityBasedAttributeMqttHandler") | ||
}; | ||
"WifiConfigurationCapabilityBasedAttributeMqttHandler": require("./WifiConfigurationCapabilityBasedAttributeMqttHandler"), | ||
"ZoneCleaningCapabilityBasedAttributeMqttHandler": require("./ZoneCleaningCapabilityBasedAttributeMqttHandler"), | ||
"GoToLocationCapabilityBasedAttributeMqttHandler": require("./GoToLocationCapabilityBasedAttributeMqttHandler") | ||
}; |
Oops, something went wrong.