From 2cc02e8cc2e528bac77ca2cfa5af5040225775e5 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Fri, 18 Jul 2025 15:38:53 +0800 Subject: instant push --- packages/airmx/src/airmx.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'packages') 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) { + 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) { -- cgit v1.2.3