UNPKG

homebridge-pentair-intellicenter-ai

Version:

Homebridge plugin for the Pentair IntelliCenter pool control system (maintained with AI assistance)

49 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TemperatureAccessory = void 0; const settings_1 = require("./settings"); const types_1 = require("./types"); const util_1 = require("./util"); const MODEL = 'Temperature Sensor'; class TemperatureAccessory { constructor(platform, accessory) { this.platform = platform; this.accessory = accessory; this.type = accessory.context.sensor.type; this.name = accessory.context.sensor.name; this.accessory .getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, settings_1.MANUFACTURER) .setCharacteristic(this.platform.Characteristic.Model, MODEL) .setCharacteristic(this.platform.Characteristic.SerialNumber, this.accessory.UUID); this.service = this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor, this.name); this.service.setCharacteristic(this.platform.Characteristic.Name, this.name); this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this)); } async getCurrentTemperature() { var _a; const isFahrenheit = this.platform.getConfig().temperatureUnits === types_1.TemperatureUnits.F; const temp = (_a = this.accessory.context.sensor) === null || _a === void 0 ? void 0 : _a.probe; if (temp === undefined || temp === null || isNaN(temp)) { this.platform.log.warn(`[${this.name}] Invalid temperature value: ${temp}, returning 0`); return 0; } const celsius = isFahrenheit ? (0, util_1.fahrenheitToCelsius)(temp) : temp; return celsius; } updateTemperature(value) { if (value === undefined || value === null || isNaN(value)) { this.platform.log.warn(`[${this.name}] Invalid temperature update value: ${value}, skipping update`); return; } const isFahrenheit = this.platform.getConfig().temperatureUnits === types_1.TemperatureUnits.F; const celsius = isFahrenheit ? (0, util_1.fahrenheitToCelsius)(value) : value; this.accessory.context.sensor.probe = value; this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, celsius); this.platform.log.debug(`[${this.name}] Updated temperature: ${value}${isFahrenheit ? 'F' : 'C'} -> ${celsius}C`); } } exports.TemperatureAccessory = TemperatureAccessory; //# sourceMappingURL=temperatureAccessory.js.map