diff --git a/src/accessories/koboldVacuumRobot.ts b/src/accessories/koboldVacuumRobot.ts index 1b38b5a..5d2d112 100644 --- a/src/accessories/koboldVacuumRobot.ts +++ b/src/accessories/koboldVacuumRobot.ts @@ -1,6 +1,8 @@ import {CharacteristicValue, Logger, PlatformAccessory, PlatformAccessoryEvent, PlatformConfig, Service} from 'homebridge'; import {HomebridgeKoboldPlatform} from '../homebridgeKoboldPlatform'; import {Options} from '../models/options'; +import { RobotService, CleanType } from '../models/services'; +import { SERVICES, BACKGROUND_INTERVAL, PREFIX } from '../defaults'; /** * Platform Accessory @@ -30,7 +32,7 @@ export class KoboldVacuumRobotAccessory // Config private readonly backgroundUpdateInterval: number; private readonly prefix: boolean; - private readonly availableServices: string[]; + private readonly availableServices: Set; // Transient private isSpotCleaning: boolean; @@ -53,7 +55,7 @@ export class KoboldVacuumRobotAccessory this.backgroundUpdateInterval = KoboldVacuumRobotAccessory.parseBackgroundUpdateInterval(this.config['backgroundUpdate']); this.prefix = this.config['prefix'] || PREFIX; - this.availableServices = this.config['services'] || SERVICES; + this.availableServices = new Set(this.config['services']) || SERVICES; this.isSpotCleaning = false; @@ -82,7 +84,7 @@ export class KoboldVacuumRobotAccessory }); // Services - this.cleanService = this.getSwitchService(RobotService.CLEAN_HOUSE); + this.cleanService = this.getSwitchService(RobotService.CLEAN); this.spotCleanService = this.getSwitchService(RobotService.CLEAN_SPOT); this.goToDockService = this.getSwitchService(RobotService.GO_TO_DOCK); this.dockStateService = this.getOccupancyService(RobotService.DOCKED) @@ -170,11 +172,11 @@ export class KoboldVacuumRobotAccessory }); } - private getSwitchService(serviceName: string) + private getSwitchService(serviceName: RobotService) { let displayName = this.prefix ? this.robot.name + serviceName : serviceName; - if (this.availableServices.includes(serviceName)) + if (this.availableServices.has(serviceName)) { return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.Switch, displayName, serviceName); } @@ -188,11 +190,11 @@ export class KoboldVacuumRobotAccessory } } - private getOccupancyService(serviceName: string) + private getOccupancyService(serviceName: RobotService) { let displayName = this.prefix ? this.robot.name + serviceName : serviceName; - if (this.availableServices.includes(serviceName)) + if (this.availableServices.has(serviceName)) { return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.OccupancySensor, displayName, serviceName); } @@ -616,33 +618,10 @@ export class KoboldVacuumRobotAccessory } } -enum CleanType -{ - ALL, - SPOT -} enum DebugType { ACTION, STATUS, INFO -} - -enum RobotService -{ - CLEAN_HOUSE = "Clean house", - CLEAN_SPOT = "Clean spot", - GO_TO_DOCK = "Go to dock", - DOCKED = "Docked sensor", - BIN_FULL = "Bin full sensor", - FIND_ME = "Find me", - SCHEDULE = "Schedule", - ECO = "Eco", - NOGO_LINES = "Nogo lines", - EXTRA_CARE = "Extra care" -} - -const BACKGROUND_INTERVAL = 30; -const PREFIX = false; -const SERVICES = Object.values(RobotService); \ No newline at end of file +} \ No newline at end of file diff --git a/src/defaults.ts b/src/defaults.ts new file mode 100644 index 0000000..9634ebd --- /dev/null +++ b/src/defaults.ts @@ -0,0 +1,5 @@ +import { RobotService } from "./models/services"; + +export const BACKGROUND_INTERVAL = 30; +export const PREFIX = false; +export const SERVICES = new Set(Object.values(RobotService)); \ No newline at end of file diff --git a/src/localization.ts b/src/localization.ts new file mode 100644 index 0000000..d54365f --- /dev/null +++ b/src/localization.ts @@ -0,0 +1,54 @@ +export enum availableLocales { + EN = "en", + DE = "de", + FR = "fr", +} + +const localizationDicts = { + 'en': { + "clean": "Clean", + "cleanThe": "Clean the", + "goToDock": "Go to Dock", + "dockState": "Docked", + "binFull": "Bin Full", + "eco": "Eco Mode", + "noGoLines": "NoGo Lines", + "extraCare": "Extra Care", + "schedule": "Schedule", + "findMe": "Find me", + "cleanSpot": "Clean Spot", + "battery": "Battery" + }, + 'de': { + "clean": "Sauge", + "cleanThe": "Sauge", + "goToDock": "Zur Basis", + "dockState": "In der Basis", + "binFull": "Behälter voll", + "eco": "Eco Modus", + "noGoLines": "NoGo Linien", + "extraCare": "Extra Care", + "schedule": "Zeitplan", + "findMe": "Finde mich", + "cleanSpot": "Spot Reinigung", + "battery": "Batterie" + }, + 'fr': { + "clean": "Aspirer", + "cleanThe": "Aspirer", + "goToDock": "Retour à la base", + "dockState": "Sur la base", + "binFull": "Conteneur plein", + "eco": "Eco mode", + "noGoLines": "Lignes NoGo", + "extraCare": "Extra Care", + "schedule": "Planifier", + "findMe": "Me retrouver", + "cleanSpot": "Nettoyage local", + "battery": "Batterie" + } +} + +export function localize(label: string, locale: availableLocales) : string { + return localizationDicts[locale][label] ?? label +} \ No newline at end of file diff --git a/src/models/services.ts b/src/models/services.ts new file mode 100644 index 0000000..c62450b --- /dev/null +++ b/src/models/services.ts @@ -0,0 +1,18 @@ +export enum CleanType { + ALL, + SPOT, +} + +export enum RobotService { + CLEAN = "clean", + CLEAN_SPOT = "cleanSpot", + GO_TO_DOCK = "goToDock", + DOCKED = "dockState", + BIN_FULL = "binFull", + FIND_ME = "findMe", + SCHEDULE = "schedule", + ECO = "eco", + NOGO_LINES = "noGoLines", + EXTRA_CARE = "extraCare", + BATTERY = "battery", +}