diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index 9489e5e05..9dff2b805 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.102", + "version": "0.0.110", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.102", + "version": "0.0.110", "dependencies": { "hap-nodejs": "file:../../external/HAP-NodeJS", "lodash": "^4.17.21", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index d8c512ef0..fce842c16 100644 --- a/plugins/homekit/package.json +++ b/plugins/homekit/package.json @@ -40,5 +40,5 @@ "@types/qrcode": "^1.4.1", "@types/url-parse": "^1.4.3" }, - "version": "0.0.102" + "version": "0.0.110" } diff --git a/plugins/homekit/src/common.ts b/plugins/homekit/src/common.ts index 645fbba7d..ac2ef4d9b 100644 --- a/plugins/homekit/src/common.ts +++ b/plugins/homekit/src/common.ts @@ -36,7 +36,6 @@ export function bindCharacteristic(device: ScryptedDevice, event: ScryptedInterf service.getCharacteristic(characteristic).on(CharacteristicEventTypes.GET, callback => { try { if (device.interfaces.includes(ScryptedInterface.Refresh)) { - console.log('refreshing', device.name); (device as ScryptedDevice & Refresh).refresh(event, true); } callback(null, map()); diff --git a/plugins/homekit/src/types/common.ts b/plugins/homekit/src/types/common.ts index 82d4b75e2..a75eaa7ad 100644 --- a/plugins/homekit/src/types/common.ts +++ b/plugins/homekit/src/types/common.ts @@ -1,6 +1,6 @@ import { ScryptedDevice } from "@scrypted/sdk"; import { uuid, Accessory } from '../hap'; -export function makeAccessory(device: ScryptedDevice): Accessory { - return new Accessory(device.name, uuid.generate(device.id)); +export function makeAccessory(device: ScryptedDevice, suffix?: string): Accessory { + return new Accessory(device.name, uuid.generate(device.id + (suffix ? '-' + suffix : ''))); } diff --git a/plugins/homekit/src/types/thermostat.ts b/plugins/homekit/src/types/thermostat.ts index fe64b45e0..c4076624a 100644 --- a/plugins/homekit/src/types/thermostat.ts +++ b/plugins/homekit/src/types/thermostat.ts @@ -1,9 +1,8 @@ -import { HumiditySensor, OnOff, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, ScryptedInterfaceProperty, TemperatureSetting, TemperatureUnit, Thermometer, ThermostatMode } from '@scrypted/sdk' -import { access } from 'fs'; -import { Fanv2 } from 'hap-nodejs/dist/lib/definitions'; +import { HumiditySensor, OnOff, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, TemperatureSetting, TemperatureUnit, Thermometer, ThermostatMode } from '@scrypted/sdk' +import { Accessory } from 'hap-nodejs'; import { addSupportedType, bindCharacteristic, DummyDevice } from '../common' -import { Characteristic, CharacteristicEventTypes, CharacteristicSetCallback, CharacteristicValue, NodeCallback, Service } from '../hap'; +import { Characteristic, CharacteristicEventTypes, CharacteristicSetCallback, CharacteristicValue, Service } from '../hap'; import { makeAccessory } from './common'; addSupportedType({ @@ -66,7 +65,7 @@ addSupportedType({ }) bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.TargetHeatingCoolingState, - () => toTargetMode(device.thermostatActiveMode)); + () => toTargetMode(device.thermostatMode)); function getTargetTemperature() { return device.thermostatSetpoint || @@ -96,11 +95,19 @@ addSupportedType({ } if (device.interfaces.includes(ScryptedInterface.OnOff)) { - const fanService = accessory.addService(Fanv2); - bindCharacteristic(device, ScryptedInterface.OnOff, fanService, Characteristic.Active, - () => device.on ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE); + const fanService = accessory.addService(Service.Fan); + bindCharacteristic(device, ScryptedInterface.OnOff, fanService, Characteristic.On, + () => !!device.on); + + fanService.getCharacteristic(Characteristic.On).on(CharacteristicEventTypes.SET, (value, callback) => { + callback(); + if (value) + device.turnOn(); + else + device.turnOff(); + }); } return accessory; - } + }, });