matterbridge-roborock-vacuum-plugin
Version:
Matterbridge Roborock Vacuum Plugin
83 lines • 2.76 kB
JavaScript
import { NotifyMessageTypes } from '../../../../types/index.js';
export class SimpleMessageHandler {
duid;
logger;
deviceNotify;
constructor(duid, logger, deviceNotify) {
this.duid = duid;
this.logger = logger;
this.deviceNotify = deviceNotify;
}
async onError(error) {
if (!this.deviceNotify) {
this.logger.debug(`[SimpleMessageHandler]: No deviceNotify callback provided`);
return Promise.resolve();
}
await this.deviceNotify({
type: NotifyMessageTypes.ErrorOccurred,
data: {
duid: error.duid,
vacuumErrorCode: error.vacuumErrorCode,
dockErrorCode: error.dockErrorCode,
dockStationStatus: error.dockStationStatus,
},
});
}
async onBatteryUpdate(message) {
if (!this.deviceNotify) {
this.logger.debug(`[SimpleMessageHandler]: No deviceNotify callback provided`);
return Promise.resolve();
}
await this.deviceNotify({
type: NotifyMessageTypes.BatteryUpdate,
data: message,
});
}
async onStatusChanged(message) {
if (!this.deviceNotify) {
this.logger.debug(`[SimpleMessageHandler]: No deviceNotify callback provided`);
return Promise.resolve();
}
await this.deviceNotify({
type: NotifyMessageTypes.DeviceStatus,
data: message,
});
}
async onCleanModeUpdate(message) {
if (!this.deviceNotify) {
this.logger.debug(`[SimpleMessageHandler]: No deviceNotify callback provided`);
return Promise.resolve();
}
await this.deviceNotify({
type: NotifyMessageTypes.CleanModeUpdate,
data: {
...message,
duid: this.duid,
seq_type: message.sequenceType,
},
});
}
async onServiceAreaUpdate(message) {
if (!this.deviceNotify) {
this.logger.debug(`[SimpleMessageHandler]: No deviceNotify callback provided`);
return Promise.resolve();
}
await this.deviceNotify({
type: NotifyMessageTypes.ServiceAreaUpdate,
data: message,
});
}
onAdditionalProps(value) {
// Implement additional properties handling logic here
return Promise.resolve();
}
async onActiveMapChanged(mapId) {
if (!this.deviceNotify)
return;
await this.deviceNotify({
type: NotifyMessageTypes.ActiveMapChanged,
data: { duid: this.duid, mapId },
});
}
}
//# sourceMappingURL=simpleMessageHandler.js.map