Skip to content

Commit

Permalink
Added water valve support (#1451)
Browse files Browse the repository at this point in the history
Co-authored-by: Vyacheslav Andreykiv <vandreykiv@linkedin.com>
  • Loading branch information
vandreykiv and Vyacheslav Andreykiv authored Aug 9, 2024
1 parent e286b97 commit 5029d2c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/homebridge-ring/ring-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { Thermostat } from './thermostat'
import { UnknownZWaveSwitchSwitch } from './unknown-zwave-switch'
import { generateMacAddress } from './util'
import { Intercom } from './intercom'
import { Valve } from './valve'

const ignoreHiddenDeviceTypes: string[] = [
RingDeviceType.RingNetAdapter,
Expand Down Expand Up @@ -122,6 +123,8 @@ function getAccessoryClass(
return WaterSensor
case RingDeviceType.Thermostat:
return Thermostat
case RingDeviceType.WaterValve:
return Valve
case RingDeviceType.UnknownZWave:
return UnknownZWaveSwitchSwitch
}
Expand Down
40 changes: 40 additions & 0 deletions packages/homebridge-ring/valve.ts
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

View workflow job for this annotation

GitHub Actions / build (20)

Strings must use singlequote

Check failure on line 27 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `"open"` with `'open'`

Check failure on line 27 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Strings must use singlequote

Check failure on line 27 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Replace `"open"` with `'open'`
return true;

Check failure on line 28 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Extra semicolon

Check failure on line 28 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 28 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Extra semicolon

Check failure on line 28 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Delete `;`
}
return false;

Check failure on line 30 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Extra semicolon

Check failure on line 30 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 30 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Extra semicolon

Check failure on line 30 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Delete `;`
}

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

View workflow job for this annotation

GitHub Actions / build (20)

Extra semicolon

Check failure on line 36 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Strings must use singlequote

Check failure on line 36 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `"valve.open");` with `'valve.open')`

Check failure on line 36 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Extra semicolon

Check failure on line 36 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Strings must use singlequote

Check failure on line 36 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Replace `"valve.open");` with `'valve.open')`
}
return this.device.sendCommand("valve.close");

Check failure on line 38 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `"valve.close");` with `'valve.close')`

Check failure on line 38 in packages/homebridge-ring/valve.ts

View workflow job for this annotation

GitHub Actions / build (18)

Replace `"valve.close");` with `'valve.close')`
}
}
3 changes: 3 additions & 0 deletions packages/ring-client-api/ring-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum RingDeviceType {
OnvifCamera = 'onvif_camera',
ThirdPartyGarageDoorOpener = 'third_party_gdo',
IntercomHandsetAudio = 'intercom_handset_audio',
WaterValve = 'valve.water'
}

// eslint-disable-next-line no-shadow
Expand All @@ -70,6 +71,7 @@ export enum RingDeviceCategory {
Keypads = 33,
Sirens = 34,
PanicButtons = 35,
WaterValves = 37,
}

// eslint-disable-next-line no-shadow
Expand Down Expand Up @@ -267,6 +269,7 @@ export interface RingDeviceData {
motionSensorEnabled?: boolean
// security-keypad
brightness?: number // 0 - 1
valveState?: 'open' | 'closed'
}

export const deviceTypesWithVolume = [
Expand Down

0 comments on commit 5029d2c

Please sign in to comment.