Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Change default homeassistant.status_topic to homeassistant/status #25286

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const ACTION_PATTERNS: string[] = [
const ACCESS_STATE = 0b001;
const ACCESS_SET = 0b010;
const GROUP_SUPPORTED_TYPES: ReadonlyArray<string> = ['light', 'switch', 'lock', 'cover'];
const DEFAULT_STATUS_TOPIC = 'homeassistant/status';
const COVER_OPENING_LOOKUP: ReadonlyArray<string> = ['opening', 'open', 'forward', 'up', 'rising'];
const COVER_CLOSING_LOOKUP: ReadonlyArray<string> = ['closing', 'close', 'backward', 'back', 'reverse', 'down', 'declining'];
const COVER_STOPPED_LOOKUP: ReadonlyArray<string> = ['stopped', 'stop', 'pause', 'paused'];
Expand Down Expand Up @@ -449,7 +448,6 @@ export default class HomeAssistant extends Extension {
this.eventBus.onExposesChanged(this, async (data) => await this.discover(data.device));

await this.mqtt.subscribe(this.statusTopic);
await this.mqtt.subscribe(DEFAULT_STATUS_TOPIC);

/**
* Prevent unnecessary re-discovery of entities by waiting 5 seconds for retained discovery messages to come in.
Expand Down Expand Up @@ -1748,7 +1746,7 @@ export default class HomeAssistant extends Extension {
} else if (entity) {
this.getDiscovered(entity).messages[topic] = {payload: stringify(message), published: true};
}
} else if ((data.topic === this.statusTopic || data.topic === DEFAULT_STATUS_TOPIC) && data.message.toLowerCase() === 'online') {
} else if (data.topic === this.statusTopic && data.message.toLowerCase() === 'online') {
const timer = setTimeout(async () => {
// Publish all device states.
for (const entity of this.zigbee.devicesAndGroupsIterator(utils.deviceNotCoordinator)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"type": "string",
"title": "Home Assistant status topic",
"description": "Home Assistant status topic",
"default": "hass/status",
"default": "homeassistant/status",
"requiresRestart": true,
"examples": ["homeassistant/status"]
},
Expand Down
2 changes: 1 addition & 1 deletion lib/util/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const defaults: RecursivePartial<Settings> = {
homeassistant: {
enabled: false,
discovery_topic: 'homeassistant',
status_topic: 'hass/status',
status_topic: 'homeassistant/status',
legacy_action_sensor: false,
experimental_event_entities: false,
},
Expand Down
2 changes: 1 addition & 1 deletion test/extensions/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Extension: Bridge', () => {
homeassistant: {
enabled: false,
discovery_topic: 'homeassistant',
status_topic: 'hass/status',
status_topic: 'homeassistant/status',
legacy_action_sensor: false,
experimental_event_entities: false,
},
Expand Down
8 changes: 4 additions & 4 deletions test/extensions/homeassistant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,9 +1348,9 @@ describe('Extension: HomeAssistant', () => {
// @ts-expect-error private
extension.state.load();
await resetExtension();
expect(mockMQTT.subscribeAsync).toHaveBeenCalledWith('hass/status');
expect(mockMQTT.subscribeAsync).toHaveBeenCalledWith('homeassistant/status');
mockMQTT.publishAsync.mockClear();
await mockMQTTEvents.message('hass/status', 'online');
await mockMQTTEvents.message('homeassistant/status', 'online');
await flushPromises();
await jest.runOnlyPendingTimersAsync();
await flushPromises();
Expand Down Expand Up @@ -1389,7 +1389,7 @@ describe('Extension: HomeAssistant', () => {
await resetExtension();
await flushPromises();
mockMQTT.publishAsync.mockClear();
await mockMQTTEvents.message('hass/status', 'offline');
await mockMQTTEvents.message('homeassistant/status', 'offline');
await flushPromises();
await jest.runOnlyPendingTimersAsync();
await flushPromises();
Expand All @@ -1402,7 +1402,7 @@ describe('Extension: HomeAssistant', () => {
extension.state.load();
await resetExtension();
mockMQTT.publishAsync.mockClear();
await mockMQTTEvents.message('hass/status_different', 'offline');
await mockMQTTEvents.message('homeassistant/status_different', 'offline');
await flushPromises();
await jest.runOnlyPendingTimersAsync();
await flushPromises();
Expand Down
Loading