summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorLi Zhineng <[email protected]>2025-07-18 11:10:54 +0800
committerLi Zhineng <[email protected]>2025-07-18 11:10:54 +0800
commite4bafbe2a341ce33fbfb485c1878226653375983 (patch)
treea18df9e5a454a3ccc6a00ef62610fb00d48eddc4 /packages
parent2801f9c059eebfcfb9cecc927bbacf204aee4329 (diff)
downloadairmx-e4bafbe2a341ce33fbfb485c1878226653375983.tar.gz
airmx-e4bafbe2a341ce33fbfb485c1878226653375983.zip
refactor command IDs
Diffstat (limited to 'packages')
-rw-r--r--packages/airmx/src/airmx.ts5
-rw-r--r--packages/airmx/src/eagle.ts8
-rw-r--r--packages/airmx/src/snow.ts9
-rw-r--r--packages/airmx/src/types.ts5
4 files changed, 14 insertions, 13 deletions
diff --git a/packages/airmx/src/airmx.ts b/packages/airmx/src/airmx.ts
index 5b397db..8c30049 100644
--- a/packages/airmx/src/airmx.ts
+++ b/packages/airmx/src/airmx.ts
@@ -9,7 +9,6 @@ import type {
EagleListener,
EagleControlData,
} from './types.js'
-import { Command } from './types.js'
import { Signer } from './util.js'
import type { CommandMessage } from './messages.js'
@@ -111,10 +110,10 @@ export class Airmx {
this.#validateMessage(t.deviceId, str, data.sig)
switch (data.cmdId) {
- case Command.SnowStatus:
+ case SnowStatus.commandId():
this.#notifySnow(SnowStatus.from(t.deviceId, data))
break
- case Command.EagleStatus:
+ case EagleStatus.commandId():
this.#notifyEagle(EagleStatus.from(t.deviceId, data))
break
}
diff --git a/packages/airmx/src/eagle.ts b/packages/airmx/src/eagle.ts
index b3f28e3..124222b 100644
--- a/packages/airmx/src/eagle.ts
+++ b/packages/airmx/src/eagle.ts
@@ -7,9 +7,13 @@ export class EagleStatus {
public readonly message: Message<EagleStatusData>,
) {}
+ static commandId() {
+ return 210
+ }
+
static from(deviceId: number, message: Message<EagleStatusData>) {
- if (message.cmdId !== 210) {
- throw new Error('Eagle status expects a message with command ID 210.')
+ if (message.cmdId !== this.commandId()) {
+ throw new Error(`Eagle status expects a message with command ID ${this.commandId()}.`)
}
return new this(deviceId, message)
diff --git a/packages/airmx/src/snow.ts b/packages/airmx/src/snow.ts
index 38242fa..3517dcd 100644
--- a/packages/airmx/src/snow.ts
+++ b/packages/airmx/src/snow.ts
@@ -1,5 +1,4 @@
import {
- Command,
type Message,
type SnowStatusData,
BatteryState,
@@ -14,10 +13,14 @@ export class SnowStatus {
//
}
+ static commandId() {
+ return 200
+ }
+
static from(deviceId: number, message: Message<SnowStatusData>) {
- if (message.cmdId !== Command.SnowStatus) {
+ if (message.cmdId !== this.commandId()) {
throw new Error(
- `Snow status expects a message with command ID "${Command.SnowStatus}".`,
+ `Snow status expects a message with command ID "${this.commandId()}".`,
)
}
diff --git a/packages/airmx/src/types.ts b/packages/airmx/src/types.ts
index 6d6bbc7..ef7ab89 100644
--- a/packages/airmx/src/types.ts
+++ b/packages/airmx/src/types.ts
@@ -15,11 +15,6 @@ export interface Device {
export type SnowListener = (status: SnowStatus) => void
export type EagleListener = (status: EagleStatus) => void
-export enum Command {
- SnowStatus = 200,
- EagleStatus = 210,
-}
-
export enum MessageSource {
Snow = 1,
Eagle = 2,