mirror of
https://github.com/parnic/node-intellicenter.git
synced 2025-06-16 18:20:14 -05:00
Getting a feel for how the development experience is with this setup. With the previous idea of abstracting the request into a getSystemInfo() function on the Unit itself, the documentation for what to expect from GetSystemInfo either had to live in two places or be presented as a link to the canonical location. Neither felt great, so I think the caller can just call send(GetRequest()) themselves. Also added the first "set" message which is capable of toggling a body or circuit.
43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
"use strict";
|
|
import { FindUnits } from "./finder.js";
|
|
import { GetBodyStatus } from "./messages/body-status.js";
|
|
import { GetSystemConfiguration } from "./messages/configuration.js";
|
|
// import { SetItemStatus } from "./messages/set-status.js";
|
|
import { GetSystemInfoRequest } from "./messages/system-info.js";
|
|
import { Unit } from "./unit.js";
|
|
console.log("searching...");
|
|
const f = new FindUnits();
|
|
const units = await f.searchAsync(1000);
|
|
f.close();
|
|
console.log("Discovered units:", units);
|
|
if (units.length === 0) {
|
|
throw new Error("no IntelliCenter units found, exiting.");
|
|
}
|
|
if (units.length > 1) {
|
|
throw new Error(`found more than one IntelliCenter unit, unsure which one to use. ${JSON.stringify(units)}`);
|
|
}
|
|
const endpoint = units[0].addressStr;
|
|
const port = units[0].port;
|
|
// const endpoint = "10.0.0.41";
|
|
// const port = 6680;
|
|
console.log("connecting to intellicenter device at", endpoint, "port", port);
|
|
const unit = new Unit(endpoint, port);
|
|
await unit.connect();
|
|
console.log("connected");
|
|
console.log("sending Get System Info request...");
|
|
let resp = await unit.send(GetSystemInfoRequest());
|
|
console.log("got response:", JSON.stringify(resp, null, 2));
|
|
console.log("sending Get System Config request...");
|
|
resp = await unit.send(GetSystemConfiguration());
|
|
console.log("got response:", JSON.stringify(resp, null, 2));
|
|
console.log("sending Get Body Status request...");
|
|
resp = await unit.send(GetBodyStatus());
|
|
console.log("got response:", JSON.stringify(resp, null, 2));
|
|
// console.log("turning off pool...");
|
|
// resp = await unit.send(SetItemStatus("B1101", false));
|
|
// console.log("got response:", JSON.stringify(resp, null, 2));
|
|
// console.log("turning off water feature...");
|
|
// resp = await unit.send(SetItemStatus("C0003", false));
|
|
// console.log("got response:", JSON.stringify(resp, null, 2));
|
|
unit.close();
|
|
//# sourceMappingURL=index.js.map
|