Skip to content

Commit

Permalink
fix: Don't allow homeassistant.discovery_topic to be equal to `mqtt…
Browse files Browse the repository at this point in the history
….base_topic` #23109
  • Loading branch information
Koenkk committed Jun 30, 2024
1 parent 6ba42c6 commit c22d351
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export default class HomeAssistant extends Extension {
if (settings.get().advanced.output === 'attribute') {
throw new Error('Home Assistant integration is not possible with attribute output!');
}

if (settings.get().homeassistant.discovery_topic === settings.get().mqtt.base_topic) {
throw new Error(`'homeassistant.discovery_topic' cannot not be equal to the 'mqtt.base_topic' (got '${settings.get().mqtt.base_topic}')`);
}
}

override async start(): Promise<void> {
Expand Down
11 changes: 9 additions & 2 deletions test/homeassistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,15 @@ describe('HomeAssistant extension', () => {
settings.set(['experimental', 'output'], 'attribute');
settings.set(['homeassistant'], true);
expect(() => {
const controller = new Controller(false);
}).toThrowError('Home Assistant integration is not possible with attribute output!');
new Controller(false);
}).toThrow('Home Assistant integration is not possible with attribute output!');
});

it('Should throw error when homeassistant.discovery_topic equals the mqtt.base_topic', async () => {
settings.set(['mqtt', 'base_topic'], 'homeassistant');
expect(() => {
new Controller(false);
}).toThrow("'homeassistant.discovery_topic' cannot not be equal to the 'mqtt.base_topic' (got 'homeassistant')");
});

it('Should warn when starting with cache_state false', async () => {
Expand Down

0 comments on commit c22d351

Please sign in to comment.