diff options
| author | Li Zhineng <[email protected]> | 2025-07-18 15:38:53 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-07-18 15:38:53 +0800 |
| commit | 2cc02e8cc2e528bac77ca2cfa5af5040225775e5 (patch) | |
| tree | accb5c4931b53a7ac56c3eec8aed9869605ea7a3 /packages | |
| parent | 3c8a5afb2612d779fb1be4f7bf683f3bdf63599b (diff) | |
| download | airmx-2cc02e8cc2e528bac77ca2cfa5af5040225775e5.tar.gz airmx-2cc02e8cc2e528bac77ca2cfa5af5040225775e5.zip | |
instant push
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) { |
