-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
Co-authored-by: Vyacheslav Andreykiv <vandreykiv@linkedin.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { BaseDeviceAccessory } from './base-device-accessory' | ||
import type { RingDevice } from 'ring-client-api' | ||
import { hap } from './hap' | ||
import { RingPlatformConfig } from './config' | ||
import { PlatformAccessory } from 'homebridge' | ||
import { logInfo } from 'ring-client-api/util' | ||
|
||
export class Valve extends BaseDeviceAccessory { | ||
constructor( | ||
public readonly device: RingDevice, | ||
public readonly accessory: PlatformAccessory, | ||
public readonly config: RingPlatformConfig, | ||
) { | ||
super() | ||
|
||
const { Characteristic, Service } = hap | ||
|
||
this.registerCharacteristic({ | ||
characteristicType: Characteristic.On, | ||
serviceType: Service.Switch, | ||
getValue: (data) => this.isOpen(data.valveState), | ||
setValue: (value) => this.setOnState(value), | ||
}) | ||
} | ||
|
||
isOpen(status: any): boolean { | ||
if (status === "open") { | ||
Check failure on line 27 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 27 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 27 in packages/homebridge-ring/valve.ts GitHub Actions / build (18)
|
||
return true; | ||
Check failure on line 28 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 28 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 28 in packages/homebridge-ring/valve.ts GitHub Actions / build (18)
|
||
} | ||
return false; | ||
Check failure on line 30 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 30 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 30 in packages/homebridge-ring/valve.ts GitHub Actions / build (18)
|
||
} | ||
|
||
setOnState(on: boolean) { | ||
logInfo(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`) | ||
if (on) { | ||
return this.device.sendCommand("valve.open"); | ||
Check failure on line 36 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 36 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 36 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
Check failure on line 36 in packages/homebridge-ring/valve.ts GitHub Actions / build (18)
Check failure on line 36 in packages/homebridge-ring/valve.ts GitHub Actions / build (18)
|
||
} | ||
return this.device.sendCommand("valve.close"); | ||
Check failure on line 38 in packages/homebridge-ring/valve.ts GitHub Actions / build (20)
|
||
} | ||
} |