diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/airmx/src/airmx.ts | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/airmx/src/airmx.ts b/packages/airmx/src/airmx.ts index 5e933ba..1050bf0 100644 --- a/packages/airmx/src/airmx.ts +++ b/packages/airmx/src/airmx.ts @@ -9,7 +9,7 @@ import type { } from './types.js' import type { CommandMessage } from './messages.js' -import { EagleControlMesasge } from './messages.js' +import { EagleControlMesasge, InstantPushMessage } from './messages.js' import { EagleController, EagleStatus } from './eagle.js' import { Signer } from './util.js' import { SnowStatus } from './snow.js' @@ -102,6 +102,11 @@ export class Airmx { #handleConnect() { this.#client.subscribe('airmx/01/+/+/1/1/+') + + // After successfully connecting to the MQTT server, we need to retrieve + // the latest statuses for all devices instead of waiting for them to + // notify us. It also enables us to make partial tweaks to devices. + this.#dispatchAll(InstantPushMessage.make(2, 1)) } #handleMessage(topic: string, message: Buffer): void { @@ -158,6 +163,12 @@ export class Airmx { ) } + #dispatchAll(message: CommandMessage<unknown>) { + for (const device of this.config.devices) { + this.#dispatch(device.id, message) + } + } + #getDevice(deviceId: number) { const device = this.config.devices.find((device) => device.id === deviceId) if (device === undefined) { |
