mirror of
https://github.com/koush/scrypted.git
synced 2026-05-04 21:30:30 +01:00
garage type on homekit
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -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<Setting[]> {
|
||||
return [
|
||||
{
|
||||
title: "Pairing Code",
|
||||
readonly: true,
|
||||
value: "123-45-678",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async putSetting(key: string, value: string | number | boolean): Promise<void> {
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
||||
|
||||
48
plugins/homekit/src/types/garage.ts
Normal file
48
plugins/homekit/src/types/garage.ts
Normal file
@@ -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<CharacteristicValue>) => {
|
||||
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<CharacteristicValue>) => {
|
||||
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;
|
||||
}
|
||||
});
|
||||
@@ -9,3 +9,4 @@ import './mediaplayer';
|
||||
import './vacuum';
|
||||
import './doorbell';
|
||||
import './irrigation';
|
||||
import './garage';
|
||||
|
||||
1
plugins/myq/src/myq
Submodule
1
plugins/myq/src/myq
Submodule
Submodule plugins/myq/src/myq added at b82091dab3
Reference in New Issue
Block a user