"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const logger = require("./log"); const MqttDispatcher_1 = require("./MqttDispatcher"); const AItem_1 = require("./AItem"); const Export_1 = require("./Export"); const http = require("http"); class UrlSwitchItem extends AItem_1.AItem { getStateTopic() { return this.stateTopic; } getStateFeedbackTopic() { return this.stateFeedbackTopic; } constructor(floor, room, item, label, onUrl, offUrl, type = 'bulb') { super(floor, room, item, label); this.stateTopic = `${this.topicFirstPart}/state`; this.subscribeTopics = [this.stateTopic]; this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`; this.actionTopic = 'IoT/Mqtt433Gateway/Message'; this.state = 'OFF'; this.oldState = undefined; this.onUrl = onUrl; this.offUrl = offUrl; this.type = type; } exportItem() { return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type); } processMessage(topic, payload) { this.state = payload; MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); if (this.state != this.oldState) { try { if (this.state == 'ON') { http.get(this.onUrl); } else { http.get(this.offUrl); } this.oldState = this.state; } catch (_a) { logger.error(`Failed to handle ${this.onUrl} or ${this.offUrl}`); } } } } exports.UrlSwitchItem = UrlSwitchItem; //# sourceMappingURL=UrlSwitchItem.js.map