UNPKG

matterbridge-roborock-vacuum-plugin

Version:
30 lines (29 loc) 932 B
import decodeComponent from '../helper/nameDecoder.js'; export class MapInfo { maps = []; allRooms = []; constructor(multimap) { this.maps = multimap.map_info.map((mapInfo) => { const rooms = mapInfo.rooms?.map((room) => ({ id: room.id, globalId: parseInt(room.iot_name_id), iot_name_id: room.iot_name_id, tag: room.tag, displayName: room.iot_name, mapId: mapInfo.mapFlag, })) ?? []; this.allRooms.push(...rooms); return { id: mapInfo.mapFlag, name: decodeComponent(mapInfo.name), rooms, }; }); } getById(id) { return this.maps.find((m) => m.id === id)?.name; } getByName(name) { return this.maps.find((m) => m.name?.toLowerCase() === name.toLowerCase())?.id; } }