Reconfigure device after OTA update. #7716 #7150

This commit is contained in:
Koen Kanters committed 2021-12-07 21:58:11 +01:00
1 parent d4f560d198
commit ac16d7ce69
8 files changed
+18 -17

No files matched your search

+4 -4
View File
@@ -133,11 +133,11 @@ export default class EventBus {
this.on('scenesChanged', callback, key);
}
public emitReportingDisabled(data: eventdata.ReportingDisabled): void {
this.emitter.emit('reportingDisabled', data);
public emitReconfigure(data: eventdata.Reconfigure): void {
this.emitter.emit('reconfigure', data);
}
public onReportingDisabled(key: ListenerKey, callback: (data: eventdata.ReportingDisabled) => void): void {
this.on('reportingDisabled', callback, key);
public onReconfigure(key: ListenerKey, callback: (data: eventdata.Reconfigure) => void): void {
this.on('reconfigure', callback, key);
}
public emitStateChange(data: eventdata.StateChange): void {
+1 -1
View File
@@ -417,7 +417,7 @@ export default class Bind extends Extension {
}
}
this.eventBus.emitReportingDisabled({device});
this.eventBus.emitReconfigure({device});
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ export default class Configure extends Extension {
private topic = `${settings.get().mqtt.base_topic}/bridge/request/device/configure`;
private legacyTopic = `${settings.get().mqtt.base_topic}/bridge/configure`;
@bind private async onReportingDisabled(data: eventdata.ReportingDisabled): Promise<void> {
@bind private async onReconfigure(data: eventdata.Reconfigure): Promise<void> {
// Disabling reporting unbinds some cluster which could be bound by configure, re-setup.
if (data.device.zh.meta?.hasOwnProperty('configured')) {
delete data.device.zh.meta.configured;
@@ -79,7 +79,7 @@ export default class Configure extends Extension {
this.eventBus.onDeviceInterview(this, (data) => this.configure(data.device, 'zigbee_event'));
this.eventBus.onLastSeenChanged(this, (data) => this.configure(data.device, 'zigbee_event'));
this.eventBus.onMQTTMessage(this, this.onMQTTMessage);
this.eventBus.onReportingDisabled(this, this.onReportingDisabled);
this.eventBus.onReconfigure(this, this.onReconfigure);
}
private async configure(device: Device, event: 'started' | 'zigbee_event' | 'reporting_disabled' | 'mqtt_message',
+1 -1
View File
@@ -116,7 +116,7 @@ export default class Report extends Extension {
device.zh.meta.reporting = reportKey;
} else {
delete device.zh.meta.reporting;
this.eventBus.emitReportingDisabled({device});
this.eventBus.emitReconfigure({device});
}
this.eventBus.emitDevicesChanged();
+5 -4
View File
@@ -92,11 +92,11 @@ export default class OTAUpdate extends Extension {
}
}
private async readSoftwareBuildIDAndDateCode(device: Device, update: boolean):
private async readSoftwareBuildIDAndDateCode(device: Device, update: boolean, sendWhenActive: boolean):
Promise<{softwareBuildID: string, dateCode: string}> {
try {
const endpoint = device.zh.endpoints.find((e) => e.supportsInputCluster('genBasic'));
const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId']);
const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId'], {sendWhenActive});
if (update) {
device.zh.softwareBuildID = result.swBuildId;
@@ -230,10 +230,11 @@ export default class OTAUpdate extends Extension {
}
};
const from_ = await this.readSoftwareBuildIDAndDateCode(device, false);
const from_ = await this.readSoftwareBuildIDAndDateCode(device, false, false);
await device.definition.ota.updateToLatest(device.zh, logger, onProgress);
const to = await this.readSoftwareBuildIDAndDateCode(device, true);
const to = await this.readSoftwareBuildIDAndDateCode(device, true, device.zh.type === 'EndDevice');
const [fromS, toS] = [stringify(from_), stringify(to)];
this.eventBus.emitReconfigure({device});
const msg = `Finished update of '${device.name}'` +
(to ? `, from '${fromS}' to '${toS}'` : ``);
logger.info(msg);
+1 -1
View File
@@ -142,7 +142,7 @@ declare global {
type DeviceAnnounce = { device: Device };
type DeviceInterview = { device: Device, status: 'started' | 'successful' | 'failed' };
type DeviceJoined = { device: Device };
type ReportingDisabled = { device: Device };
type Reconfigure = { device: Device };
type DeviceLeave = { ieeeAddr: string, name: string };
type GroupMembersChanged = {group: Group, action: 'remove' | 'add' | 'remove_all',
endpoint: zh.Endpoint, skipDisableReporting: boolean };
+2 -2
View File
@@ -100,12 +100,12 @@ describe('Configure', () => {
expectBulbConfigured();
});
it('Should reconfigure reporting on reportingDisabled event', async () => {
it('Should reconfigure reporting on reconfigure event', async () => {
expectBulbConfigured();
const device = controller.zigbee.resolveEntity(zigbeeHerdsman.devices.bulb);
mockClear(device.zh);
expectBulbNotConfigured();
controller.eventBus.emitReportingDisabled({device});
controller.eventBus.emitReconfigure({device});
await flushPromises();
expectBulbConfigured();
});
+2 -2
View File
@@ -71,7 +71,7 @@ describe('OTA update', () => {
expect(logger.info).toHaveBeenCalledWith(`Update of 'bulb' at 0.00%`);
expect(logger.info).toHaveBeenCalledWith(`Update of 'bulb' at 10.00%, ≈ 60 minutes remaining`);
expect(logger.info).toHaveBeenCalledWith(`Finished update of 'bulb', from '{"dateCode":"20190101","softwareBuildID":1}' to '{"dateCode":"20190102","softwareBuildID":2}'`);
expect(device.save).toHaveBeenCalledTimes(1);
expect(device.save).toHaveBeenCalledTimes(3);
expect(device.dateCode).toBe('20190102');
expect(device.softwareBuildID).toBe(2);
expect(MQTT.publish).toHaveBeenCalledWith(
@@ -372,7 +372,7 @@ describe('OTA update', () => {
expect(logger.info).toHaveBeenCalledWith(`Update of 'bulb' at 10.00%, ≈ 60 minutes remaining`);
expect(logger.info).toHaveBeenCalledWith(`Finished update of 'bulb', from '{"dateCode":"20190101","softwareBuildID":1}' to '{"dateCode":"20190102","softwareBuildID":2}'`);
expect(logger.error).toHaveBeenCalledTimes(0);
expect(device.save).toHaveBeenCalledTimes(1);
expect(device.save).toHaveBeenCalledTimes(3);
expect(device.dateCode).toBe('20190102');
expect(device.softwareBuildID).toBe(2);
});