matterbridge-roborock-vacuum-plugin
Version:
Matterbridge Roborock Vacuum Plugin
52 lines (51 loc) • 3.4 kB
JavaScript
import { RoboticVacuumCleaner } from 'matterbridge/devices';
import { getOperationalStates, getSupportedAreas, getSupportedCleanModes, getSupportedRunModes } from './initialData/index.js';
import { debugStringify } from 'matterbridge/logger';
import { RvcOperationalState } from 'matterbridge/matter/clusters';
export class RoborockVacuumCleaner extends RoboticVacuumCleaner {
username;
device;
roomInfo;
dockStationStatus;
constructor(username, device, roomMap, routineAsRoom, enableExperimentalFeature, log) {
const cleanModes = getSupportedCleanModes(device.data.model, enableExperimentalFeature);
const supportedRunModes = getSupportedRunModes();
const enableMultipleMap = enableExperimentalFeature?.enableExperimentalFeature && enableExperimentalFeature?.advancedFeature?.enableMultipleMap;
const { supportedAreas, supportedMaps } = getSupportedAreas(device.rooms, roomMap, enableMultipleMap, log);
const supportedAreaAndRoutines = [...supportedAreas, ...routineAsRoom];
const deviceName = `${device.name}-${device.duid}`.replace(/\s+/g, '');
log.debug(`Creating RoborockVacuumCleaner for device: ${deviceName}, model: ${device.data.model}, forceRunAtDefault: ${enableExperimentalFeature?.advancedFeature?.forceRunAtDefault}`);
log.debug(`Supported Clean Modes: ${JSON.stringify(cleanModes)}`);
log.debug(`Supported Run Modes: ${JSON.stringify(supportedRunModes)}`);
log.debug(`Supported Areas: ${JSON.stringify(supportedAreas)}`);
log.debug(`Supported Maps: ${JSON.stringify(supportedMaps)}`);
const bridgeMode = enableExperimentalFeature?.enableExperimentalFeature && enableExperimentalFeature?.advancedFeature?.enableServerMode ? 'server' : undefined;
super(deviceName, device.duid, bridgeMode, supportedRunModes[0].mode, supportedRunModes, cleanModes[0].mode, cleanModes, undefined, undefined, RvcOperationalState.OperationalState.Docked, getOperationalStates(), supportedAreaAndRoutines, undefined, supportedAreas[0].areaId, supportedMaps);
this.username = username;
this.device = device;
}
configurateHandler(behaviorHandler) {
this.addCommandHandler('identify', async ({ request, cluster, attributes, endpoint }) => {
this.log.info(`Identify command received for endpoint ${endpoint}, cluster ${cluster}, attributes ${debugStringify(attributes)}, request: ${JSON.stringify(request)}`);
behaviorHandler.executeCommand('playSoundToLocate', request.identifyTime ?? 0);
});
this.addCommandHandler('selectAreas', async ({ request }) => {
const { newAreas } = request;
this.log.info(`Selecting areas: ${newAreas?.join(', ')}`);
behaviorHandler.executeCommand('selectAreas', newAreas);
});
this.addCommandHandler('changeToMode', async ({ request }) => {
const { newMode } = request;
behaviorHandler.executeCommand('changeToMode', newMode);
});
this.addCommandHandler('pause', async () => {
behaviorHandler.executeCommand('pause');
});
this.addCommandHandler('resume', async () => {
behaviorHandler.executeCommand('resume');
});
this.addCommandHandler('goHome', async () => {
behaviorHandler.executeCommand('goHome');
});
}
}