UNPKG

matterbridge-roborock-vacuum-plugin

Version:
45 lines (44 loc) 2.53 kB
import { RoboticVacuumCleaner } from 'matterbridge'; import { getOperationalStates, getSupportedAreas, getSupportedCleanModes, getSupportedRunModes } from './initialData/index.js'; import { RvcOperationalState } from 'matterbridge/matter/clusters'; export class RoborockVacuumCleaner extends RoboticVacuumCleaner { username; device; rrHomeId; roomInfo; dockStationStatus; constructor(username, device, roomMap, routineAsRoom, enableExperimentalFeature, log) { const cleanModes = getSupportedCleanModes(device.data.model, enableExperimentalFeature); const supportedRunModes = getSupportedRunModes(); const supportedAreas = [...getSupportedAreas(device.rooms, roomMap, log), ...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)}`); super(deviceName, device.duid, supportedRunModes[0].mode, supportedRunModes, cleanModes[0].mode, cleanModes, undefined, undefined, RvcOperationalState.OperationalState.Docked, getOperationalStates(), supportedAreas, undefined, supportedAreas[0].areaId); this.username = username; this.device = device; this.rrHomeId = device.rrHomeId; } configurateHandler(behaviorHandler) { this.addCommandHandler('identify', async ({ request: { identifyTime } }) => { behaviorHandler.executeCommand('playSoundToLocate', identifyTime); }); this.addCommandHandler('selectAreas', async ({ request }) => { this.log.info(`Selecting areas: ${request.newAreas.join(', ')}`); behaviorHandler.executeCommand('selectAreas', request.newAreas); }); this.addCommandHandler('changeToMode', async ({ request }) => { behaviorHandler.executeCommand('changeToMode', request.newMode); }); this.addCommandHandler('pause', async () => { behaviorHandler.executeCommand('pause'); }); this.addCommandHandler('resume', async () => { behaviorHandler.executeCommand('resume'); }); this.addCommandHandler('goHome', async () => { behaviorHandler.executeCommand('goHome'); }); } }