From 875f200c39bdc3009424fd881a288c104c333202 Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Mon, 11 Sep 2017 14:45:52 -0600 Subject: [PATCH] Progress --- app/mqtt.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app/mqtt.ts b/app/mqtt.ts index 8ad4b60..9e6de78 100644 --- a/app/mqtt.ts +++ b/app/mqtt.ts @@ -100,6 +100,16 @@ export class MqttApiClient implements ISprinklersApi { } } +const subscriptions = [ + "/connected", + "/sections", + "/sections/+/#", + "/programs", + "/programs/+/#", + "/responses/+", + "/section_runner", +]; + class MqttSprinklersDevice extends SprinklersDevice { readonly apiClient: MqttApiClient; readonly prefix: string; @@ -119,28 +129,16 @@ class MqttSprinklersDevice extends SprinklersDevice { return this.prefix; } - private get subscriptions() { - return [ - `${this.prefix}/connected`, - `${this.prefix}/sections`, - `${this.prefix}/sections/+/#`, - `${this.prefix}/programs`, - `${this.prefix}/programs/+/#`, - `${this.prefix}/responses/+`, - `${this.prefix}/section_runner`, - ]; - } - doSubscribe() { const c = this.apiClient.client; - this.subscriptions - .forEach((filter) => c.subscribe(filter, { qos: 1 })); + subscriptions + .forEach((filter) => c.subscribe(this.prefix + filter, { qos: 1 })); } doUnsubscribe() { const c = this.apiClient.client; - this.subscriptions - .forEach((filter) => c.unsubscribe(filter)); + subscriptions + .forEach((filter) => c.unsubscribe(this.prefix + filter)); } /** @@ -200,7 +198,7 @@ class MqttSprinklersDevice extends SprinklersDevice { //noinspection JSUnusedLocalSymbols /* tslint:disable-next-line:no-unused-variable */ const [_topic, respIdStr] = matches; - console.log(`response: ${respIdStr}`); + // console.log(`response: ${respIdStr}`); const respId = parseInt(respIdStr, 10); const data = JSON.parse(payload) as IResponseData; const cb = this.responseCallbacks[respId];