mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-06-23 05:31:47 +00:00
chore: Update dependencies (#18459)
* fix(ignore): update dependencies * Make compatible with MQTT 5 * updates --------- Co-authored-by: Koenkk <Koenkk@users.noreply.github.com>
This commit is contained in:
@@ -124,7 +124,7 @@ export default class Frontend extends Extension {
|
||||
if (!isBinary && data) {
|
||||
const message = data.toString();
|
||||
const {topic, payload} = JSON.parse(message);
|
||||
this.mqtt.onMessage(`${this.mqttBaseTopic}/${topic}`, stringify(payload));
|
||||
this.mqtt.onMessage(`${this.mqttBaseTopic}/${topic}`, Buffer.from(stringify(payload)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+6
-5
@@ -4,6 +4,7 @@ import * as settings from './util/settings';
|
||||
import utils from './util/utils';
|
||||
import fs from 'fs';
|
||||
import bind from 'bind-decorator';
|
||||
import type {QoS} from 'mqtt-packet';
|
||||
|
||||
export default class MQTT {
|
||||
private publishedTopics: Set<string> = new Set();
|
||||
@@ -26,7 +27,7 @@ export default class MQTT {
|
||||
const options: mqtt.IClientOptions = {
|
||||
will: {
|
||||
topic: `${settings.get().mqtt.base_topic}/bridge/state`,
|
||||
payload: utils.availabilityPayload('offline', settings.get()),
|
||||
payload: Buffer.from(utils.availabilityPayload('offline', settings.get())),
|
||||
retain: settings.get().mqtt.force_disable_retain ? false : true,
|
||||
qos: 1,
|
||||
},
|
||||
@@ -133,11 +134,11 @@ export default class MQTT {
|
||||
this.client.subscribe(topic);
|
||||
}
|
||||
|
||||
@bind public onMessage(topic: string, message: string): void {
|
||||
@bind public onMessage(topic: string, message: Buffer): void {
|
||||
// Since we subscribe to zigbee2mqtt/# we also receive the message we send ourselves, skip these.
|
||||
if (!this.publishedTopics.has(topic)) {
|
||||
logger.debug(`Received MQTT message on '${topic}' with data '${message}'`);
|
||||
this.eventBus.emitMQTTMessage({topic, message: message + ''});
|
||||
logger.debug(`Received MQTT message on '${topic}' with data '${message.toString()}'`);
|
||||
this.eventBus.emitMQTTMessage({topic, message: message.toString()});
|
||||
}
|
||||
|
||||
if (this.republishRetainedTimer && topic === `${settings.get().mqtt.base_topic}/bridge/info`) {
|
||||
@@ -153,7 +154,7 @@ export default class MQTT {
|
||||
async publish(topic: string, payload: string, options: MQTTOptions={},
|
||||
base=settings.get().mqtt.base_topic, skipLog=false, skipReceive=true,
|
||||
): Promise<void> {
|
||||
const defaultOptions: {qos: mqtt.QoS, retain: boolean} = {qos: 0, retain: false};
|
||||
const defaultOptions: {qos: QoS, retain: boolean} = {qos: 0, retain: false};
|
||||
topic = `${base}/${topic}`;
|
||||
|
||||
if (skipReceive) {
|
||||
|
||||
Vendored
+3
-3
@@ -31,7 +31,7 @@ import type TypeDevice from 'lib/model/device';
|
||||
import type TypeGroup from 'lib/model/group';
|
||||
import type TypeExtension from 'lib/extension/extension';
|
||||
|
||||
import type mqtt from 'mqtt';
|
||||
import type {QoS} from 'mqtt-packet';
|
||||
|
||||
declare global {
|
||||
// Define some class types as global
|
||||
@@ -45,7 +45,7 @@ declare global {
|
||||
|
||||
// Types
|
||||
interface MQTTResponse {data: KeyValue, status: 'error' | 'ok', error?: string, transaction?: string}
|
||||
interface MQTTOptions {qos?: mqtt.QoS, retain?: boolean, properties?: {messageExpiryInterval: number}}
|
||||
interface MQTTOptions {qos?: QoS, retain?: boolean, properties?: {messageExpiryInterval: number}}
|
||||
type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged' | 'publishCached';
|
||||
type PublishEntityState = (entity: Device | Group, payload: KeyValue,
|
||||
stateChangeReason?: StateChangeReason) => Promise<void>;
|
||||
@@ -189,7 +189,7 @@ declare global {
|
||||
base_topic: string,
|
||||
include_device_information: boolean,
|
||||
force_disable_retain: boolean
|
||||
version?: number,
|
||||
version?: 3 | 4 | 5,
|
||||
user?: string,
|
||||
password?: string,
|
||||
server: string,
|
||||
|
||||
Generated
+1018
-926
File diff suppressed because it is too large
Load Diff
+7
-6
@@ -49,7 +49,7 @@
|
||||
"jszip": "^3.10.1",
|
||||
"mkdir-recursive": "^0.4.0",
|
||||
"moment": "^2.29.4",
|
||||
"mqtt": "4.3.7",
|
||||
"mqtt": "5.0.2",
|
||||
"object-assign-deep": "^0.4.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"semver": "^7.5.4",
|
||||
@@ -75,15 +75,16 @@
|
||||
"@types/jest": "^29.5.3",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/object-assign-deep": "^0.4.0",
|
||||
"@types/readable-stream": "^4.0.0",
|
||||
"@types/rimraf": "^3.0.2",
|
||||
"@types/ws": "8.5.4",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"@typescript-eslint/parser": "^6.1.0",
|
||||
"babel-jest": "^29.6.1",
|
||||
"eslint": "^8.45.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
||||
"@typescript-eslint/parser": "^6.2.1",
|
||||
"babel-jest": "^29.6.2",
|
||||
"eslint": "^8.46.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"eslint-plugin-jest": "^27.2.3",
|
||||
"jest": "^29.6.1",
|
||||
"jest": "^29.6.2",
|
||||
"tmp": "^0.2.1",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('Controller', () => {
|
||||
expect(logger.info).toHaveBeenCalledWith('remote (0x0017880104e45517): 324131092621 - Philips Hue dimmer switch (EndDevice)');
|
||||
expect(logger.info).toHaveBeenCalledWith('0x0017880104e45518 (0x0017880104e45518): Not supported (EndDevice)');
|
||||
expect(MQTT.connect).toHaveBeenCalledTimes(1);
|
||||
expect(MQTT.connect).toHaveBeenCalledWith("mqtt://localhost", {"will": {"payload": "offline", "retain": true, "topic": "zigbee2mqtt/bridge/state", "qos": 1}});
|
||||
expect(MQTT.connect).toHaveBeenCalledWith("mqtt://localhost", {"will": {"payload": Buffer.from("offline"), "retain": true, "topic": "zigbee2mqtt/bridge/state", "qos": 1}});
|
||||
expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bulb', stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99}),{ retain: true, qos: 0 }, expect.any(Function));
|
||||
expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/remote', stringify({"brightness":255}), { retain: true, qos: 0 }, expect.any(Function));
|
||||
});
|
||||
@@ -88,7 +88,7 @@ describe('Controller', () => {
|
||||
await flushPromises();
|
||||
expect(MQTT.connect).toHaveBeenCalledTimes(1);
|
||||
const expected = {
|
||||
"will": {"payload": "offline", "retain": true, "topic": "zigbee2mqtt/bridge/state", "qos": 1},
|
||||
"will": {"payload": Buffer.from("offline"), "retain": true, "topic": "zigbee2mqtt/bridge/state", "qos": 1},
|
||||
keepalive: 30,
|
||||
ca: Buffer.from([99, 97]),
|
||||
key: Buffer.from([107, 101, 121]),
|
||||
@@ -640,7 +640,7 @@ describe('Controller', () => {
|
||||
await flushPromises();
|
||||
expect(MQTT.connect).toHaveBeenCalledTimes(1);
|
||||
const expected = {
|
||||
"will": { "payload": "offline", "retain": false, "topic": "zigbee2mqtt/bridge/state", "qos": 1 },
|
||||
"will": { "payload": Buffer.from("offline"), "retain": false, "topic": "zigbee2mqtt/bridge/state", "qos": 1 },
|
||||
}
|
||||
expect(MQTT.connect).toHaveBeenCalledWith("mqtt://localhost", expected);
|
||||
});
|
||||
|
||||
@@ -71,12 +71,7 @@ describe('Publish', () => {
|
||||
});
|
||||
|
||||
it('Should corretly handle mallformed messages', async () => {
|
||||
await MQTT.events.message('zigbee2mqtt/foo', undefined);
|
||||
await MQTT.events.message('zigbee2mqtt/foo', null);
|
||||
await MQTT.events.message('zigbee2mqtt/foo', "");
|
||||
|
||||
await MQTT.events.message('zigbee2mqtt/bulb_color/set', undefined);
|
||||
await MQTT.events.message('zigbee2mqtt/bulb_color/set', null);
|
||||
await MQTT.events.message('zigbee2mqtt/bulb_color/set', "");
|
||||
await flushPromises();
|
||||
expectNothingPublished();
|
||||
|
||||
Reference in New Issue
Block a user