Browse Source

Progress

update-deps
Alex Mikhalev 7 years ago
parent
commit
875f200c39
  1. 32
      app/mqtt.ts

32
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 { class MqttSprinklersDevice extends SprinklersDevice {
readonly apiClient: MqttApiClient; readonly apiClient: MqttApiClient;
readonly prefix: string; readonly prefix: string;
@ -119,28 +129,16 @@ class MqttSprinklersDevice extends SprinklersDevice {
return this.prefix; 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() { doSubscribe() {
const c = this.apiClient.client; const c = this.apiClient.client;
this.subscriptions subscriptions
.forEach((filter) => c.subscribe(filter, { qos: 1 })); .forEach((filter) => c.subscribe(this.prefix + filter, { qos: 1 }));
} }
doUnsubscribe() { doUnsubscribe() {
const c = this.apiClient.client; const c = this.apiClient.client;
this.subscriptions subscriptions
.forEach((filter) => c.unsubscribe(filter)); .forEach((filter) => c.unsubscribe(this.prefix + filter));
} }
/** /**
@ -200,7 +198,7 @@ class MqttSprinklersDevice extends SprinklersDevice {
//noinspection JSUnusedLocalSymbols //noinspection JSUnusedLocalSymbols
/* tslint:disable-next-line:no-unused-variable */ /* tslint:disable-next-line:no-unused-variable */
const [_topic, respIdStr] = matches; const [_topic, respIdStr] = matches;
console.log(`response: ${respIdStr}`); // console.log(`response: ${respIdStr}`);
const respId = parseInt(respIdStr, 10); const respId = parseInt(respIdStr, 10);
const data = JSON.parse(payload) as IResponseData; const data = JSON.parse(payload) as IResponseData;
const cb = this.responseCallbacks[respId]; const cb = this.responseCallbacks[respId];

Loading…
Cancel
Save