UNPKG

homebridge-rinnai-touch-platform

Version:

Homebridge Plugin to control heating/cooling via a Rinnai Touch WiFi Module

66 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TemperatureFormat = void 0; const jsonpath_plus_1 = require("jsonpath-plus"); class TemperatureFormat { constructor(platform, client) { this.platform = platform; this.client = client; this.zoneTopics = {}; if (platform.settings.mqtt.subscribeTemperature) { for (const zone of this.platform.service.AllZones) { if (platform.settings.mqtt.subscribeTemperature[zone] !== undefined) { this.zoneTopics[zone] = platform.settings.mqtt.subscribeTemperature[zone]; } } } } get subscriptionTopics() { return [...new Set(Object.values(this.zoneTopics))]; } process(topic, payload) { this.platform.log.debug(this.constructor.name, 'process', topic, payload); try { for (const zone in this.zoneTopics) { if (this.zoneTopics[zone] === topic) { const temperture = this.extractTemperature(zone, payload); this.platform.log.info(`MQTT: Extracted Temperature: ${temperture}`); if (temperture !== undefined) { this.platform.temperatureService.setTemperature(zone, temperture); } } } } catch (error) { if (error instanceof Error) { this.platform.log.error(error.message); } } } extractTemperature(zone, payload) { var _a; this.platform.log.debug(this.constructor.name, 'extractTemperature', zone, payload); try { let temperature; const path = (_a = this.platform.settings.mqtt) === null || _a === void 0 ? void 0 : _a.subscribeTemperature[`jsonPath${zone}`]; if (path === undefined || path === '') { temperature = Number(payload); return isNaN(temperature) ? undefined : temperature; } const json = JSON.parse(payload); const result = (0, jsonpath_plus_1.JSONPath)({ path: path, json }); if (Array.isArray(result) && result.length > 0) { temperature = Number(result[0]); return isNaN(temperature) ? undefined : temperature; } } catch (_b) { return; } } async publishTopics() { // Do nothing } } exports.TemperatureFormat = TemperatureFormat; //# sourceMappingURL=TemperatureFormat.js.map