zigbee2mqtt-extensions
zigbee2mqtt-extensions copied to clipboard
z2m 2.4 support
hi. are you planning upgrade code to z2m 2.4 ? this extension work up to z2m 2.3 but after upgrade to 2.4 there are errors on z2m restart : error: z2m: Invalid external extension 'auto.js' was ignored and renamed to prevent interference with Zigbee2MQTT.
Hello @maxilee, @Anonym-tsk, this is the what you need to put on top of the js file to make it work with zigbee2mqtt 2.5. (it replaces the existing imports) It rewrites yaml and data utils instead of grabbing zigbee2mqtt ones. Seems to work alright on my side.
"use strict";
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const assert = require('assert');
const stringify = require("json-stable-stringify-without-jsonify");
const crypto = require("crypto");
function read(file) {
try {
const result = yaml.load(fs.readFileSync(file, "utf8"));
assert(result instanceof Object);
return result;
} catch (error) {
if (error instanceof yaml.YAMLException) {
throw new YAMLFileException(error, file);
}
throw error;
}
}
function readIfExists(file, fallback = {}) {
return fs.existsSync(file) ? read(file) : fallback;
}
function setPath() {
return process.env.ZIGBEE2MQTT_DATA ? process.env.ZIGBEE2MQTT_DATA : path.normalize(path.join(__dirname, "..", "..", "data"));
}
let dataPath = setPath();
function joinPath(file) {
return path.resolve(dataPath, file);
}
function toArray(item) {
return Array.isArray(item) ? item : [item];
}
thx. I'll check this and let you know.