Skip to content

Commit

Permalink
mqtt: Fix autodiscvoery
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 16, 2024
1 parent 807ba81 commit 584ea97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/mqtt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/mqtt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
"@types/node": "^18.4.2",
"@types/nunjucks": "^3.2.0"
},
"version": "0.0.79"
"version": "0.0.80"
}
8 changes: 6 additions & 2 deletions plugins/mqtt/src/autodiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ autoDiscoveryMap.set(ScryptedInterface.OnOff, {
});

export function publishAutoDiscovery(mqttId: string, client: Client, device: MixinDeviceBase<any>, topic: string, subscribe: boolean, autoDiscoveryPrefix = 'homeassistant') {
const subs = new Set<string>();

for (const iface of device.interfaces) {
const found = autoDiscoveryMap.get(iface);
if (!found)
Expand All @@ -721,6 +723,8 @@ export function publishAutoDiscovery(mqttId: string, client: Client, device: Mix
if (subscribe) {
const subscriptions = found.subscriptions || {};
for (const subscriptionTopic of Object.keys(subscriptions || {})) {
subs.add(subscriptionTopic);

const fullTopic = topic + '/' + subscriptionTopic;
const cb = subscriptions[subscriptionTopic];
client.subscribe(fullTopic)
Expand All @@ -746,7 +750,7 @@ export function publishAutoDiscovery(mqttId: string, client: Client, device: Mix
});
}
}

return found;
}

return subs;
}
2 changes: 1 addition & 1 deletion plugins/mqtt/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class MqttPublisherMixin extends SettingsMixinDeviceBase<any> {
const method = messageTopic.substring(this.pathname.length + 1);
if (!allMethods.includes(method)) {
if (!allProperties.includes(method)) {
if (!found?.subscriptions?.[method]) {
if (!found?.has(method)) {
this.console.warn('unknown topic', method);
}
}
Expand Down

0 comments on commit 584ea97

Please sign in to comment.