daikin-airbase 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lake
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # TypeScript Daikin Airbase Library
2
+ This library is used to communicate with Daikin Airbase devices.
3
+
4
+ ## Supported Devices
5
+
6
+ - Wireless LAN connecting Adaptor for Ducted Split Systems
7
+ - 🇦🇺 `BRP15B61`
8
+
9
+ > [!TIP]
10
+ > Does this library support your system? Please add your model number and country flag here!
11
+
12
+ ## Supported Features
13
+ The following features have been tested
14
+ - Get/Set Temperature
15
+ - Get/Set Fan Speed
16
+ - Get/Set Power
17
+ - Get/Set Mode
18
+ - Get/Set Zones On/Off
19
+
20
+ ## Not Yet Implemented
21
+ The following features are not yet implemented.
22
+ A lot of these are not supported by my particular device. Some i just didn't need to implement.
23
+
24
+ **Pull Requests are welcome!**
25
+ - Get/Set Humidity
26
+ - Get/Set Zones Temperature
27
+ - Get/Set Zones Humidity
28
+ - Timers
29
+
30
+ ## Usage
31
+ There are a collection of examples in the `examples` folder. As a very basic example:
32
+ ```typescript
33
+ import {DaikinClient} from "../src";
34
+ const client = new DaikinClient({ host: EXAMPLE_HOST });
35
+ await client.setTargetTemprature(24);
36
+ ```
37
+
38
+ ## Security and Warranty
39
+ This library is not affiliated with Daikin. I take no responsibility for any damages caused by this library. Use at your own risk.
40
+
41
+ Issues within the endpoints provided by Daikin are not covered by this library. Any security concerns should be disclosed to Daikin.
42
+
43
+ > [!WARNING]
44
+ > Daikin exposes your wifi password in plain text with the get_wifi_setting.
45
+ > Make sure you don't connect your system to the internet!
46
+
47
+ ## Development
48
+ All contributions are welcome! Please make sure everything is tested on your own device before submitting a pull request.
49
+
50
+ There is no real strict style guide, but please try to follow the existing code.
51
+ - Raw endpoints should be in the `src/api/` and the client should wrap and map them to nicer objects in `src/`
52
+ - A list of all available endpoints can be found in [ENDPOINTS.md](https://github.com/Lachee/daikin-airbase/blob/main/ENDPOINTS.md).
53
+ - These were extracted from the [App's](https://play.google.com/store/apps/details?id=au.com.daikin.airbase&hl=en_AU) strings.
package/dist/index.cjs ADDED
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ API: () => API,
34
+ DaikinClient: () => DaikinClient,
35
+ basic_info: () => basic_info,
36
+ discover: () => discover,
37
+ get_zone_settings: () => get_zone_settings
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/ParamParser.ts
42
+ function parse(str) {
43
+ const result = {};
44
+ const parts = str.split(",");
45
+ for (const part of parts) {
46
+ const [key, value] = part.split("=");
47
+ if (key === void 0) continue;
48
+ const maybeNumber = Number(value);
49
+ if (Number.isNaN(maybeNumber)) {
50
+ result[key] = decodeURIComponent(`${value}`);
51
+ } else {
52
+ result[key] = maybeNumber;
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+
58
+ // src/api/API.ts
59
+ var import_node_http = __toESM(require("http"), 1);
60
+ var API = class {
61
+ host;
62
+ constructor(host) {
63
+ this.host = host;
64
+ }
65
+ async request(endpoint, parameters) {
66
+ const body = await new Promise((resolve, reject) => {
67
+ const url = new URL(`/skyfi${endpoint}`, `http://${this.host}/`);
68
+ const queries = [];
69
+ if (parameters) {
70
+ for (const key in parameters) {
71
+ const value = parameters[key];
72
+ if (value === void 0) continue;
73
+ const encoded = encodeURIComponent(`${value || ""}`);
74
+ queries.push(`${key}=${encoded}`);
75
+ }
76
+ }
77
+ const search = queries.length > 0 ? `?${queries.join("&")}` : "";
78
+ const req = import_node_http.default.request(
79
+ {
80
+ host: url.hostname,
81
+ port: url.port,
82
+ path: url.pathname + search,
83
+ // important
84
+ method: "GET",
85
+ headers: {
86
+ Accept: "*/*",
87
+ Connection: "close"
88
+ }
89
+ },
90
+ (res) => {
91
+ let data = "";
92
+ res.setEncoding("utf8");
93
+ res.on("data", (c) => data += c);
94
+ res.on("end", () => resolve(data));
95
+ }
96
+ );
97
+ req.on("error", reject);
98
+ req.end();
99
+ });
100
+ return parse(body);
101
+ }
102
+ };
103
+
104
+ // src/api/Discover.ts
105
+ var import_node_dgram = __toESM(require("dgram"), 1);
106
+ var DISCOVERY_PORT = 30050;
107
+ var DISCOVERY_ADDRESS = "255.255.255.255";
108
+ function discover(timeoutMs = 3e3) {
109
+ return new Promise((resolve, reject) => {
110
+ const availableUnits = /* @__PURE__ */ new Map();
111
+ const socket = import_node_dgram.default.createSocket("udp4");
112
+ const payload = Buffer.from("DAIKIN_UDP/common/basic_info", "utf8");
113
+ const finish = () => {
114
+ socket.close();
115
+ resolve([...availableUnits.values()]);
116
+ };
117
+ socket.once("error", (err) => {
118
+ socket.close();
119
+ reject(err);
120
+ });
121
+ socket.on("message", (msg, rinfo) => {
122
+ const raw = msg.toString("utf8");
123
+ const info = parse(raw);
124
+ const key = `${info.mac || info.id || rinfo.address}`;
125
+ availableUnits.set(key, {
126
+ discoveredAddress: rinfo.address,
127
+ discoveredPort: rinfo.port,
128
+ ...info
129
+ });
130
+ });
131
+ socket.bind(0, "0.0.0.0", () => {
132
+ try {
133
+ socket.setBroadcast(true);
134
+ socket.send(payload, DISCOVERY_PORT, DISCOVERY_ADDRESS, (err) => {
135
+ if (err) {
136
+ socket.close();
137
+ reject(err);
138
+ return;
139
+ }
140
+ setTimeout(finish, timeoutMs);
141
+ });
142
+ } catch (err) {
143
+ socket.close();
144
+ reject(err);
145
+ }
146
+ });
147
+ });
148
+ }
149
+
150
+ // src/api/common/basic_info.ts
151
+ var basic_info = (http2) => http2.request("/common/basic_info");
152
+
153
+ // src/api/aircon/get_zone_setting.ts
154
+ var get_zone_settings = (http2) => http2.request("/aircon/get_zone_setting");
155
+
156
+ // src/api/aircon/set_zone_setting.ts
157
+ var set_zone_setting = (http2, params) => http2.request("/aircon/set_zone_setting", params);
158
+
159
+ // src/Zones.ts
160
+ var Zones = class {
161
+ zones = [];
162
+ client;
163
+ constructor(client) {
164
+ this.client = client;
165
+ }
166
+ /** Refreshes the cached zone state */
167
+ async refresh() {
168
+ const response = await get_zone_settings(this.client.api);
169
+ const zoneNames = response.zone_name.split(";");
170
+ const zoneState = response.zone_onoff.split(";");
171
+ return this.zones = zoneNames.map((name, index) => ({
172
+ name,
173
+ state: zoneState[index] === "1"
174
+ }));
175
+ }
176
+ /**
177
+ * Gets the state of all cached zones.
178
+ */
179
+ getCachedZones() {
180
+ return [...this.zones];
181
+ }
182
+ /**
183
+ * Gets all zones' state
184
+ */
185
+ async getZones() {
186
+ return await this.refresh();
187
+ }
188
+ /**
189
+ * Gets the cached state of a zone
190
+ * @param name
191
+ */
192
+ getCachedZone(name) {
193
+ return this.zones.find((zone) => zone.name === name)?.state;
194
+ }
195
+ /**
196
+ * Gets the state of a Zone
197
+ * @param name
198
+ */
199
+ async getZone(name) {
200
+ const zones = await this.refresh();
201
+ return zones.find((zone) => zone.name === name)?.state;
202
+ }
203
+ /**
204
+ * Sets a Zone's state
205
+ * @param name
206
+ * @param state
207
+ */
208
+ async setZone(name, state) {
209
+ await this.setZones([{ name, state }]);
210
+ }
211
+ /**
212
+ * Sets multiple zones' state
213
+ * @param changes
214
+ */
215
+ async setZones(changes) {
216
+ await this.refresh();
217
+ for (const change of changes) {
218
+ const existingZone = this.zones.find((z) => z.name === change.name);
219
+ if (existingZone) {
220
+ existingZone.state = change.state;
221
+ }
222
+ }
223
+ const response = await set_zone_setting(this.client.api, {
224
+ zone_name: this.zones.map((zone) => zone.name).join(";"),
225
+ zone_onoff: this.zones.map((zone) => zone.state ? "1" : "0").join(";")
226
+ });
227
+ if (response.ret !== "OK")
228
+ throw new Error(`Failed to set zones: ${response.ret}`);
229
+ }
230
+ };
231
+
232
+ // src/api/aircon/get_control_info.ts
233
+ var get_control_info = (http2) => http2.request("/aircon/get_control_info");
234
+
235
+ // src/api/aircon/set_control_info.ts
236
+ var set_control_info = (http2, params) => http2.request("/aircon/set_control_info", params);
237
+
238
+ // src/DaikinClient.ts
239
+ var DaikinClient = class {
240
+ options;
241
+ api;
242
+ zones;
243
+ cachedControlInfo;
244
+ constructor(options) {
245
+ this.options = options;
246
+ if ("host" in options) {
247
+ this.api = new API(options.host);
248
+ } else {
249
+ this.api = new API(options.device.discoveredAddress);
250
+ }
251
+ this.zones = new Zones(this);
252
+ }
253
+ async getControlInfo() {
254
+ const response = await get_control_info(this.api);
255
+ const responseValues = Object.entries(response);
256
+ return this.cachedControlInfo = {
257
+ mode: Number(response.mode),
258
+ fanSpeed: Number(response.f_rate),
259
+ fanAuto: response.f_auto != 0,
260
+ fanAirside: response.f_airside != 0,
261
+ targetTemperature: response.stemp,
262
+ sensorTemperatures: responseValues.filter(([k, v]) => k.startsWith("dt")).map(([k, v]) => +v),
263
+ power: response.pow != 0,
264
+ status: Number(response.operate),
265
+ swinging: response.f_dir != 0,
266
+ isFilterDirty: response.filter_sign_info != 0,
267
+ isCentrallyControlled: response.cent != 0,
268
+ remoteControlType: Number(response.remo)
269
+ };
270
+ }
271
+ getCachedControlInfo() {
272
+ return this.cachedControlInfo;
273
+ }
274
+ async getPowered() {
275
+ return (await this.getControlInfo()).power;
276
+ }
277
+ async setPowered(state) {
278
+ return await this.setControlInfo({ power: state });
279
+ }
280
+ async getMode() {
281
+ return (await this.getControlInfo()).mode;
282
+ }
283
+ async setMode(mode) {
284
+ return await this.setControlInfo({ mode });
285
+ }
286
+ async getFan() {
287
+ const info = await this.getControlInfo();
288
+ return {
289
+ speed: info.fanSpeed,
290
+ auto: info.fanAuto
291
+ };
292
+ }
293
+ async setFan(fan) {
294
+ return await this.setControlInfo({ fanSpeed: fan.speed, fanAuto: fan.auto });
295
+ }
296
+ async getTargetTemperature() {
297
+ return (await this.getControlInfo()).targetTemperature;
298
+ }
299
+ async setTargetTemperature(temperature) {
300
+ return await this.setControlInfo({ targetTemperature: temperature });
301
+ }
302
+ async getSensorTemperatures() {
303
+ return (await this.getControlInfo()).sensorTemperatures;
304
+ }
305
+ async getStatus() {
306
+ return (await this.getControlInfo()).status;
307
+ }
308
+ async setControlInfo(info) {
309
+ const latest = await this.getControlInfo();
310
+ const update = { ...latest, ...info };
311
+ const bool = (v) => v ? 1 : 0;
312
+ const response = await set_control_info(this.api, {
313
+ f_airside: bool(update.fanAirside),
314
+ f_auto: bool(update.fanAuto),
315
+ f_dir: bool(update.swinging),
316
+ f_rate: update.fanSpeed,
317
+ mode: update.mode,
318
+ pow: bool(update.power),
319
+ stemp: update.targetTemperature
320
+ });
321
+ if (response.ret !== "OK")
322
+ throw new Error(`Failed to update control info: ${response.ret}`);
323
+ this.cachedControlInfo = update;
324
+ }
325
+ async getBasicInfo() {
326
+ const response = await basic_info(this.api);
327
+ return {
328
+ type: response.type,
329
+ region: response.reg,
330
+ version: response.ver,
331
+ name: response.name,
332
+ method: response.method,
333
+ port: response.port,
334
+ id: response.id,
335
+ password: response.pw,
336
+ ssid: response.ssid,
337
+ led: response.led === 1,
338
+ adp_mode: response.adp_mode,
339
+ adp_kind: response.adp_kind
340
+ };
341
+ }
342
+ static async discover(timeoutMs = 3e3) {
343
+ return discover(timeoutMs);
344
+ }
345
+ };
346
+ // Annotate the CommonJS export names for ESM import in node:
347
+ 0 && (module.exports = {
348
+ API,
349
+ DaikinClient,
350
+ basic_info,
351
+ discover,
352
+ get_zone_settings
353
+ });
@@ -0,0 +1,183 @@
1
+ type Params = Record<string, number | string>;
2
+
3
+ type DaikinResponse = {
4
+ ret: 'OK';
5
+ };
6
+ declare class API {
7
+ readonly host: string;
8
+ constructor(host: string);
9
+ request(endpoint: string, parameters?: Record<string, string | number | undefined | null>): Promise<Params>;
10
+ }
11
+
12
+ type BasicInfoResponse = DaikinResponse & {
13
+ type: 'aircon';
14
+ reg: 'string';
15
+ dst: number;
16
+ ver: 'string';
17
+ rev: 'string';
18
+ pow: number;
19
+ err: number;
20
+ location: number;
21
+ name: 'string';
22
+ icon: number;
23
+ method: 'polling';
24
+ port: number;
25
+ id: 'string';
26
+ pw: 'string';
27
+ lpw_flag: number;
28
+ adp_kind: number;
29
+ led: number;
30
+ en_setzone: number;
31
+ mac: string;
32
+ adp_mode: 'run';
33
+ ssid: 'string';
34
+ err_type: string;
35
+ err_code: number;
36
+ en_ch: number;
37
+ holiday: number;
38
+ en_hol: number;
39
+ sync_time: number;
40
+ };
41
+ declare const basic_info: (http: API) => Promise<BasicInfoResponse>;
42
+
43
+ type DiscoveredDevice = BasicInfoResponse & {
44
+ discoveredAddress: string;
45
+ discoveredPort: number;
46
+ };
47
+ declare function discover(timeoutMs?: number): Promise<DiscoveredDevice[]>;
48
+
49
+ type ZoneSettingResponse = DaikinResponse & {
50
+ zone_name: string;
51
+ zone_onoff: string;
52
+ };
53
+ declare const get_zone_settings: (http: API) => Promise<ZoneSettingResponse>;
54
+
55
+ type ZoneState = {
56
+ name: string;
57
+ state: boolean;
58
+ };
59
+ declare class Zones {
60
+ private zones;
61
+ private readonly client;
62
+ constructor(client: DaikinClient);
63
+ /** Refreshes the cached zone state */
64
+ refresh(): Promise<ZoneState[]>;
65
+ /**
66
+ * Gets the state of all cached zones.
67
+ */
68
+ getCachedZones(): ZoneState[];
69
+ /**
70
+ * Gets all zones' state
71
+ */
72
+ getZones(): Promise<ZoneState[]>;
73
+ /**
74
+ * Gets the cached state of a zone
75
+ * @param name
76
+ */
77
+ getCachedZone(name: string): boolean | undefined;
78
+ /**
79
+ * Gets the state of a Zone
80
+ * @param name
81
+ */
82
+ getZone(name: string): Promise<boolean | undefined>;
83
+ /**
84
+ * Sets a Zone's state
85
+ * @param name
86
+ * @param state
87
+ */
88
+ setZone(name: string, state: boolean): Promise<void>;
89
+ /**
90
+ * Sets multiple zones' state
91
+ * @param changes
92
+ */
93
+ setZones(changes: ZoneState[]): Promise<void>;
94
+ }
95
+
96
+ type BasicInfo = {
97
+ type: 'aircon';
98
+ region: string;
99
+ version: string;
100
+ name: string;
101
+ method: 'polling';
102
+ port: number;
103
+ id: string;
104
+ password: string;
105
+ ssid: string;
106
+ led: boolean;
107
+ adp_mode: 'run';
108
+ adp_kind: number;
109
+ };
110
+ declare enum ControlMode {
111
+ Fan = 0,
112
+ Hot = 1,
113
+ Cool = 2,
114
+ Auto = 3,
115
+ Dry = 4
116
+ }
117
+ declare enum FanSpeed {
118
+ Low = 1,
119
+ Medium = 3,
120
+ High = 5
121
+ }
122
+ declare enum Status {
123
+ Stopped = 0,
124
+ Operating = 1,
125
+ Idle = 2
126
+ }
127
+ declare enum RemoteType {
128
+ None = 0,
129
+ Wired = 1,
130
+ Wireless = 2
131
+ }
132
+ type ControlInfo = {
133
+ mode: ControlMode;
134
+ fanSpeed: FanSpeed;
135
+ fanAuto: boolean;
136
+ fanAirside: boolean;
137
+ targetTemperature: number;
138
+ sensorTemperatures: number[];
139
+ power: boolean;
140
+ status: Status;
141
+ swinging: boolean;
142
+ isFilterDirty: boolean;
143
+ isCentrallyControlled: boolean;
144
+ remoteControlType: RemoteType;
145
+ };
146
+
147
+ type DeviceOption = {
148
+ device: DiscoveredDevice;
149
+ };
150
+ type HostOption = {
151
+ host: string;
152
+ };
153
+ type DaikinClientOptions = (DeviceOption | HostOption) & {
154
+ password?: string;
155
+ };
156
+ type Fan = {
157
+ speed: FanSpeed;
158
+ auto: boolean;
159
+ };
160
+ declare class DaikinClient {
161
+ private readonly options;
162
+ readonly api: API;
163
+ readonly zones: Zones;
164
+ private cachedControlInfo;
165
+ constructor(options: DaikinClientOptions);
166
+ getControlInfo(): Promise<ControlInfo>;
167
+ getCachedControlInfo(): ControlInfo | undefined;
168
+ getPowered(): Promise<boolean>;
169
+ setPowered(state: boolean): Promise<void>;
170
+ getMode(): Promise<ControlMode>;
171
+ setMode(mode: ControlMode): Promise<void>;
172
+ getFan(): Promise<Fan>;
173
+ setFan(fan: Fan): Promise<void>;
174
+ getTargetTemperature(): Promise<number>;
175
+ setTargetTemperature(temperature: number): Promise<void>;
176
+ getSensorTemperatures(): Promise<number[]>;
177
+ getStatus(): Promise<Status>;
178
+ setControlInfo(info: Partial<ControlInfo>): Promise<void>;
179
+ getBasicInfo(): Promise<BasicInfo>;
180
+ static discover(timeoutMs?: number): Promise<DiscoveredDevice[]>;
181
+ }
182
+
183
+ export { API, type BasicInfoResponse, DaikinClient, type DaikinClientOptions, type DaikinResponse, type DiscoveredDevice, type Fan, type ZoneSettingResponse, basic_info, discover, get_zone_settings };
@@ -0,0 +1,183 @@
1
+ type Params = Record<string, number | string>;
2
+
3
+ type DaikinResponse = {
4
+ ret: 'OK';
5
+ };
6
+ declare class API {
7
+ readonly host: string;
8
+ constructor(host: string);
9
+ request(endpoint: string, parameters?: Record<string, string | number | undefined | null>): Promise<Params>;
10
+ }
11
+
12
+ type BasicInfoResponse = DaikinResponse & {
13
+ type: 'aircon';
14
+ reg: 'string';
15
+ dst: number;
16
+ ver: 'string';
17
+ rev: 'string';
18
+ pow: number;
19
+ err: number;
20
+ location: number;
21
+ name: 'string';
22
+ icon: number;
23
+ method: 'polling';
24
+ port: number;
25
+ id: 'string';
26
+ pw: 'string';
27
+ lpw_flag: number;
28
+ adp_kind: number;
29
+ led: number;
30
+ en_setzone: number;
31
+ mac: string;
32
+ adp_mode: 'run';
33
+ ssid: 'string';
34
+ err_type: string;
35
+ err_code: number;
36
+ en_ch: number;
37
+ holiday: number;
38
+ en_hol: number;
39
+ sync_time: number;
40
+ };
41
+ declare const basic_info: (http: API) => Promise<BasicInfoResponse>;
42
+
43
+ type DiscoveredDevice = BasicInfoResponse & {
44
+ discoveredAddress: string;
45
+ discoveredPort: number;
46
+ };
47
+ declare function discover(timeoutMs?: number): Promise<DiscoveredDevice[]>;
48
+
49
+ type ZoneSettingResponse = DaikinResponse & {
50
+ zone_name: string;
51
+ zone_onoff: string;
52
+ };
53
+ declare const get_zone_settings: (http: API) => Promise<ZoneSettingResponse>;
54
+
55
+ type ZoneState = {
56
+ name: string;
57
+ state: boolean;
58
+ };
59
+ declare class Zones {
60
+ private zones;
61
+ private readonly client;
62
+ constructor(client: DaikinClient);
63
+ /** Refreshes the cached zone state */
64
+ refresh(): Promise<ZoneState[]>;
65
+ /**
66
+ * Gets the state of all cached zones.
67
+ */
68
+ getCachedZones(): ZoneState[];
69
+ /**
70
+ * Gets all zones' state
71
+ */
72
+ getZones(): Promise<ZoneState[]>;
73
+ /**
74
+ * Gets the cached state of a zone
75
+ * @param name
76
+ */
77
+ getCachedZone(name: string): boolean | undefined;
78
+ /**
79
+ * Gets the state of a Zone
80
+ * @param name
81
+ */
82
+ getZone(name: string): Promise<boolean | undefined>;
83
+ /**
84
+ * Sets a Zone's state
85
+ * @param name
86
+ * @param state
87
+ */
88
+ setZone(name: string, state: boolean): Promise<void>;
89
+ /**
90
+ * Sets multiple zones' state
91
+ * @param changes
92
+ */
93
+ setZones(changes: ZoneState[]): Promise<void>;
94
+ }
95
+
96
+ type BasicInfo = {
97
+ type: 'aircon';
98
+ region: string;
99
+ version: string;
100
+ name: string;
101
+ method: 'polling';
102
+ port: number;
103
+ id: string;
104
+ password: string;
105
+ ssid: string;
106
+ led: boolean;
107
+ adp_mode: 'run';
108
+ adp_kind: number;
109
+ };
110
+ declare enum ControlMode {
111
+ Fan = 0,
112
+ Hot = 1,
113
+ Cool = 2,
114
+ Auto = 3,
115
+ Dry = 4
116
+ }
117
+ declare enum FanSpeed {
118
+ Low = 1,
119
+ Medium = 3,
120
+ High = 5
121
+ }
122
+ declare enum Status {
123
+ Stopped = 0,
124
+ Operating = 1,
125
+ Idle = 2
126
+ }
127
+ declare enum RemoteType {
128
+ None = 0,
129
+ Wired = 1,
130
+ Wireless = 2
131
+ }
132
+ type ControlInfo = {
133
+ mode: ControlMode;
134
+ fanSpeed: FanSpeed;
135
+ fanAuto: boolean;
136
+ fanAirside: boolean;
137
+ targetTemperature: number;
138
+ sensorTemperatures: number[];
139
+ power: boolean;
140
+ status: Status;
141
+ swinging: boolean;
142
+ isFilterDirty: boolean;
143
+ isCentrallyControlled: boolean;
144
+ remoteControlType: RemoteType;
145
+ };
146
+
147
+ type DeviceOption = {
148
+ device: DiscoveredDevice;
149
+ };
150
+ type HostOption = {
151
+ host: string;
152
+ };
153
+ type DaikinClientOptions = (DeviceOption | HostOption) & {
154
+ password?: string;
155
+ };
156
+ type Fan = {
157
+ speed: FanSpeed;
158
+ auto: boolean;
159
+ };
160
+ declare class DaikinClient {
161
+ private readonly options;
162
+ readonly api: API;
163
+ readonly zones: Zones;
164
+ private cachedControlInfo;
165
+ constructor(options: DaikinClientOptions);
166
+ getControlInfo(): Promise<ControlInfo>;
167
+ getCachedControlInfo(): ControlInfo | undefined;
168
+ getPowered(): Promise<boolean>;
169
+ setPowered(state: boolean): Promise<void>;
170
+ getMode(): Promise<ControlMode>;
171
+ setMode(mode: ControlMode): Promise<void>;
172
+ getFan(): Promise<Fan>;
173
+ setFan(fan: Fan): Promise<void>;
174
+ getTargetTemperature(): Promise<number>;
175
+ setTargetTemperature(temperature: number): Promise<void>;
176
+ getSensorTemperatures(): Promise<number[]>;
177
+ getStatus(): Promise<Status>;
178
+ setControlInfo(info: Partial<ControlInfo>): Promise<void>;
179
+ getBasicInfo(): Promise<BasicInfo>;
180
+ static discover(timeoutMs?: number): Promise<DiscoveredDevice[]>;
181
+ }
182
+
183
+ export { API, type BasicInfoResponse, DaikinClient, type DaikinClientOptions, type DaikinResponse, type DiscoveredDevice, type Fan, type ZoneSettingResponse, basic_info, discover, get_zone_settings };
package/dist/index.js ADDED
@@ -0,0 +1,312 @@
1
+ // src/ParamParser.ts
2
+ function parse(str) {
3
+ const result = {};
4
+ const parts = str.split(",");
5
+ for (const part of parts) {
6
+ const [key, value] = part.split("=");
7
+ if (key === void 0) continue;
8
+ const maybeNumber = Number(value);
9
+ if (Number.isNaN(maybeNumber)) {
10
+ result[key] = decodeURIComponent(`${value}`);
11
+ } else {
12
+ result[key] = maybeNumber;
13
+ }
14
+ }
15
+ return result;
16
+ }
17
+
18
+ // src/api/API.ts
19
+ import http from "http";
20
+ var API = class {
21
+ host;
22
+ constructor(host) {
23
+ this.host = host;
24
+ }
25
+ async request(endpoint, parameters) {
26
+ const body = await new Promise((resolve, reject) => {
27
+ const url = new URL(`/skyfi${endpoint}`, `http://${this.host}/`);
28
+ const queries = [];
29
+ if (parameters) {
30
+ for (const key in parameters) {
31
+ const value = parameters[key];
32
+ if (value === void 0) continue;
33
+ const encoded = encodeURIComponent(`${value || ""}`);
34
+ queries.push(`${key}=${encoded}`);
35
+ }
36
+ }
37
+ const search = queries.length > 0 ? `?${queries.join("&")}` : "";
38
+ const req = http.request(
39
+ {
40
+ host: url.hostname,
41
+ port: url.port,
42
+ path: url.pathname + search,
43
+ // important
44
+ method: "GET",
45
+ headers: {
46
+ Accept: "*/*",
47
+ Connection: "close"
48
+ }
49
+ },
50
+ (res) => {
51
+ let data = "";
52
+ res.setEncoding("utf8");
53
+ res.on("data", (c) => data += c);
54
+ res.on("end", () => resolve(data));
55
+ }
56
+ );
57
+ req.on("error", reject);
58
+ req.end();
59
+ });
60
+ return parse(body);
61
+ }
62
+ };
63
+
64
+ // src/api/Discover.ts
65
+ import dgram from "dgram";
66
+ var DISCOVERY_PORT = 30050;
67
+ var DISCOVERY_ADDRESS = "255.255.255.255";
68
+ function discover(timeoutMs = 3e3) {
69
+ return new Promise((resolve, reject) => {
70
+ const availableUnits = /* @__PURE__ */ new Map();
71
+ const socket = dgram.createSocket("udp4");
72
+ const payload = Buffer.from("DAIKIN_UDP/common/basic_info", "utf8");
73
+ const finish = () => {
74
+ socket.close();
75
+ resolve([...availableUnits.values()]);
76
+ };
77
+ socket.once("error", (err) => {
78
+ socket.close();
79
+ reject(err);
80
+ });
81
+ socket.on("message", (msg, rinfo) => {
82
+ const raw = msg.toString("utf8");
83
+ const info = parse(raw);
84
+ const key = `${info.mac || info.id || rinfo.address}`;
85
+ availableUnits.set(key, {
86
+ discoveredAddress: rinfo.address,
87
+ discoveredPort: rinfo.port,
88
+ ...info
89
+ });
90
+ });
91
+ socket.bind(0, "0.0.0.0", () => {
92
+ try {
93
+ socket.setBroadcast(true);
94
+ socket.send(payload, DISCOVERY_PORT, DISCOVERY_ADDRESS, (err) => {
95
+ if (err) {
96
+ socket.close();
97
+ reject(err);
98
+ return;
99
+ }
100
+ setTimeout(finish, timeoutMs);
101
+ });
102
+ } catch (err) {
103
+ socket.close();
104
+ reject(err);
105
+ }
106
+ });
107
+ });
108
+ }
109
+
110
+ // src/api/common/basic_info.ts
111
+ var basic_info = (http2) => http2.request("/common/basic_info");
112
+
113
+ // src/api/aircon/get_zone_setting.ts
114
+ var get_zone_settings = (http2) => http2.request("/aircon/get_zone_setting");
115
+
116
+ // src/api/aircon/set_zone_setting.ts
117
+ var set_zone_setting = (http2, params) => http2.request("/aircon/set_zone_setting", params);
118
+
119
+ // src/Zones.ts
120
+ var Zones = class {
121
+ zones = [];
122
+ client;
123
+ constructor(client) {
124
+ this.client = client;
125
+ }
126
+ /** Refreshes the cached zone state */
127
+ async refresh() {
128
+ const response = await get_zone_settings(this.client.api);
129
+ const zoneNames = response.zone_name.split(";");
130
+ const zoneState = response.zone_onoff.split(";");
131
+ return this.zones = zoneNames.map((name, index) => ({
132
+ name,
133
+ state: zoneState[index] === "1"
134
+ }));
135
+ }
136
+ /**
137
+ * Gets the state of all cached zones.
138
+ */
139
+ getCachedZones() {
140
+ return [...this.zones];
141
+ }
142
+ /**
143
+ * Gets all zones' state
144
+ */
145
+ async getZones() {
146
+ return await this.refresh();
147
+ }
148
+ /**
149
+ * Gets the cached state of a zone
150
+ * @param name
151
+ */
152
+ getCachedZone(name) {
153
+ return this.zones.find((zone) => zone.name === name)?.state;
154
+ }
155
+ /**
156
+ * Gets the state of a Zone
157
+ * @param name
158
+ */
159
+ async getZone(name) {
160
+ const zones = await this.refresh();
161
+ return zones.find((zone) => zone.name === name)?.state;
162
+ }
163
+ /**
164
+ * Sets a Zone's state
165
+ * @param name
166
+ * @param state
167
+ */
168
+ async setZone(name, state) {
169
+ await this.setZones([{ name, state }]);
170
+ }
171
+ /**
172
+ * Sets multiple zones' state
173
+ * @param changes
174
+ */
175
+ async setZones(changes) {
176
+ await this.refresh();
177
+ for (const change of changes) {
178
+ const existingZone = this.zones.find((z) => z.name === change.name);
179
+ if (existingZone) {
180
+ existingZone.state = change.state;
181
+ }
182
+ }
183
+ const response = await set_zone_setting(this.client.api, {
184
+ zone_name: this.zones.map((zone) => zone.name).join(";"),
185
+ zone_onoff: this.zones.map((zone) => zone.state ? "1" : "0").join(";")
186
+ });
187
+ if (response.ret !== "OK")
188
+ throw new Error(`Failed to set zones: ${response.ret}`);
189
+ }
190
+ };
191
+
192
+ // src/api/aircon/get_control_info.ts
193
+ var get_control_info = (http2) => http2.request("/aircon/get_control_info");
194
+
195
+ // src/api/aircon/set_control_info.ts
196
+ var set_control_info = (http2, params) => http2.request("/aircon/set_control_info", params);
197
+
198
+ // src/DaikinClient.ts
199
+ var DaikinClient = class {
200
+ options;
201
+ api;
202
+ zones;
203
+ cachedControlInfo;
204
+ constructor(options) {
205
+ this.options = options;
206
+ if ("host" in options) {
207
+ this.api = new API(options.host);
208
+ } else {
209
+ this.api = new API(options.device.discoveredAddress);
210
+ }
211
+ this.zones = new Zones(this);
212
+ }
213
+ async getControlInfo() {
214
+ const response = await get_control_info(this.api);
215
+ const responseValues = Object.entries(response);
216
+ return this.cachedControlInfo = {
217
+ mode: Number(response.mode),
218
+ fanSpeed: Number(response.f_rate),
219
+ fanAuto: response.f_auto != 0,
220
+ fanAirside: response.f_airside != 0,
221
+ targetTemperature: response.stemp,
222
+ sensorTemperatures: responseValues.filter(([k, v]) => k.startsWith("dt")).map(([k, v]) => +v),
223
+ power: response.pow != 0,
224
+ status: Number(response.operate),
225
+ swinging: response.f_dir != 0,
226
+ isFilterDirty: response.filter_sign_info != 0,
227
+ isCentrallyControlled: response.cent != 0,
228
+ remoteControlType: Number(response.remo)
229
+ };
230
+ }
231
+ getCachedControlInfo() {
232
+ return this.cachedControlInfo;
233
+ }
234
+ async getPowered() {
235
+ return (await this.getControlInfo()).power;
236
+ }
237
+ async setPowered(state) {
238
+ return await this.setControlInfo({ power: state });
239
+ }
240
+ async getMode() {
241
+ return (await this.getControlInfo()).mode;
242
+ }
243
+ async setMode(mode) {
244
+ return await this.setControlInfo({ mode });
245
+ }
246
+ async getFan() {
247
+ const info = await this.getControlInfo();
248
+ return {
249
+ speed: info.fanSpeed,
250
+ auto: info.fanAuto
251
+ };
252
+ }
253
+ async setFan(fan) {
254
+ return await this.setControlInfo({ fanSpeed: fan.speed, fanAuto: fan.auto });
255
+ }
256
+ async getTargetTemperature() {
257
+ return (await this.getControlInfo()).targetTemperature;
258
+ }
259
+ async setTargetTemperature(temperature) {
260
+ return await this.setControlInfo({ targetTemperature: temperature });
261
+ }
262
+ async getSensorTemperatures() {
263
+ return (await this.getControlInfo()).sensorTemperatures;
264
+ }
265
+ async getStatus() {
266
+ return (await this.getControlInfo()).status;
267
+ }
268
+ async setControlInfo(info) {
269
+ const latest = await this.getControlInfo();
270
+ const update = { ...latest, ...info };
271
+ const bool = (v) => v ? 1 : 0;
272
+ const response = await set_control_info(this.api, {
273
+ f_airside: bool(update.fanAirside),
274
+ f_auto: bool(update.fanAuto),
275
+ f_dir: bool(update.swinging),
276
+ f_rate: update.fanSpeed,
277
+ mode: update.mode,
278
+ pow: bool(update.power),
279
+ stemp: update.targetTemperature
280
+ });
281
+ if (response.ret !== "OK")
282
+ throw new Error(`Failed to update control info: ${response.ret}`);
283
+ this.cachedControlInfo = update;
284
+ }
285
+ async getBasicInfo() {
286
+ const response = await basic_info(this.api);
287
+ return {
288
+ type: response.type,
289
+ region: response.reg,
290
+ version: response.ver,
291
+ name: response.name,
292
+ method: response.method,
293
+ port: response.port,
294
+ id: response.id,
295
+ password: response.pw,
296
+ ssid: response.ssid,
297
+ led: response.led === 1,
298
+ adp_mode: response.adp_mode,
299
+ adp_kind: response.adp_kind
300
+ };
301
+ }
302
+ static async discover(timeoutMs = 3e3) {
303
+ return discover(timeoutMs);
304
+ }
305
+ };
306
+ export {
307
+ API,
308
+ DaikinClient,
309
+ basic_info,
310
+ discover,
311
+ get_zone_settings
312
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "daikin-airbase",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "prepublishOnly": "npm run build",
23
+ "build:example": "tsup example/basic_example.ts --format esm --out-dir dist/example",
24
+ "dev:example": "npm run build:example && node dist/example/basic_example.js"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^25.5.0",
28
+ "tsup": "^8.5.1",
29
+ "typescript": "^5.9.3"
30
+ }
31
+ }