@jakobgoerke/ac-infinity-client 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +258 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,259 @@
1
1
  # ac-infinity-client
2
+
3
+ [![npm](https://img.shields.io/npm/v/@jakobgoerke/ac-infinity-client)](https://www.npmjs.com/package/@jakobgoerke/ac-infinity-client)
4
+ [![build & test](https://github.com/jakobgoerke/ac-infinity-client/actions/workflows/build.yml/badge.svg)](https://github.com/jakobgoerke/ac-infinity-client/actions/workflows/build.yml)
5
+ [![license](https://img.shields.io/npm/l/@jakobgoerke/ac-infinity-client)](LICENSE)
6
+
7
+ A typed Node.js client for the [AC Infinity](https://acinfinity.com) cloud API, the same backend the AC Infinity app uses. Use it to read your
8
+ UIS controllers, their ports and sensors, and to change device and mode settings from your own code.
9
+
10
+ - **Typed**: responses are validated with [zod](https://zod.dev) and turned into readable objects (`levelWhileOn` instead of `onSpead`).
11
+ - **Decoded values**: temperatures, humidity, VPD and sensor readings come back in real units, not vendor-scaled integers.
12
+ - **Partial updates**: send only the fields you want to change. The client fetches the current settings and merges your changes in.
13
+ - **Device detection**: ports without an assigned device type are identified by the ID resistor in the plug.
14
+
15
+ > [!NOTE]
16
+ > This is an unofficial project and is not affiliated with AC Infinity. The API is undocumented and may change without notice.
17
+
18
+ ## Installation
19
+
20
+ ```sh
21
+ npm install @jakobgoerke/ac-infinity-client
22
+ # or
23
+ yarn add @jakobgoerke/ac-infinity-client
24
+ ```
25
+
26
+ Requires Node.js 24 or newer.
27
+
28
+ ## Quick start
29
+
30
+ ```ts
31
+ import { AcInfinityClient, DeviceMode } from '@jakobgoerke/ac-infinity-client';
32
+
33
+ // build() creates the client and logs in
34
+ const client = await AcInfinityClient.build({
35
+ email: 'you@example.com',
36
+ password: 'your-password',
37
+ });
38
+
39
+ const [controller] = await client.getControllers();
40
+ console.log(`${controller.name}: ${controller.deviceInfo.temperature} °C, ${controller.deviceInfo.humidity} %`);
41
+
42
+ for (const port of controller.deviceInfo.ports) {
43
+ console.log(`Port ${port.port} (${port.deviceName}) is at level ${port.currentLevel}`);
44
+ }
45
+
46
+ // turn the fan on port 1 on at level 6
47
+ await client.setDeviceModeSettings({
48
+ controllerId: controller.id,
49
+ port: 1,
50
+ settings: { mode: DeviceMode.ON, levelWhileOn: 6 },
51
+ });
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ ### Authentication
57
+
58
+ `AcInfinityClient.build()` creates a client and logs in right away. If you want to log in later, create the client with `new` and call
59
+ `authenticate()` yourself:
60
+
61
+ ```ts
62
+ const client = new AcInfinityClient({ email, password });
63
+ const user = await client.authenticate(); // { id, username, email }
64
+ ```
65
+
66
+ If the credentials are rejected, an `AuthenticationError` is thrown.
67
+
68
+ > [!WARNING]
69
+ > The user `id` returned by `authenticate()` is also the API token: it is sent with every request, and anyone who has it can control your
70
+ > devices. Treat it like your password and keep it out of logs, issues and screenshots. The vendor API is served over plain HTTP, so the
71
+ > token travels unencrypted.
72
+
73
+ ### Controllers
74
+
75
+ ```ts
76
+ const controllers = await client.getControllers(); // controllers on your account
77
+ const shared = await client.getSharedControllers(); // controllers others shared with you
78
+ const controller = await client.getController({ controllerId: controllers[0].id });
79
+ ```
80
+
81
+ A controller looks like this (abridged):
82
+
83
+ ```ts
84
+ {
85
+ id: '1234567890123456789',
86
+ name: 'Grow Tent',
87
+ type: ControllerDeviceType.UIS_CONTROLLER_69_PRO,
88
+ totalPorts: 4,
89
+ online: true,
90
+ firmwareVersion: '3.2.25',
91
+ deviceInfo: {
92
+ temperature: 24.5, // °C
93
+ temperatureF: 76.1, // °F, null if not reported
94
+ humidity: 58.3, // %
95
+ vpd: 1.28, // kPa
96
+ ports: [
97
+ {
98
+ port: 1,
99
+ deviceName: 'Exhaust Fan',
100
+ deviceType: DeviceType.FAN,
101
+ currentMode: DeviceMode.AUTO,
102
+ currentLevel: 4,
103
+ online: true,
104
+ remainingTime: null, // seconds until the next timer / cycle / schedule switch
105
+ },
106
+ ],
107
+ sensors: [
108
+ { port: 1, type: SensorType.CO2, value: 812 }, // value is null when the sensor has no reading
109
+ ],
110
+ },
111
+ }
112
+ ```
113
+
114
+ ### Ports
115
+
116
+ Settings are addressed by `controllerId` and `port`. Port `0` is the controller itself, ports `1` to `n` are the devices plugged into it.
117
+
118
+ ### Mode settings
119
+
120
+ Mode settings control what a device does: its mode, its levels, and the triggers for timer, cycle, schedule, auto and VPD modes.
121
+
122
+ ```ts
123
+ const modes = await client.getDeviceModeSettings({ controllerId, port: 1 });
124
+
125
+ modes.mode; // DeviceMode.AUTO
126
+ modes.levelWhileOn; // 0–10
127
+ modes.auto.highTemperature; // { enabled: true, celsius: 28, fahrenheit: 82 }
128
+ modes.vpd.target; // { enabled: false, value: 1.2 } (kPa)
129
+ modes.schedule; // { start: 480, end: 1200 } (minutes after midnight)
130
+ ```
131
+
132
+ Only the fields you pass to `setDeviceModeSettings()` are changed:
133
+
134
+ ```ts
135
+ // run the fan in auto mode when it gets hotter than 28 °C or more humid than 65 %
136
+ await client.setDeviceModeSettings({
137
+ controllerId,
138
+ port: 1,
139
+ settings: {
140
+ mode: DeviceMode.AUTO,
141
+ levelWhileOn: 8,
142
+ levelWhileOff: 1,
143
+ auto: {
144
+ highTemperature: { enabled: true, celsius: 28 },
145
+ highHumidity: { enabled: true, value: 65 },
146
+ },
147
+ },
148
+ });
149
+
150
+ // switch the light on at 08:00 and off at 20:00
151
+ await client.setDeviceModeSettings({
152
+ controllerId,
153
+ port: 2,
154
+ settings: {
155
+ mode: DeviceMode.SCHEDULE,
156
+ schedule: { start: 8 * 60, end: 20 * 60 },
157
+ },
158
+ });
159
+
160
+ // 15 minutes on, 45 minutes off
161
+ await client.setDeviceModeSettings({
162
+ controllerId,
163
+ port: 3,
164
+ settings: {
165
+ mode: DeviceMode.CYCLE,
166
+ cycle: { on: 15 * 60, off: 45 * 60 },
167
+ },
168
+ });
169
+ ```
170
+
171
+ | Setting | Unit / range |
172
+ | ---------------------------------------------------- | -------------------------------------------------------------- |
173
+ | `levelWhileOn`, `levelWhileOff` | 0–10 |
174
+ | `timer.toOn`, `timer.toOff`, `cycle.on`, `cycle.off` | seconds |
175
+ | `schedule.start`, `schedule.end` | minutes after midnight (0–1439), `null` to clear |
176
+ | temperature triggers | `celsius` (0–90) **or** `fahrenheit` (32–194), the other is computed |
177
+ | humidity triggers | percent (0–100) |
178
+ | VPD triggers | kPa (0–9.9) |
179
+
180
+ ### Device settings
181
+
182
+ Device settings are the general settings of a port or the controller: name, temperature unit, display brightness, backlight and sensor
183
+ calibration.
184
+
185
+ ```ts
186
+ const settings = await client.getDeviceSettings({ controllerId, port: 0 });
187
+
188
+ settings.name; // 'Grow Tent'
189
+ settings.temperatureUnit; // TemperatureUnit.CELSIUS
190
+ settings.calibration; // { temperatureC, temperatureF, humidity, leafTemperatureC, leafTemperatureF }
191
+
192
+ await client.setDeviceSettings({
193
+ controllerId,
194
+ port: 0,
195
+ settings: {
196
+ name: 'Grow Tent',
197
+ temperatureUnit: TemperatureUnit.CELSIUS,
198
+ backlight: true,
199
+ calibration: { temperatureC: -1, humidity: 2 },
200
+ },
201
+ });
202
+ ```
203
+
204
+ As with temperature triggers, give the temperature calibration in either `temperatureC` or `temperatureF`. The other value is computed for you.
205
+
206
+ ### Errors
207
+
208
+ | Error | When |
209
+ | --------------------- | ---------------------------------------------------------------------------------------- |
210
+ | `AuthenticationError` | The login was rejected. |
211
+ | `ApiError` | The API answered with a non-200 code. The error carries the vendor's `code` and `msg`. |
212
+ | `ZodError` | A response didn't match the expected shape, or the changes you passed are out of range. |
213
+
214
+ ```ts
215
+ import { ApiError } from '@jakobgoerke/ac-infinity-client';
216
+
217
+ try {
218
+ await client.getController({ controllerId: 'unknown' });
219
+ } catch (error) {
220
+ if (error instanceof ApiError) {
221
+ console.error(error.code, error.msg);
222
+ }
223
+ }
224
+ ```
225
+
226
+ ## API reference
227
+
228
+ | Method | Returns |
229
+ | -------------------------------------------------------- | ----------------------------- |
230
+ | `AcInfinityClient.build({ email, password })` | `Promise<AcInfinityClient>` |
231
+ | `authenticate()` | `Promise<User>` |
232
+ | `getControllers()` | `Promise<Controller[]>` |
233
+ | `getSharedControllers()` | `Promise<Controller[]>` |
234
+ | `getController({ controllerId })` | `Promise<Controller>` |
235
+ | `getDeviceSettings({ controllerId, port })` | `Promise<DeviceSettings>` |
236
+ | `setDeviceSettings({ controllerId, port, settings })` | `Promise<void>` |
237
+ | `getDeviceModeSettings({ controllerId, port })` | `Promise<DeviceModeSettings>` |
238
+ | `setDeviceModeSettings({ controllerId, port, settings })`| `Promise<void>` |
239
+
240
+ The package also exports the enums `ControllerDeviceType`, `DeviceType`, `DeviceMode`, `SensorType` and `TemperatureUnit`, and the types
241
+ `Controller`, `ControllerDeviceInfo`, `ControllerPort`, `ControllerSensor`, `DeviceSettings`, `DeviceSettingsChanges`, `DeviceModeSettings`,
242
+ `DeviceModeSettingsChanges` and `User`.
243
+
244
+ ## Development
245
+
246
+ ```sh
247
+ corepack enable
248
+ yarn install
249
+ yarn test # run the tests
250
+ yarn coverage # run the tests with coverage
251
+ yarn lint # check formatting and lint rules with Biome
252
+ yarn build # compile to ./build
253
+ ```
254
+
255
+ New versions are published to npm by CI when a tag is pushed.
256
+
257
+ ## License
258
+
259
+ [GPL-3.0-or-later](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakobgoerke/ac-infinity-client",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "./build/src",
5
5
  "types": "./build/src/index.d.ts",
6
6
  "repository": "git@github.com:jakobgoerke/ac-infinity-client.git",