UNPKG

@homebridge-plugins/homebridge-resideo

Version:

The Resideo plugin allows you to access your Resideo device(s) from HomeKit.

90 lines (88 loc) 3.2 kB
/** * Converts the value to celsius if the temperature units are in Fahrenheit */ export function toCelsius(value, unit) { if (unit === 0) { return value; } // celsius should be to the nearest 0.5 degree return Math.round((5 / 9) * (value - 32) * 2) / 2; } export function toCelsiusWithOverride(value, unit, convertUnits) { if (convertUnits === 'fahrenheit') { return toCelsius(value, 1); } if (convertUnits === 'celsius') { return toCelsius(value, 0); } return toCelsius(value, unit); } /** * Converts the value to fahrenheit if the temperature units are in Fahrenheit */ export function toFahrenheit(value, unit) { if (unit === 0) { return value; } return Math.round((value * 9) / 5 + 32); } // Map HomeKit Modes to Resideo Modes export var HomeKitModes; (function (HomeKitModes) { HomeKitModes[HomeKitModes["Off"] = 0] = "Off"; HomeKitModes[HomeKitModes["Heat"] = 1] = "Heat"; HomeKitModes[HomeKitModes["Cool"] = 2] = "Cool"; HomeKitModes[HomeKitModes["Auto"] = 3] = "Auto"; })(HomeKitModes || (HomeKitModes = {})); // Don't change the order of these! export var ResideoModes; (function (ResideoModes) { ResideoModes["Off"] = "Off"; ResideoModes["Heat"] = "Heat"; ResideoModes["Cool"] = "Cool"; ResideoModes["Auto"] = "Auto"; })(ResideoModes || (ResideoModes = {})); ; /* export enum holdModes { NoHold = 0, //this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS TemporaryHold = 1, //this.hap.Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS PermanentHold = 2, //this.hap.Characteristic.ProgrammableSwitchEvent.LONG_PRESS } export enum fanModes { Auto = 0, //this.hap.Characteristic.TargetFanState.AUTO On = 1, //this.hap.Characteristic.TargetFanState.ON } export type resideoHold = { NoHold: 'NoHold', TemporaryHold: 'TemporaryHold', PermanentHold: 'PermanentHold' }; */ /** * Creates a proxy class that instantiates the correct platform implementation * (HAP or Matter) at runtime based on the user's configuration and the * availability of the Matter API in the running Homebridge instance. * * @param HAPPlatform The HAP platform class constructor. * @param MatterPlatform The Matter platform class constructor. * @returns A proxy class that delegates to the correct platform implementation. */ export function createPlatformProxy(HAPPlatform, MatterPlatform) { return class ResideoPlatformProxy { /** The instantiated platform implementation (HAP or Matter). */ impl; constructor(log, config, api) { const preferMatter = config?.options?.preferMatter ?? true; const enableMatter = config?.options?.enableMatter ?? true; const matterAvailable = !!(api?.isMatterAvailable?.() && api?.isMatterEnabled?.()); if (enableMatter && preferMatter && MatterPlatform && matterAvailable) { this.impl = new MatterPlatform(log, config, api); return this.impl; } // Fallback to HAP this.impl = new HAPPlatform(log, config, api); return this.impl; } }; } //# sourceMappingURL=utils.js.map