Skip to content

Commit

Permalink
Added water valve support (#1451)
Browse files Browse the repository at this point in the history
Closes #1450

Squashed commit of the following:

commit 81cfb8a52c1d0ad106ebbcc47d52998f0c9e35c4
Author: dgreif <[email protected]>
Date:   Fri Aug 9 09:15:03 2024 -0400

    Update readme

commit cd14182ba037988b47963c874959f841bc16bfd3
Author: dgreif <[email protected]>
Date:   Fri Aug 9 09:09:16 2024 -0400

    Fix lint

commit 49aba72627253519ab01c5da7ddd1e87ecac7ca4
Author: dgreif <[email protected]>
Date:   Fri Aug 9 09:09:00 2024 -0400

    Release notes

commit 5029d2c
Author: Vyacheslav Andreykiv <[email protected]>
Date:   Fri Aug 9 06:02:35 2024 -0700

    Added water valve support (#1451)

    Co-authored-by: Vyacheslav Andreykiv <[email protected]>
  • Loading branch information
dgreif committed Aug 9, 2024
1 parent e286b97 commit 1a1ee4b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-ducks-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'homebridge-ring': minor
'ring-client-api': minor
---

Add support for water valves. Note, these have not been tested extensively so please let us know if you run into issues.
2 changes: 2 additions & 0 deletions packages/homebridge-ring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ Note: Although homebridge has support for HomeKit Secure Video (HKSV), I will no
- Set Thermostat mode to heat/cool/off
- Set target temperature
- View current temperature and heating/cooling status
- Water Valves (**untested**)
- Open/Close the valve

### Chimes

Expand Down
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: RingDevice['data']['valveState']): boolean {
if (status === 'open') {
return true
}
return false
}

setOnState(on: boolean) {
logInfo(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`)
if (on) {
return this.device.sendCommand('valve.open')
}
return this.device.sendCommand('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 1a1ee4b

Please sign in to comment.