matterbridge-roborock-vacuum-plugin
Version:
Matterbridge Roborock Vacuum Plugin
82 lines • 2.79 kB
JavaScript
import { DeviceError } from '../errors/index.js';
/** Manages cleaning areas, rooms, maps, and scenes. */
export class AreaManagementService {
logger;
serviceRouting;
supportedAreas = new Map();
supportedRoutines = new Map();
selectedAreas = new Map();
supportedAreaIndexMaps = new Map();
iotApi;
messageClient;
constructor(logger, serviceRouting) {
this.logger = logger;
this.serviceRouting = serviceRouting;
}
setIotApi(iotApi) {
this.iotApi = iotApi;
}
setMessageClient(messageClient) {
this.messageClient ??= messageClient;
}
setSelectedAreas(duid, selectedAreas) {
this.logger.debug('AreaManagementService - setSelectedAreas', selectedAreas);
this.selectedAreas.set(duid, selectedAreas);
}
getSelectedAreas(duid) {
return this.selectedAreas.get(duid) ?? [];
}
setSupportedAreas(duid, supportedAreas) {
this.supportedAreas.set(duid, supportedAreas);
}
setSupportedAreaIndexMap(duid, indexMap) {
this.supportedAreaIndexMaps.set(duid, indexMap);
}
setSupportedRoutines(duid, routineAsRooms) {
this.supportedRoutines.set(duid, routineAsRooms);
}
getSupportedAreas(duid) {
return this.supportedAreas.get(duid) ?? [];
}
getSupportedAreasIndexMap(duid) {
return this.supportedAreaIndexMaps.get(duid);
}
getSupportedRoutines(duid) {
return this.supportedRoutines.get(duid);
}
async getMapInfo(duid) {
if (!this.serviceRouting) {
throw new DeviceError('Service routing not initialized', duid);
}
this.logger.debug('AreaManagementService - getMapInfo', duid);
return this.serviceRouting.getMapInfo(duid);
}
async getRoomMap(duid, activeMap) {
if (!this.serviceRouting) {
throw new DeviceError('Service routing not initialized', duid);
}
this.logger.debug('AreaManagementService - getRoomMap', duid);
return this.serviceRouting.getRoomMap(duid, activeMap);
}
async getScenes(homeId) {
if (!this.iotApi) {
throw new DeviceError('IoT API not initialized');
}
return this.iotApi.getScenes(homeId);
}
async startScene(sceneId) {
if (!this.iotApi) {
throw new DeviceError('IoT API not initialized');
}
return this.iotApi.startScene(sceneId);
}
/** Clear all area management data. */
clearAll() {
this.supportedAreas.clear();
this.supportedRoutines.clear();
this.selectedAreas.clear();
this.supportedAreaIndexMaps.clear();
this.logger.debug('AreaManagementService - All data cleared');
}
}
//# sourceMappingURL=areaManagementService.js.map