UNPKG

homebridge-rinnai-touch-platform

Version:

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

67 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConnectionFormat = void 0; class ConnectionFormat { constructor(platform, client) { this.platform = platform; this.client = client; const prefix = this.platform.settings.mqtt.topicPrefix ? `${this.platform.settings.mqtt.topicPrefix}/` : ''; this.pubTopic = `${prefix}connection/status/get`; // Publish on status change if (this.platform.settings.mqtt.publishStatusChanged) { this.platform.service.session.on('connection', () => { this.publishStatus(); }); } } 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 { this.publishStatus(); } catch (error) { if (error instanceof Error) { this.platform.log.error(error.message); } } } publishStatus() { this.platform.log.debug(this.constructor.name, 'publishStatus'); if (this.connectionError === this.platform.service.session.hasConnectionError) { return; } this.connectionError = this.platform.service.session.hasConnectionError; const payload = this.connectionError ? 'error' : 'ok'; this.publish(this.pubTopic, payload); } async publish(topic, payload) { this.platform.log.debug(this.constructor.name, 'publish', topic, payload); try { if (payload === this.topicPayload && !this.platform.settings.mqtt.publishAll) { return; } this.topicPayload = 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.ConnectionFormat = ConnectionFormat; //# sourceMappingURL=ConnectionFormat.js.map