Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Allowing the ability to force a sensor pod as a leak sensor #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ Allows you to expose devices (binary_switch/light_bulb) as switches, instead of
}
```

#### `leak_ids`

Allows you to expose devices (sensor_pod) as leak sensors, instead of contact sensors.

```json
{
"leak_ids": [
248563
]
}
```


#### `direct_access`

Expand Down
1 change: 1 addition & 0 deletions src/WinkPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ module.exports = class WinkPlatform {
outlet_ids: [],
switch_ids: [],
window_ids: [],
leak_ids: [],
...config
};

Expand Down
26 changes: 20 additions & 6 deletions src/devices/sensor_pod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { batteryService } = require("./_shared");

const isLeakSensor = (state, device, config) =>
config.leak_ids.indexOf(device.object_id) !== -1;

const isContactSensor = (state, device, config) =>
config.leak_ids.indexOf(device.object_id) === -1 &&
state.opened !== undefined;

module.exports = ({ Characteristic, Service }) => {
const {
ContactSensorState,
Expand Down Expand Up @@ -63,14 +70,21 @@ module.exports = ({ Characteristic, Service }) => {
},
{
service: Service.LeakSensor,
supported: state => state.liquid_detected !== undefined,
supported: isLeakSensor,
characteristics: [
{
characteristic: LeakDetected,
get: state =>
state.liquid_detected
? LeakDetected.LEAK_DETECTED
: LeakDetected.LEAK_NOT_DETECTED
get: state => {
if (isLeakSensor) {
return state.opened
? LeakDetected.LEAK_DETECTED
: LeakDetected.LEAK_NOT_DETECTED;
} else {
return state.liquid_detected
? LeakDetected.LEAK_DETECTED
: LeakDetected.LEAK_NOT_DETECTED;
}
}
}
]
},
Expand All @@ -86,7 +100,7 @@ module.exports = ({ Characteristic, Service }) => {
},
{
service: Service.ContactSensor,
supported: state => state.opened !== undefined,
supported: isContactSensor,
characteristics: [
{
characteristic: ContactSensorState,
Expand Down