Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ You can thank the authors by these links:
## Changelog
### **WORK IN PROGRESS**
* (schimi1983) Smoke and water leak sensors get the roles the device detector expects (sensor.alarm.fire / sensor.alarm.flood)
* (MikeFTV) OTA: one write to info.ota or info.ota_available runs one scan or one update per device instead of two (#3059)

### 3.6.1 (2026-11-20)
* (reloxx13) Add optional group membership restoration after rejoin or successful interview (disabled by default), and report membership update failures after synchronization.
Expand Down
2 changes: 0 additions & 2 deletions lib/pluginOta.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class Ota extends basePlugin{
constructor(adapter) {
super(adapter, 'OTA');
this.adapter = adapter;
this.adapter.on('message', this.onMessage.bind(this));
this.adapter.on('stateChange', this.onStateChange.bind(this));
this.inProgress = new Set();
this.otaAvailable = new Set();
}
Expand Down
71 changes: 71 additions & 0 deletions test/otaHandlers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

// Regression test for the OTA plugin listening twice to the adapter.
//
// The constructor of Ota registered its message and stateChange handlers, and start() registered
// them again through registerHandler(). One write to info.ota then started two availability scans,
// and one write to info.ota_available started two updates per device (the second one failing with
// "OTA already in progress"). The constructor registrations were also never removed by stop().
//
// Runs the real plugin against a stubbed adapter; no hardware.
// Run: node --test test/otaHandlers.test.js

const Module = require('node:module');
const { EventEmitter } = require('node:events');
const { describe, it } = require('node:test');
const assert = require('node:assert');

// pluginOta.js imports zigbee-herdsman only for setOtaConfiguration(); stub it so the test needs
// neither the dependency tree nor a coordinator.
const originalLoad = Module._load;
let Ota;
try {
Module._load = function (request, ...args) {
if (request === 'zigbee-herdsman') return { setOtaConfiguration() {} };
return originalLoad.call(this, request, ...args);
};
Ota = require('../lib/pluginOta');
} finally {
Module._load = originalLoad;
}

function makeAdapter() {
const adapter = new EventEmitter();
adapter.namespace = 'zigbee.0';
adapter.config = {};
adapter.onLog = () => {};
adapter.setStateAsync = async () => {};
adapter.getDataFolder = () => '/tmp';
return adapter;
}

describe('Ota plugin handlers', () => {
it('listens once to stateChange and message after start()', () => {
const adapter = makeAdapter();
const plugin = new Ota(adapter);
plugin.start({}, {});
assert.strictEqual(adapter.listenerCount('stateChange'), 1);
assert.strictEqual(adapter.listenerCount('message'), 1);
});

it('handles a single stateChange once', async () => {
const adapter = makeAdapter();
const plugin = new Ota(adapter);
let calls = 0;
adapter.getDevicesAsync = async () => [{ native: { id: '00158d0001a2b3c4' } }];
plugin.multiCheckOtaAvail = async () => { calls++; };
plugin.start({}, {});
adapter.emit('stateChange', 'zigbee.0.info.ota', { val: true, ack: false });
await new Promise((resolve) => setImmediate(resolve));
assert.strictEqual(calls, 1, 'one write to info.ota must start one availability scan');
});

it('leaves no handler behind after stop()', () => {
const adapter = makeAdapter();
const plugin = new Ota(adapter);
plugin.start({}, {});
plugin.stop();
assert.strictEqual(adapter.listenerCount('stateChange'), 0);
assert.strictEqual(adapter.listenerCount('message'), 0);
});
});
Loading