commit a5e5a70c09f75cd8e0842ef969b6c31b40450576
parent cbd311c96b80fbb8a464a5aa6b651649d65a5857
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Feb 2021 12:38:32 +0100
parent cbd311c96b80fbb8a464a5aa6b651649d65a5857
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Feb 2021 12:38:32 +0100
support for new devices
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/state.js b/src/state.js @@ -52,22 +52,25 @@ class State { _initWS() { // this.ws = new WebSocket(`${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.hostname}/${window.location.pathname.split("/").slice(0, -1).join("/")}/ws`); - this.ws = new WebSocket('wss://home.ctu.cx/ws'); + this.ws = new WebSocket('ws://localhost:5000/ws'); this.ws.onclose = () => { this.connected = false; this._initWS(); this._updateSubscribers(); + console.log("connection was closed!") }; this.ws.onopen = () => { this.connected = true; this._updateSubscribers(); this.ws.send(JSON.stringify({ type: "GetClientConfigAction", + deviceName: "", configName: "smarthome-pwa", accessToken: this.accessToken })); this.ws.send(JSON.stringify({ type: "SetSubscriptionStateAction", + deviceName: "", subscribed: true, accessToken: this.accessToken })); @@ -77,7 +80,8 @@ class State { this._timeout = setTimeout(() => { this.ws.close(); this.ws.onclose(); - }, 2000); + console.log("got no ping!") + }, 5000); if (!msg.data.length) return; // keepalive this._setData(JSON.parse(msg.data)); };
diff --git a/src/switches.js b/src/switches.js @@ -23,10 +23,10 @@ class Switches extends LitElement { const sw = row.querySelector("mwc-switch"); sw.checked = !sw.checked; state.ws.send(JSON.stringify({ - type: "SetRelayAction", - setRelayBoard: sw.relayboard, - setRelay: sw.relay, - setValue: sw.checked, + type: "SwitchStateAction", + deviceName: sw.deviceName, + relay: sw.relayNum, + state: sw.checked, accessToken: state.accessToken })); if (evt.clientX !== 0 || evt.clientY !== 0) sw.blur(); @@ -41,7 +41,9 @@ class Switches extends LitElement { <smarthome-row @click="${this._clickHandler}" ?disabled="${!state.connected}"> <span slot="left">${sw.name}</span> <mwc-ripple slot="center"></mwc-ripple> - <mwc-switch slot="right" .relayboard="${sw.device}" .relay="${sw.relay}" ?disabled="${!state.connected}" ?checked="${state.data[sw.device].relays[sw.relay]}"></mwc-switch> + ${state.data[sw.device].type == "RelayBoard" ? html`<mwc-switch slot="right" .deviceName="${sw.device}" .relayNum="${sw.relay}" ?disabled="${!state.connected}" ?checked="${state.data[sw.device].relays[sw.relay]}"></mwc-switch>` : html``} + ${state.data[sw.device].type == "Zigbee2MqttLamp" ? html`<mwc-switch slot="right" .deviceName="${sw.device}" ?disabled="${!state.connected}" ?checked="${state.data[sw.device].lampState}"></mwc-switch>` : html``} + ${state.data[sw.device].type == "Zigbee2MqttRelay" ? html`<mwc-switch slot="right" .deviceName="${sw.device}" ?disabled="${!state.connected}" ?checked="${state.data[sw.device].relayState}"></mwc-switch>` : html``} </smarthome-row> `)} </smarthome-card>