Skip to content

Commit

Permalink
fix(ignore): Revert "chore: Update dependencies (#18459)"
Browse files Browse the repository at this point in the history
This reverts commit 53cb421.
  • Loading branch information
Koenkk committed Aug 9, 2023
1 parent 7f05f31 commit b09b8ec
Show file tree
Hide file tree
Showing 7 changed files with 949 additions and 1,038 deletions.
2 changes: 1 addition & 1 deletion lib/extension/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, Buffer.from(stringify(payload)));
this.mqtt.onMessage(`${this.mqttBaseTopic}/${topic}`, stringify(payload));
}
});

Expand Down
11 changes: 5 additions & 6 deletions lib/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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();
Expand All @@ -27,7 +26,7 @@ export default class MQTT {
const options: mqtt.IClientOptions = {
will: {
topic: `${settings.get().mqtt.base_topic}/bridge/state`,
payload: Buffer.from(utils.availabilityPayload('offline', settings.get())),
payload: utils.availabilityPayload('offline', settings.get()),
retain: settings.get().mqtt.force_disable_retain ? false : true,
qos: 1,
},
Expand Down Expand Up @@ -134,11 +133,11 @@ export default class MQTT {
this.client.subscribe(topic);
}

@bind public onMessage(topic: string, message: Buffer): void {
@bind public onMessage(topic: string, message: string): 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.toString()}'`);
this.eventBus.emitMQTTMessage({topic, message: message.toString()});
logger.debug(`Received MQTT message on '${topic}' with data '${message}'`);
this.eventBus.emitMQTTMessage({topic, message: message + ''});
}

if (this.republishRetainedTimer && topic === `${settings.get().mqtt.base_topic}/bridge/info`) {
Expand All @@ -154,7 +153,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: QoS, retain: boolean} = {qos: 0, retain: false};
const defaultOptions: {qos: mqtt.QoS, retain: boolean} = {qos: 0, retain: false};
topic = `${base}/${topic}`;

if (skipReceive) {
Expand Down
6 changes: 3 additions & 3 deletions lib/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {QoS} from 'mqtt-packet';
import type mqtt from 'mqtt';

declare global {
// Define some class types as global
Expand All @@ -45,7 +45,7 @@ declare global {

// Types
interface MQTTResponse {data: KeyValue, status: 'error' | 'ok', error?: string, transaction?: string}
interface MQTTOptions {qos?: QoS, retain?: boolean, properties?: {messageExpiryInterval: number}}
interface MQTTOptions {qos?: mqtt.QoS, retain?: boolean, properties?: {messageExpiryInterval: number}}
type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged' | 'publishCached';
type PublishEntityState = (entity: Device | Group, payload: KeyValue,
stateChangeReason?: StateChangeReason) => Promise<void>;
Expand Down Expand Up @@ -189,7 +189,7 @@ declare global {
base_topic: string,
include_device_information: boolean,
force_disable_retain: boolean
version?: 3 | 4 | 5,
version?: number,
user?: string,
password?: string,
server: string,
Expand Down
Loading

0 comments on commit b09b8ec

Please sign in to comment.