fix: Fix configure on startup crashing coordinator https://github.com/Koenkk/zigbee2mqtt/issues/20526

This commit is contained in:
koenkk
2024-01-03 10:51:05 +01:00
parent e6bcf91e17
commit e9aee4c6dc
6 changed files with 26 additions and 1 deletions
+3
View File
@@ -66,6 +66,9 @@ export default class Configure extends Extension {
override async start(): Promise<void> {
setImmediate(async () => {
for (const device of this.zigbee.devices(false)) {
// Sleep 10 seconds between configuring on startup to not DDoS the coordinator
// when many devices have to be configured.
await utils.sleep(10);
await this.configure(device, 'started');
}
});
+3
View File
@@ -5,6 +5,7 @@ const logger = require('./stub/logger');
const zigbeeHerdsman = require('./stub/zigbeeHerdsman');
const flushPromises = require('./lib/flushPromises');
const MQTT = require('./stub/mqtt');
const sleep = require('./stub/sleep');
const Controller = require('../lib/controller');
const fs = require('fs');
const path = require('path');
@@ -42,12 +43,14 @@ describe('HomeAssistant extension', () => {
settings.reRead();
data.writeEmptyState();
MQTT.publish.mockClear();
sleep.mock();
controller = new Controller(false);
await controller.start();
});
afterAll(async () => {
jest.useRealTimers();
sleep.restore();
});
it('Should not have duplicate type/object_ids in a mapping', () => {
+4 -1
View File
@@ -2,6 +2,7 @@ const path = require('path');
const data = require('./stub/data');
const logger = require('./stub/logger');
const sleep = require('./stub/sleep');
const zigbeeHerdsman = require('./stub/zigbeeHerdsman');
const MQTT = require('./stub/mqtt');
const settings = require('../lib/util/settings');
@@ -35,6 +36,7 @@ describe('OTA update', () => {
settings.reRead();
jest.useFakeTimers();
controller = new Controller(jest.fn(), jest.fn());
sleep.mock();
await controller.start();
await jest.runOnlyPendingTimers();
await flushPromises();
@@ -47,6 +49,7 @@ describe('OTA update', () => {
afterAll(async () => {
jest.useRealTimers();
sleep.restore();
});
beforeEach(async () => {
@@ -57,7 +60,7 @@ describe('OTA update', () => {
MQTT.publish.mockClear();
});
it('Should OTA update a device', async () => {
it('onlythis Should OTA update a device', async () => {
const device = zigbeeHerdsman.devices.bulb;
const endpoint = device.endpoints[0];
let count = 0;
+3
View File
@@ -1,4 +1,5 @@
const data = require('./stub/data');
const sleep = require('./stub/sleep');
const logger = require('./stub/logger');
const zigbeeHerdsman = require('./stub/zigbeeHerdsman');
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
@@ -30,6 +31,7 @@ describe('Publish', () => {
jest.useFakeTimers();
data.writeEmptyState();
controller = new Controller(jest.fn(), jest.fn());
sleep.mock();
await controller.start();
await flushPromises();
});
@@ -56,6 +58,7 @@ describe('Publish', () => {
afterAll(async () => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
sleep.restore();
});
it('Should publish messages to zigbee devices', async () => {
+3
View File
@@ -1,4 +1,5 @@
const data = require('./stub/data');
const sleep = require('./stub/sleep');
const logger = require('./stub/logger');
const stringify = require('json-stable-stringify-without-jsonify');
const zigbeeHerdsman = require('./stub/zigbeeHerdsman');
@@ -15,6 +16,7 @@ describe('Receive', () => {
beforeAll(async () => {
jest.useFakeTimers();
controller = new Controller(jest.fn(), jest.fn());
sleep.mock();
await controller.start();
await jest.runOnlyPendingTimers();
await flushPromises();
@@ -30,6 +32,7 @@ describe('Receive', () => {
afterAll(async () => {
jest.useRealTimers();
sleep.restore();
});
it('Should handle a zigbee message', async () => {
+10
View File
@@ -0,0 +1,10 @@
const utils = require('../../lib/util/utils');
const spy = jest.spyOn(utils.default, 'sleep');
export function mock() {
spy.mockImplementation(() => {});
}
export function restore() {
spy.mockRestore();
}