Skip to content

Commit

Permalink
feat: Add option for switch instead of fan, fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
apexad committed Jun 11, 2020
1 parent a6a6169 commit d569ca0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ To configure manually, add to the `accessories` section of homebridge's `config.
"deviceId": "<deviceId/devId>",
"localKey": "<localKey>",
"hideFindButton": "<true | false, defaults to false>",
"useSwitchService": "<true | false, defaults to false>",
"debugLog": "<true | false, defaults to false>"
}
```
Expand Down
6 changes: 6 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"required": false,
"default": false
},
"useSwitchService": {
"title": "Use Switch for Vacuum (Default is Fan)",
"type": "boolean",
"required": false,
"default": false
},
"debugLog": {
"title": "Enable Debug Log",
"type": "boolean",
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EufyRoboVacAccessory {
services: any[];
name: string;

fanService: any;
vacuumService: any;
batteryService: any;
serviceInfo: any;
findRobot: any;
Expand Down Expand Up @@ -57,14 +57,14 @@ class EufyRoboVacAccessory {

this.services.push(this.serviceInfo);

this.fanService = new Service.Fan(this.name);
this.vacuumService = config.useSwitchService ? new Service.Switch(this.name) : new Service.Fan(this.name);

this.fanService
this.vacuumService
.getCharacteristic(Characteristic.On)
.on('get', this.getCleanState.bind(this))
.on('set', this.setCleanState.bind(this));

this.services.push(this.fanService);
this.services.push(this.vacuumService);

this.batteryService = new Service.BatteryService(this.name + ' Battery');
this.batteryService
Expand Down Expand Up @@ -126,7 +126,7 @@ class EufyRoboVacAccessory {

updateCleaningState(state: boolean) {
this.log.debug('Cleaning State -> %s', state);
this.fanService.getCharacteristic(Characteristic.On).updateValue(state)
this.vacuumService.getCharacteristic(Characteristic.On).updateValue(state)
}

async getCleanState(callback: Function) {
Expand Down

0 comments on commit d569ca0

Please sign in to comment.