Skip to content

Commit 18f817a

Browse files
committed
feat(homebridge): add single-level switch
#75
1 parent 545203a commit 18f817a

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

api/ring-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export enum RingDeviceType {
1414
CoAlarm = 'alarm.co',
1515
SmokeCoListener = 'listener.smoke-co',
1616
MultiLevelSwitch = 'switch.multilevel',
17+
MultiLevelBulb = 'switch.multilevel.bulb',
18+
Switch = 'switch',
1719
BeamsMotionSensor = 'motion-sensor.beams',
1820
BeamsSwitch = 'switch.multilevel.beams',
1921
BeamsLightGroupSwitch = 'group.light-group.beams',

homebridge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ HomeKit with a snapshot from the camera
129129
* Smart Locks
130130
* Lights/Switches
131131
* On/Off
132-
* Brightness Level
132+
* Brightness Level (if applicable)
133133
* Hue/Sat/Color Temp are _possible_, but currently not supported.
134134
Please open an issue if you have a device that you would be able to
135135
test these on.

homebridge/ring-platform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SmokeCoListener } from './smoke-co-listener'
1212
import { RingPlatformConfig } from './config'
1313
import { Beam } from './beam'
1414
import { MultiLevelSwitch } from './multi-level-switch'
15+
import { Switch } from './switch'
1516
import { Camera } from './camera'
1617
import { RingAuth } from '../api/rest-client'
1718
import { platformName, pluginName } from './plugin-info'
@@ -46,7 +47,10 @@ function getAccessoryClass(device: RingDevice | RingCamera) {
4647
case RingDeviceType.BeamsLightGroupSwitch:
4748
return Beam
4849
case RingDeviceType.MultiLevelSwitch:
50+
case RingDeviceType.MultiLevelBulb:
4951
return MultiLevelSwitch
52+
case RingDeviceType.Switch:
53+
return Switch
5054
}
5155

5256
if (/^lock($|\.)/.test(deviceType)) {

homebridge/switch.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BaseDeviceAccessory } from './base-device-accessory'
2+
import { RingDevice } from '../api'
3+
import { HAP, hap } from './hap'
4+
import { RingPlatformConfig } from './config'
5+
6+
export class Switch extends BaseDeviceAccessory {
7+
constructor(
8+
public readonly device: RingDevice,
9+
public readonly accessory: HAP.Accessory,
10+
public readonly logger: HAP.Log,
11+
public readonly config: RingPlatformConfig
12+
) {
13+
super()
14+
15+
const { Characteristic, Service } = hap
16+
17+
this.registerCharacteristic(
18+
Characteristic.On,
19+
Service.On,
20+
data => Boolean(data.on),
21+
value => this.setOnState(value)
22+
)
23+
}
24+
25+
setOnState(on: boolean) {
26+
this.logger.info(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`)
27+
28+
return this.device.setInfo({ device: { v1: { on } } })
29+
}
30+
}

0 commit comments

Comments
 (0)