forked from tuya/tuya-homebridge
-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement ContactSensorAccessory and LeakSensorAccessory
- Loading branch information
Showing
7 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { PlatformAccessory } from 'homebridge'; | ||
import { TuyaPlatform } from '../platform'; | ||
import BaseAccessory from './BaseAccessory'; | ||
|
||
export default class ContaceSensor extends BaseAccessory { | ||
|
||
constructor(platform: TuyaPlatform, accessory: PlatformAccessory) { | ||
super(platform, accessory); | ||
|
||
const service = this.accessory.getService(this.Service.ContactSensor) | ||
|| this.accessory.addService(this.Service.ContactSensor); | ||
|
||
service.getCharacteristic(this.Characteristic.ContactSensorState) | ||
.onGet(() => { | ||
const status = this.device.getDeviceStatus('doorcontact_state'); | ||
return status!.value ? | ||
this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED: | ||
this.Characteristic.ContactSensorState.CONTACT_DETECTED; | ||
}); | ||
|
||
if (this.device.getDeviceStatus('battery_percentage')) { | ||
service.getCharacteristic(this.Characteristic.StatusLowBattery) | ||
.onGet(() => { | ||
const status = this.device.getDeviceStatus('battery_percentage'); | ||
return (status && status!.value <= 20) ? | ||
this.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : | ||
this.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL; | ||
}); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { PlatformAccessory } from 'homebridge'; | ||
import { TuyaPlatform } from '../platform'; | ||
import BaseAccessory from './BaseAccessory'; | ||
|
||
export default class LeakSensor extends BaseAccessory { | ||
|
||
constructor(platform: TuyaPlatform, accessory: PlatformAccessory) { | ||
super(platform, accessory); | ||
|
||
const service = this.accessory.getService(this.Service.LeakSensor) | ||
|| this.accessory.addService(this.Service.LeakSensor); | ||
|
||
service.getCharacteristic(this.Characteristic.LeakDetected) | ||
.onGet(() => { | ||
const gas = this.device.getDeviceStatus('gas_sensor_status') | ||
|| this.device.getDeviceStatus('gas_sensor_state'); | ||
const ch4 = this.device.getDeviceStatus('ch4_sensor_state'); | ||
const co = this.device.getDeviceStatus('co_status') | ||
|| this.device.getDeviceStatus('co_state'); | ||
|
||
if ((gas && (gas.value === 'alarm' || gas.value === '1')) | ||
|| (ch4 && ch4.value === 'alarm') | ||
|| (co && (co.value === 'alarm' || co.value === '1'))) { | ||
return this.Characteristic.LeakDetected.LEAK_DETECTED; | ||
} else { | ||
return this.Characteristic.LeakDetected.LEAK_NOT_DETECTED; | ||
} | ||
}); | ||
|
||
if (this.device.getDeviceStatus('battery_percentage')) { | ||
service.getCharacteristic(this.Characteristic.StatusLowBattery) | ||
.onGet(() => { | ||
const status = this.device.getDeviceStatus('battery_percentage'); | ||
return (status && status!.value <= 20) ? | ||
this.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : | ||
this.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL; | ||
}); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters