Merge pull request #199 from faanskit/develop
Fix scene device triggers
This commit is contained in:
commit
8f15042a58
2 changed files with 12 additions and 3 deletions
|
|
@ -36,7 +36,7 @@ const getTopicName = (
|
|||
) => `${getBaseTopic(uniqueId, mqttDeviceType)}/${topicType}`;
|
||||
|
||||
const getButtonEventTopic = (/** @type {string} */ deviceId) => `${getTopicName(deviceId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trigger`;
|
||||
const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trig`;
|
||||
const getSceneEventTopic = (/** @type {string} */ sceneId) => `${getTopicName(getTriggerUniqueId(sceneId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`;
|
||||
|
||||
|
|
@ -110,13 +110,13 @@ const getSceneDeviceTriggerhDiscoveryPayload = (
|
|||
/** @type {import('./types/DeviceRegistry').OutputDevice} */ sceneDevice,
|
||||
) => ({
|
||||
automation_type: 'trigger',
|
||||
'~': getBaseTopic(sceneDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION),
|
||||
'~': getBaseTopic(`${sceneDevice.uniqueId}_trig`, MQTT_TYPES.DEVICE_AUTOMATION),
|
||||
qos: 1,
|
||||
topic: `~/${TOPIC_TYPES.STATE}`,
|
||||
type: 'scene',
|
||||
subtype: 'trigger',
|
||||
device: {
|
||||
identifiers: `${sceneDevice.uniqueId}`,
|
||||
identifiers: `${sceneDevice.uniqueId}_trigger`,
|
||||
manufacturer: 'Plejd',
|
||||
model: sceneDevice.typeName,
|
||||
name: sceneDevice.name,
|
||||
|
|
|
|||
|
|
@ -76,6 +76,15 @@ class PlejdAddon extends EventEmitter {
|
|||
// we're triggering a scene, lets do that and jump out.
|
||||
// since scenes aren't "real" devices.
|
||||
this.sceneManager.executeScene(uniqueId);
|
||||
|
||||
// since the scene doesn't get any updates on whether it's executed or not,
|
||||
// we fake this by directly send the sceneTriggered back to HA in order for
|
||||
// it continue to acto on the scene (for non-plejd devices).
|
||||
try {
|
||||
this.mqttClient.sceneTriggered(uniqueId);
|
||||
} catch (err) {
|
||||
logger.error('Error in PlejdService.sceneTriggered callback', err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue