diff --git a/.gitmodules b/.gitmodules index dc3da5f32..536238afb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "plugins/unifi-protect/src/unifi-protect"] path = plugins/unifi-protect/src/unifi-protect url = git@github.com:koush/unifi-protect.git +[submodule "plugins/myq/src/myq"] + path = plugins/myq/src/myq + url = git@github.com:koush/myq.git diff --git a/plugins/homekit/src/main.ts b/plugins/homekit/src/main.ts index 234679b05..d321ad2ec 100644 --- a/plugins/homekit/src/main.ts +++ b/plugins/homekit/src/main.ts @@ -1,4 +1,4 @@ -import sdk, { MixinProvider, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType } from '@scrypted/sdk'; +import sdk, { Settings, MixinProvider, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, Setting } from '@scrypted/sdk'; import { Bridge, Categories, HAPStorage } from './hap'; import os from 'os'; import { supportedTypes } from './common'; @@ -50,12 +50,24 @@ const uuid = localStorage.getItem('uuid'); const includeToken = 4; -class HomeKit extends ScryptedDeviceBase implements MixinProvider { +class HomeKit extends ScryptedDeviceBase implements MixinProvider, Settings { bridge = new Bridge('Scrypted', uuid); constructor() { super(); this.start(); } + async getSettings(): Promise { + return [ + { + title: "Pairing Code", + readonly: true, + value: "123-45-678", + } + ] + } + + async putSetting(key: string, value: string | number | boolean): Promise { + } async start() { diff --git a/plugins/homekit/src/types/garage.ts b/plugins/homekit/src/types/garage.ts new file mode 100644 index 000000000..d889ac5df --- /dev/null +++ b/plugins/homekit/src/types/garage.ts @@ -0,0 +1,48 @@ + +import { Entry, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, StartStop } from '@scrypted/sdk' +import { addSupportedType, DummyDevice, listenCharacteristic } from '../common' +import { Characteristic, CharacteristicEventTypes, CharacteristicSetCallback, CharacteristicValue, NodeCallback, Service } from '../hap'; +import { makeAccessory } from './common'; + +addSupportedType({ + type: ScryptedDeviceType.Garage, + probe(device: DummyDevice): boolean { + return device.interfaces.includes(ScryptedInterface.Entry); + }, + getAccessory: (device: ScryptedDevice & Entry) => { + const accessory = makeAccessory(device); + + const service = accessory.addService(Service.GarageDoorOpener, device.name); + service.getCharacteristic(Characteristic.CurrentDoorState) + .on(CharacteristicEventTypes.GET, (callback: NodeCallback) => { + callback(null, !!device.entryOpen ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED); + }); + + + device.listen({ + event: ScryptedInterface.Entry, + }, (eventSource, eventDetails, data) => { + service.updateCharacteristic(Characteristic.CurrentDoorState, + !!device.entryOpen ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED); + }) + + let targetState = !!device.entryOpen ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED; + service.getCharacteristic(Characteristic.TargetDoorState) + .on(CharacteristicEventTypes.GET, (callback: NodeCallback) => { + callback(null, targetState); + }) + .on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => { + callback(); + if (value === Characteristic.TargetDoorState.OPEN) { + targetState = Characteristic.TargetDoorState.OPEN; + device.openEntry(); + } + else { + targetState = Characteristic.TargetDoorState.CLOSED; + device.closeEntry(); + } + }) + + return accessory; + } +}); diff --git a/plugins/homekit/src/types/index.ts b/plugins/homekit/src/types/index.ts index 995e07c36..ff6d31682 100644 --- a/plugins/homekit/src/types/index.ts +++ b/plugins/homekit/src/types/index.ts @@ -9,3 +9,4 @@ import './mediaplayer'; import './vacuum'; import './doorbell'; import './irrigation'; +import './garage'; diff --git a/plugins/myq/src/myq b/plugins/myq/src/myq new file mode 160000 index 000000000..b82091dab --- /dev/null +++ b/plugins/myq/src/myq @@ -0,0 +1 @@ +Subproject commit b82091dab33ce0864d7b234faa000659a38168cc