jmri-client 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/API.md +46 -1
- package/docs/EXAMPLES.md +31 -0
- package/docs/MOCK_MODE.md +16 -0
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -42,6 +42,12 @@ client.on('error', (error: Error) => { });
|
|
|
42
42
|
// Power events
|
|
43
43
|
client.on('power:changed', (state: PowerState) => { });
|
|
44
44
|
|
|
45
|
+
// Turnout events
|
|
46
|
+
client.on('turnout:changed', (name: string, state: TurnoutState) => { });
|
|
47
|
+
|
|
48
|
+
// Light events
|
|
49
|
+
client.on('light:changed', (name: string, state: LightState) => { });
|
|
50
|
+
|
|
45
51
|
// Throttle events
|
|
46
52
|
client.on('throttle:acquired', (throttleId: string) => { });
|
|
47
53
|
client.on('throttle:updated', (throttleId: string, data: any) => { });
|
|
@@ -106,6 +112,38 @@ const entry = await client.getRosterEntryByAddress(3);
|
|
|
106
112
|
const results = await client.searchRoster('steam');
|
|
107
113
|
```
|
|
108
114
|
|
|
115
|
+
## Light Control
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Get current light state
|
|
119
|
+
const state: LightState = await client.getLight('IL1');
|
|
120
|
+
|
|
121
|
+
// LightState enum values (from JMRI JSON protocol):
|
|
122
|
+
// LightState.UNKNOWN = 0 (state cannot be determined)
|
|
123
|
+
// LightState.ON = 2 (light is on)
|
|
124
|
+
// LightState.OFF = 4 (light is off)
|
|
125
|
+
|
|
126
|
+
// Set light state
|
|
127
|
+
await client.setLight('IL1', LightState.ON);
|
|
128
|
+
await client.turnOnLight('IL1'); // Convenience method
|
|
129
|
+
await client.turnOffLight('IL1'); // Convenience method
|
|
130
|
+
|
|
131
|
+
// List all lights
|
|
132
|
+
const lights: LightData[] = await client.listLights();
|
|
133
|
+
for (const light of lights) {
|
|
134
|
+
console.log(`${light.userName}: ${light.state === LightState.ON ? 'ON' : 'OFF'}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Cached state (no network request)
|
|
138
|
+
const cachedState = client.getLightState('IL1');
|
|
139
|
+
const allCached = client.getCachedLights();
|
|
140
|
+
|
|
141
|
+
// Listen for light changes
|
|
142
|
+
client.on('light:changed', (name: string, state: LightState) => {
|
|
143
|
+
console.log(`Light ${name} changed to ${state === LightState.ON ? 'ON' : 'OFF'}`);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
109
147
|
## Throttle Control
|
|
110
148
|
|
|
111
149
|
```typescript
|
|
@@ -165,12 +203,15 @@ const state = client.getConnectionState();
|
|
|
165
203
|
## Utility Functions
|
|
166
204
|
|
|
167
205
|
```typescript
|
|
168
|
-
import { powerStateToString, isThrottleFunctionKey, isValidSpeed } from 'jmri-client';
|
|
206
|
+
import { powerStateToString, lightStateToString, isThrottleFunctionKey, isValidSpeed } from 'jmri-client';
|
|
169
207
|
|
|
170
208
|
// Convert PowerState enum to readable string
|
|
171
209
|
const stateStr = powerStateToString(PowerState.ON); // 'ON'
|
|
172
210
|
const stateStr2 = powerStateToString(PowerState.UNKNOWN); // 'UNKNOWN'
|
|
173
211
|
|
|
212
|
+
// Convert LightState enum to readable string
|
|
213
|
+
const lightStr = lightStateToString(LightState.ON); // 'ON'
|
|
214
|
+
|
|
174
215
|
// Validate throttle function key
|
|
175
216
|
isThrottleFunctionKey('F0'); // true
|
|
176
217
|
isThrottleFunctionKey('F99'); // false
|
|
@@ -189,7 +230,11 @@ import {
|
|
|
189
230
|
JmriClient,
|
|
190
231
|
JmriClientOptions,
|
|
191
232
|
PowerState,
|
|
233
|
+
LightState,
|
|
234
|
+
LightData,
|
|
192
235
|
RosterEntry,
|
|
236
|
+
TurnoutState,
|
|
237
|
+
TurnoutData,
|
|
193
238
|
ThrottleState,
|
|
194
239
|
ThrottleFunctionKey,
|
|
195
240
|
ConnectionState
|
package/docs/EXAMPLES.md
CHANGED
|
@@ -113,6 +113,37 @@ client.on('connected', async () => {
|
|
|
113
113
|
});
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
## Light Control
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { JmriClient, LightState } from 'jmri-client';
|
|
120
|
+
|
|
121
|
+
const client = new JmriClient({ host: 'jmri.local' });
|
|
122
|
+
|
|
123
|
+
client.on('connected', async () => {
|
|
124
|
+
// List all lights
|
|
125
|
+
const lights = await client.listLights();
|
|
126
|
+
console.log(`Found ${lights.length} lights`);
|
|
127
|
+
|
|
128
|
+
for (const light of lights) {
|
|
129
|
+
console.log(` ${light.userName ?? light.name}: ${light.state === LightState.ON ? 'ON' : 'OFF'}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Turn a light on
|
|
133
|
+
await client.turnOnLight('IL1');
|
|
134
|
+
console.log('Light IL1 turned ON');
|
|
135
|
+
|
|
136
|
+
// Turn it off again
|
|
137
|
+
await client.turnOffLight('IL1');
|
|
138
|
+
console.log('Light IL1 turned OFF');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Monitor light changes in real-time
|
|
142
|
+
client.on('light:changed', (name, state) => {
|
|
143
|
+
console.log(`Light ${name} is now ${state === LightState.ON ? 'ON' : 'OFF'}`);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
116
147
|
## Roster Search
|
|
117
148
|
|
|
118
149
|
```typescript
|
package/docs/MOCK_MODE.md
CHANGED
|
@@ -72,6 +72,18 @@ Three sample locomotives:
|
|
|
72
72
|
|
|
73
73
|
Each includes realistic function key mappings (F0-F4).
|
|
74
74
|
|
|
75
|
+
### Lights
|
|
76
|
+
Three sample lights:
|
|
77
|
+
- **IL1** - Yard Light (OFF)
|
|
78
|
+
- **IL2** - Platform Light (OFF)
|
|
79
|
+
- **IL3** - Signal Lamp (ON)
|
|
80
|
+
|
|
81
|
+
### Turnouts
|
|
82
|
+
Three sample turnouts:
|
|
83
|
+
- **LT1** - Main Diverge (CLOSED)
|
|
84
|
+
- **LT2** - Yard Lead (CLOSED)
|
|
85
|
+
- **LT3** - Siding Entry (THROWN)
|
|
86
|
+
|
|
75
87
|
### Throttle Responses
|
|
76
88
|
Supports all throttle operations:
|
|
77
89
|
- Acquire/release
|
|
@@ -152,6 +164,8 @@ const response = await mockManager.getMockResponse({
|
|
|
152
164
|
The mock system maintains state for realistic behavior:
|
|
153
165
|
|
|
154
166
|
- **Power state** - Remembers if power is ON or OFF
|
|
167
|
+
- **Light states** - Tracks ON/OFF state per light
|
|
168
|
+
- **Turnout states** - Tracks CLOSED/THROWN state per turnout
|
|
155
169
|
- **Throttles** - Tracks acquired throttles and their states
|
|
156
170
|
- **Speed/Direction** - Maintains current speed and direction per throttle
|
|
157
171
|
- **Functions** - Tracks function key states (F0-F28)
|
|
@@ -196,6 +210,8 @@ Mock mode implements the full JMRI client API. All methods work identically:
|
|
|
196
210
|
- ✅ `connect()` / `disconnect()`
|
|
197
211
|
- ✅ `getPower()` / `powerOn()` / `powerOff()`
|
|
198
212
|
- ✅ `getRoster()`
|
|
213
|
+
- ✅ `getLight()` / `setLight()` / `turnOnLight()` / `turnOffLight()` / `listLights()`
|
|
214
|
+
- ✅ `getTurnout()` / `setTurnout()` / `throwTurnout()` / `closeTurnout()` / `listTurnouts()`
|
|
199
215
|
- ✅ `acquireThrottle()` / `releaseThrottle()`
|
|
200
216
|
- ✅ `setThrottleSpeed()`
|
|
201
217
|
- ✅ `setThrottleDirection()`
|
package/package.json
CHANGED