garage type on homekit

This commit is contained in:
Koushik Dutta
2021-08-27 21:00:07 -07:00
parent f881ccb598
commit f8df11ac65
5 changed files with 67 additions and 2 deletions

3
.gitmodules vendored
View File

@@ -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

View File

@@ -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() {

View 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;
}
});

View File

@@ -9,3 +9,4 @@ import './mediaplayer';
import './vacuum';
import './doorbell';
import './irrigation';
import './garage';

1
plugins/myq/src/myq Submodule

Submodule plugins/myq/src/myq added at b82091dab3