Added option to enable services

This commit is contained in:
Arne Blumentritt 2021-05-04 09:58:35 +02:00
parent 296a81010a
commit f7f70ac478
2 changed files with 168 additions and 99 deletions

View File

@ -47,7 +47,18 @@
"Bin full sensor" "Bin full sensor"
] ]
}, },
"uniqueItems": true "default": [
"Clean house",
"Clean spot",
"Go to dock",
"Find me",
"Schedule",
"Eco",
"Nogo lines",
"Extra care",
"Docked sensor",
"Bin full sensor"
]
} }
} }
}, },

View File

@ -12,16 +12,16 @@ export class NeatoVacuumRobotAccessory
// Homebridge // Homebridge
private log: Logger; private log: Logger;
private batteryService: Service; private batteryService: Service;
private cleanService: Service; private cleanService: Service | null;
private findMeService: Service; private findMeService: Service | null;
private goToDockService: Service; private goToDockService: Service | null;
private dockStateService: Service; private dockStateService: Service | null;
private binFullService: Service; private binFullService: Service | null;
private ecoService: Service; private ecoService: Service | null;
private noGoLinesService: Service; private noGoLinesService: Service | null;
private extraCareService: Service; private extraCareService: Service | null;
private scheduleService: Service; private scheduleService: Service | null;
private spotCleanService: Service; private spotCleanService: Service | null;
// Context // Context
private robot: any; private robot: any;
@ -54,7 +54,6 @@ export class NeatoVacuumRobotAccessory
this.backgroundUpdateInterval = NeatoVacuumRobotAccessory.parseBackgroundUpdateInterval(this.config['backgroundUpdate']); this.backgroundUpdateInterval = NeatoVacuumRobotAccessory.parseBackgroundUpdateInterval(this.config['backgroundUpdate']);
this.prefix = this.config['prefix'] || PREFIX; this.prefix = this.config['prefix'] || PREFIX;
this.availableServices = this.config['services'] || SERVICES; this.availableServices = this.config['services'] || SERVICES;
this.log.debug(JSON.stringify(this.availableServices));
this.isSpotCleaning = false; this.isSpotCleaning = false;
@ -75,50 +74,82 @@ export class NeatoVacuumRobotAccessory
this.debug(DebugType.INFO, JSON.stringify("Error: " + error)); this.debug(DebugType.INFO, JSON.stringify("Error: " + error));
} }
this.debug(DebugType.INFO, "Status: " + JSON.stringify(result)); this.debug(DebugType.INFO, "Status: " + JSON.stringify(result));
this.debug(DebugType.INFO,
"Config: Background Update Interval: " + this.backgroundUpdateInterval + ", Prefix: " + this.prefix + ", Enabled services: " + JSON.stringify(this.availableServices));
}); });
}); });
// Services // Services
this.cleanService = this.getSwitchService("Clean House"); this.cleanService = this.getSwitchService(RobotService.CLEAN_HOUSE);
this.spotCleanService = this.getSwitchService("Clean Spot"); this.spotCleanService = this.getSwitchService(RobotService.CLEAN_SPOT);
this.goToDockService = this.getSwitchService("Go to Dock"); this.goToDockService = this.getSwitchService(RobotService.GO_TO_DOCK);
this.dockStateService = this.getOccupancyService("Docked") this.dockStateService = this.getOccupancyService(RobotService.DOCKED)
this.binFullService = this.getOccupancyService("Bin Full") this.binFullService = this.getOccupancyService(RobotService.BIN_FULL)
this.findMeService = this.getSwitchService("Find Me"); this.findMeService = this.getSwitchService(RobotService.FIND_ME);
this.scheduleService = this.getSwitchService("Schedule"); this.scheduleService = this.getSwitchService(RobotService.SCHEDULE);
this.ecoService = this.getSwitchService("Option: Eco Mode"); this.ecoService = this.getSwitchService(RobotService.ECO);
this.noGoLinesService = this.getSwitchService("Option: NoGo Lines"); this.noGoLinesService = this.getSwitchService(RobotService.NOGO_LINES);
this.extraCareService = this.getSwitchService("Option: Extra Care"); this.extraCareService = this.getSwitchService(RobotService.EXTRA_CARE);
this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery) this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)
if (this.cleanService)
{
this.cleanService.getCharacteristic(this.platform.Characteristic.On) this.cleanService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setCleanHouse.bind(this)) .onSet(this.setCleanHouse.bind(this))
.onGet(this.getCleanHouse.bind(this)); .onGet(this.getCleanHouse.bind(this));
}
if (this.spotCleanService)
{
this.spotCleanService.getCharacteristic(this.platform.Characteristic.On) this.spotCleanService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setSpotClean.bind(this)) .onSet(this.setSpotClean.bind(this))
.onGet(this.getSpotClean.bind(this)); .onGet(this.getSpotClean.bind(this));
}
if (this.goToDockService)
{
this.goToDockService.getCharacteristic(this.platform.Characteristic.On) this.goToDockService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setGoToDock.bind(this)) .onSet(this.setGoToDock.bind(this))
.onGet(this.getGoToDock.bind(this)); .onGet(this.getGoToDock.bind(this));
}
if (this.dockStateService)
{
this.dockStateService.getCharacteristic(this.platform.Characteristic.OccupancyDetected) this.dockStateService.getCharacteristic(this.platform.Characteristic.OccupancyDetected)
.onGet(this.getDocked.bind(this)); .onGet(this.getDocked.bind(this));
}
if (this.binFullService)
{
this.binFullService.getCharacteristic(this.platform.Characteristic.OccupancyDetected) this.binFullService.getCharacteristic(this.platform.Characteristic.OccupancyDetected)
.onGet(this.getBinFull.bind(this)); .onGet(this.getBinFull.bind(this));
}
if (this.findMeService)
{
this.findMeService.getCharacteristic(this.platform.Characteristic.On) this.findMeService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setFindMe.bind(this)) .onSet(this.setFindMe.bind(this))
.onGet(this.getFindMe.bind(this)); .onGet(this.getFindMe.bind(this));
}
if (this.scheduleService)
{
this.scheduleService.getCharacteristic(this.platform.Characteristic.On) this.scheduleService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setSchedule.bind(this)) .onSet(this.setSchedule.bind(this))
.onGet(this.getSchedule.bind(this)); .onGet(this.getSchedule.bind(this));
}
if (this.ecoService)
{
this.ecoService.getCharacteristic(this.platform.Characteristic.On) this.ecoService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setEco.bind(this)) .onSet(this.setEco.bind(this))
.onGet(this.getEco.bind(this)); .onGet(this.getEco.bind(this));
}
if (this.noGoLinesService)
{
this.noGoLinesService.getCharacteristic(this.platform.Characteristic.On) this.noGoLinesService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setNoGoLines.bind(this)) .onSet(this.setNoGoLines.bind(this))
.onGet(this.getNoGoLines.bind(this)); .onGet(this.getNoGoLines.bind(this));
}
if (this.extraCareService)
{
this.extraCareService.getCharacteristic(this.platform.Characteristic.On) this.extraCareService.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setExtraCare.bind(this)) .onSet(this.setExtraCare.bind(this))
.onGet(this.getExtraCare.bind(this)); .onGet(this.getExtraCare.bind(this));
}
// Start background update // Start background update
this.updateRobotPeriodically().then(() => { this.updateRobotPeriodically().then(() => {
@ -140,13 +171,37 @@ export class NeatoVacuumRobotAccessory
private getSwitchService(serviceName: string) private getSwitchService(serviceName: string)
{ {
let displayName = this.prefix ? this.robot.name + serviceName : serviceName; let displayName = this.prefix ? this.robot.name + serviceName : serviceName;
return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.Switch, displayName, serviceName)
if (this.availableServices.includes(serviceName))
{
return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.Switch, displayName, serviceName);
}
else
{
if(this.accessory.getService(displayName))
{
this.accessory.removeService(<Service>this.accessory.getService(displayName));
}
return null;
}
} }
private getOccupancyService(serviceName: string) private getOccupancyService(serviceName: string)
{ {
let displayName = this.prefix ? this.robot.name + serviceName : serviceName; let displayName = this.prefix ? this.robot.name + serviceName : serviceName;
return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.OccupancySensor, displayName, serviceName)
if (this.availableServices.includes(serviceName))
{
return this.accessory.getService(displayName) || this.accessory.addService(this.platform.Service.OccupancySensor, displayName, serviceName);
}
else
{
if(this.accessory.getService(displayName))
{
this.accessory.removeService(<Service>this.accessory.getService(displayName));
}
return null;
}
} }
private static parseBackgroundUpdateInterval(configValue: any) private static parseBackgroundUpdateInterval(configValue: any)
@ -270,7 +325,10 @@ export class NeatoVacuumRobotAccessory
await this.updateRobot(); await this.updateRobot();
setTimeout(() => { setTimeout(() => {
if (this.goToDockService)
{
this.goToDockService.updateCharacteristic(this.platform.Characteristic.On, false); this.goToDockService.updateCharacteristic(this.platform.Characteristic.On, false);
}
}, 1000); }, 1000);
try try
@ -290,7 +348,7 @@ export class NeatoVacuumRobotAccessory
} }
else else
{ {
this.log.warn(this.robot.name + "=| Can't go to dock at the moment"); this.log.warn("[" + this.robot.name + "] Can't go to dock at the moment");
} }
} }
catch (error) catch (error)
@ -409,7 +467,10 @@ export class NeatoVacuumRobotAccessory
{ {
this.debug(DebugType.ACTION, "Find me"); this.debug(DebugType.ACTION, "Find me");
setTimeout(() => { setTimeout(() => {
if (this.findMeService)
{
this.findMeService.updateCharacteristic(this.platform.Characteristic.On, false); this.findMeService.updateCharacteristic(this.platform.Characteristic.On, false);
}
}, 1000); }, 1000);
try try
@ -510,33 +571,30 @@ export class NeatoVacuumRobotAccessory
async updateCharacteristics() async updateCharacteristics()
{ {
// Update Switches if (this.cleanService)
// Clean {
this.cleanService.updateCharacteristic(this.platform.Characteristic.On, await this.getCleanHouse()); this.cleanService.updateCharacteristic(this.platform.Characteristic.On, await this.getCleanHouse());
}
// Spot Clean if (this.spotCleanService)
{
this.spotCleanService.updateCharacteristic(this.platform.Characteristic.On, await this.getSpotClean()); this.spotCleanService.updateCharacteristic(this.platform.Characteristic.On, await this.getSpotClean());
}
// Go To Dock if (this.goToDockService)
{
this.goToDockService.updateCharacteristic(this.platform.Characteristic.On, await this.getGoToDock()); this.goToDockService.updateCharacteristic(this.platform.Characteristic.On, await this.getGoToDock());
}
// Docked if (this.dockStateService)
{
this.dockStateService.updateCharacteristic(this.platform.Characteristic.OccupancyDetected, await this.getDocked()); this.dockStateService.updateCharacteristic(this.platform.Characteristic.OccupancyDetected, await this.getDocked());
}
// Bin full if (this.binFullService)
{
this.binFullService.updateCharacteristic(this.platform.Characteristic.OccupancyDetected, await this.getBinFull()); this.binFullService.updateCharacteristic(this.platform.Characteristic.OccupancyDetected, await this.getBinFull());
}
// Schedule if (this.scheduleService)
{
this.scheduleService.updateCharacteristic(this.platform.Characteristic.On, await this.getSchedule()); this.scheduleService.updateCharacteristic(this.platform.Characteristic.On, await this.getSchedule());
}
// Eco
this.ecoService.updateCharacteristic(this.platform.Characteristic.On, await this.getEco());
// Extra Care
this.extraCareService.updateCharacteristic(this.platform.Characteristic.On, await this.getExtraCare());
// NoGo Lines
this.noGoLinesService.updateCharacteristic(this.platform.Characteristic.On, await this.getNoGoLines());
} }
private debug(debugType: DebugType, message: String) private debug(debugType: DebugType, message: String)
@ -569,20 +627,20 @@ enum DebugType
INFO INFO
} }
enum Action enum RobotService
{ {
CLEAN_HOUSE = "CLEAN_HOUSE", CLEAN_HOUSE = "Clean house",
CLEAN_SPOT = "CLEAN_SPOT", CLEAN_SPOT = "Clean spot",
GO_TO_DOCK = "GO_TO_DOCK", GO_TO_DOCK = "Go to dock",
DOCKED = "DOCKED", DOCKED = "Docked sensor",
BIN_FULL = "BIN_FULL", BIN_FULL = "Bin full sensor",
FIND_ME = "FIND_ME", FIND_ME = "Find me",
SCHEDULE = "SCHEDULE", SCHEDULE = "Schedule",
ECO = "ECO", ECO = "Eco",
NOGO_LINES = "NOGO_LINES", NOGO_LINES = "Nogo lines",
EXTRA_CARE = "EXTRA_CARE" EXTRA_CARE = "Extra care"
} }
const BACKGROUND_INTERVAL = 30; const BACKGROUND_INTERVAL = 30;
const PREFIX = false; const PREFIX = false;
const SERVICES = Object.values(Action); const SERVICES = Object.values(RobotService);