homekit: fixup fan service on thermostat

This commit is contained in:
Koushik Dutta
2021-10-30 21:38:46 -07:00
parent 8adfbec2f7
commit eb1f3c32f0
5 changed files with 21 additions and 15 deletions

View File

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

View File

@@ -40,5 +40,5 @@
"@types/qrcode": "^1.4.1",
"@types/url-parse": "^1.4.3"
},
"version": "0.0.102"
"version": "0.0.110"
}

View File

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

View File

@@ -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 : '')));
}

View File

@@ -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;
}
},
});