Skip to content

Commit 0e87755

Browse files
committed
Add Home switch as separate to docking contact sensor
1 parent e7f574c commit 0e87755

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"homebridge-roomba2": minor
3+
---
4+
5+
Add Home switch as separate to docking contact sensor

config.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"title": "Returning Home",
5656
"required": false
5757
},
58+
"homeSwitch": {
59+
"type": "boolean",
60+
"title": "Home",
61+
"required": false
62+
},
5863
"dockOnStop": {
5964
"type": "boolean",
6065
"title": "Dock when stopped",
@@ -66,6 +71,7 @@
6671
"layout": [
6772
{ "type": "section", "title": "Roomba Details", "items": [ "name", "model", "serialnum", "blid", "robotpwd", "ipaddress" ] },
6873
{ "type": "section", "title": "Contact Sensors", "items": [ "dockContactSensor", "dockingContactSensor", "runningContactSensor", "binContactSensor" ] },
74+
{ "type": "section", "title": "Switches", "items": [ "homeSwitch" ] },
6975
{ "type": "section", "title": "Behaviour", "items": [ "dockOnStop" ] }
7076
]
7177
}

src/accessory.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
9090
private runningService?: Service
9191
private binService?: Service
9292
private dockingService?: Service
93+
private homeService?: Service
9394

9495
/**
9596
* The last known state from Roomba, if any.
@@ -138,6 +139,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
138139
const showRunningAsContactSensor = config.runningContactSensor;
139140
const showBinStatusAsContactSensor = config.binContactSensor;
140141
const showDockingAsContactSensor = config.dockingContactSensor;
142+
const showHomeSwitch = config.homeSwitch;
141143

142144
const Service = api.hap.Service;
143145

@@ -156,7 +158,10 @@ export default class RoombaAccessory implements AccessoryPlugin {
156158
this.binService = new Service.ContactSensor(this.name + " Bin Full", "Full");
157159
}
158160
if (showDockingAsContactSensor) {
159-
this.dockingService = new Service.Switch(this.name + " Docking", "docking");
161+
this.dockingService = new Service.ContactSensor(this.name + " Docking", "docking");
162+
}
163+
if (showHomeSwitch) {
164+
this.homeService = new Service.Switch(this.name + " Home", "returning");
160165
}
161166

162167
const Characteristic = this.api.hap.Characteristic;
@@ -204,9 +209,14 @@ export default class RoombaAccessory implements AccessoryPlugin {
204209
}
205210
if (this.dockingService) {
206211
this.dockingService
212+
.getCharacteristic(Characteristic.ContactSensorState)
213+
.on("get", this.createCharacteristicGetter("Docking status", this.dockingStatus));
214+
}
215+
if (this.homeService) {
216+
this.homeService
207217
.getCharacteristic(Characteristic.On)
208218
.on("set", this.setDockingState.bind(this))
209-
.on("get", this.createCharacteristicGetter("Docking status", this.dockingStatus));
219+
.on("get", this.createCharacteristicGetter("Returning Home", this.dockingStatus));
210220
}
211221

212222
this.startLongWatch();
@@ -236,6 +246,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
236246
if (this.dockingService) {
237247
services.push(this.dockingService);
238248
}
249+
if (this.homeService) {
250+
services.push(this.homeService);
251+
}
239252

240253
return services;
241254
}
@@ -720,6 +733,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
720733
if (this.dockingService) {
721734
updateCharacteristic(this.dockingService, Characteristic.ContactSensorState, this.dockingStatus);
722735
}
736+
if (this.homeService) {
737+
updateCharacteristic(this.homeService, Characteristic.On, this.dockingStatus);
738+
}
723739

724740
this.lastUpdatedStatus = {
725741
...this.lastUpdatedStatus,
@@ -792,8 +808,8 @@ export default class RoombaAccessory implements AccessoryPlugin {
792808
private dockingStatus = (status: Status) => status.docking === undefined
793809
? undefined
794810
: status.docking
795-
? 1
796-
: 0;
811+
? this.api.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
812+
: this.api.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
797813
private dockedStatus = (status: Status) => status.charging === undefined
798814
? undefined
799815
: status.charging

0 commit comments

Comments
 (0)