UNPKG

homebridge-rinnai-touch-platform

Version:

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

66 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FaultFormat = void 0; const Fault_1 = require("../models/Fault"); class FaultFormat { constructor(platform, client) { this.platform = platform; this.client = client; this.topicPayload = new Map(); const prefix = this.platform.settings.mqtt.topicPrefix ? `${this.platform.settings.mqtt.topicPrefix}/` : ''; this.pubTopicFaultDetected = `${prefix}fault/detected/get`; this.pubTopicFaultMessage = `${prefix}fault/message/get`; // Publish on status change if (this.platform.settings.mqtt.publishStatusChanged) { this.platform.service.on('fault', this.publishFault.bind(this)); } } get subscriptionTopics() { return []; } process(topic, payload) { this.platform.log.debug(this.constructor.name, 'process', topic, payload); } async publishTopics() { this.platform.log.debug(this.constructor.name, 'publishTopics'); try { const status = this.platform.service.session.status; if (status !== undefined) { const fault = new Fault_1.Fault(status); this.publishFault(fault); } } catch (error) { if (error instanceof Error) { this.platform.log.error(error.message); } } } publishFault(fault) { this.platform.log.debug(this.constructor.name, 'publishFault', fault); this.publish(this.pubTopicFaultDetected, String(fault.detected)); this.publish(this.pubTopicFaultMessage, fault.toString()); } async publish(topic, payload) { this.platform.log.debug(this.constructor.name, 'publish', topic, payload); try { if (payload === this.topicPayload.get(topic) && !this.platform.settings.mqtt.publishAll) { return; } this.topicPayload.set(topic, payload); await this.client.publish(topic, payload, { retain: true }); if (this.platform.settings.mqtt.showMqttEvents) { this.platform.log.info(`MQTT: Publish: ${topic}, Payload: ${payload}`); } } catch (error) { if (error instanceof Error) { this.platform.log.error(error.message); } } } } exports.FaultFormat = FaultFormat; //# sourceMappingURL=FaultFormat.js.map