diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c24005..46ae83c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,28 +38,40 @@ jobs: id: lint run: npm run lint - # This will fail the workflow if the `dist/` directory is different than - # expected. + # This will fail the workflow if either of the output directories are different + # than expected. - name: Compare Directories id: diff run: | - if [ ! -d dist/ ]; then - echo "Expected dist/ directory does not exist. See status below:" + if [ ! -d cjs/ ]; then + echo "Expected cjs/ directory does not exist. See status below:" ls -la ./ exit 1 fi - if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then + if [ "$(git diff --ignore-space-at-eol --text cjs/ | wc -l)" -gt "0" ]; then echo "Detected uncommitted changes after build. See status below:" - git diff --ignore-space-at-eol --text dist/ + git diff --ignore-space-at-eol --text cjs/ + exit 1 + fi + if [ ! -d esm/ ]; then + echo "Expected esm/ directory does not exist. See status below:" + ls -la ./ + exit 1 + fi + if [ "$(git diff --ignore-space-at-eol --text esm/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build. See status below:" + git diff --ignore-space-at-eol --text esm/ exit 1 fi - # If `dist/` was different than expected, upload the expected version as a + # If outdir was different than expected, upload the expected version as a # workflow artifact. - if: ${{ failure() && steps.diff.outcome == 'failure' }} name: Upload Artifact id: upload uses: actions/upload-artifact@v4 with: - name: dist-${{ matrix.node-version }}-diff - path: dist/ + name: outdir-${{ matrix.node-version }}-diff + path: | + cjs/ + esm/ diff --git a/.prettierignore b/.prettierignore index 4e5f15e..b7fd5e1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ /.github/ -/dist/ +/cjs/ +/esm/ /connection-logs/ diff --git a/dist/dns.d.ts b/cjs/dns.d.ts similarity index 100% rename from dist/dns.d.ts rename to cjs/dns.d.ts diff --git a/cjs/dns.js b/cjs/dns.js new file mode 100644 index 0000000..c770aea --- /dev/null +++ b/cjs/dns.js @@ -0,0 +1,169 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ARecord = exports.SrvRecord = exports.TxtRecord = exports.PtrRecord = exports.Record = exports.Question = exports.TypeA = exports.TypeSrv = exports.TypePtr = exports.TypeTxt = void 0; +exports.ipToString = ipToString; +exports.GetDNSQuestion = GetDNSQuestion; +exports.GetDNSAnswer = GetDNSAnswer; +exports.TypeTxt = 16; +exports.TypePtr = 12; +exports.TypeSrv = 33; +exports.TypeA = 1; +class Question { + name = ""; + type = 0; + class = 0; + endOffset = 0; +} +exports.Question = Question; +class Record { + type = 0; + ttlSeconds = 0; + name = ""; + endOffset = -1; +} +exports.Record = Record; +class PtrRecord extends Record { + domain = ""; +} +exports.PtrRecord = PtrRecord; +class TxtRecord extends Record { + text = ""; +} +exports.TxtRecord = TxtRecord; +class SrvRecord extends Record { + priority = 0; + weight = 0; + port = 0; + target = ""; +} +exports.SrvRecord = SrvRecord; +class ARecord extends Record { + address = 0; + get addressStr() { + return ipToString(this.address); + } +} +exports.ARecord = ARecord; +function ipToString(ip) { + const o1 = (ip >> 24) & 0xff; + const o2 = (ip >> 16) & 0xff; + const o3 = (ip >> 8) & 0xff; + const o4 = (ip >> 0) & 0xff; + const addressStr = `${o1.toString()}.${o2.toString()}.${o3.toString()}.${o4.toString()}`; + return addressStr; +} +class dnsAnswerParseResult { + name = ""; + endOffset = 0; +} +function parseDnsName(msg, startOffset) { + const result = new dnsAnswerParseResult(); + let offset = startOffset; + while (offset < msg.length) { + const nextByte = msg.readUInt8(offset); + if (nextByte === 0) { + offset++; + break; + } + const pointerMask = (1 << 6) | (1 << 7); + if ((nextByte & pointerMask) === pointerMask) { + offset++; + const pointerOffset = msg.readUInt8(offset); + offset++; + const nestedResult = parseDnsName(msg, pointerOffset); + if (result.name.length > 0 && nestedResult.name.length > 0) { + result.name += "."; + } + result.name += nestedResult.name; + break; + } + offset++; + const segment = msg.toString("ascii", offset, offset + nextByte); + offset += nextByte; + if (result.name.length > 0 && segment.length > 0) { + result.name += "."; + } + result.name += segment; + } + result.endOffset = offset; + return result; +} +function GetDNSQuestion(msg, startOffset) { + let offset = startOffset; + const parsedResult = parseDnsName(msg, offset); + offset = parsedResult.endOffset; + const type = msg.readUInt16BE(offset); + offset += 2; + const cls = msg.readUInt16BE(offset); + offset += 2; + const ret = new Question(); + ret.name = parsedResult.name; + ret.type = type; + ret.class = cls; + ret.endOffset = offset; + return ret; +} +function GetDNSAnswer(msg, startOffset) { + let offset = startOffset; + const parsedResult = parseDnsName(msg, offset); + offset = parsedResult.endOffset; + const type = msg.readUInt16BE(offset); + offset += 2; + offset += 2; // don't care about "class" of answer + const ttlSeconds = msg.readUInt32BE(offset); + offset += 4; + const rDataLength = msg.readUInt16BE(offset); + offset += 2; + switch (type) { + case exports.TypePtr: { + const domainResult = parseDnsName(msg, offset); + const ret = new PtrRecord(); + ret.type = type; + ret.ttlSeconds = ttlSeconds; + ret.name = parsedResult.name; + ret.endOffset = offset + rDataLength; + ret.domain = domainResult.name; + return ret; + } + case exports.TypeTxt: { + const textResult = parseDnsName(msg, offset); + const ret = new TxtRecord(); + ret.type = type; + ret.ttlSeconds = ttlSeconds; + ret.name = parsedResult.name; + ret.endOffset = offset + rDataLength; + ret.text = textResult.name; + return ret; + } + case exports.TypeSrv: { + const priority = msg.readUInt16BE(offset); + const weight = msg.readUInt16BE(offset + 2); + const port = msg.readUInt16BE(offset + 4); + const targetResult = parseDnsName(msg, offset + 6); + const ret = new SrvRecord(); + ret.type = type; + ret.ttlSeconds = ttlSeconds; + ret.name = parsedResult.name; + ret.endOffset = offset + rDataLength; + ret.priority = priority; + ret.weight = weight; + ret.port = port; + ret.target = targetResult.name; + return ret; + } + case exports.TypeA: { + const address = msg.readUInt32BE(offset); + const ret = new ARecord(); + ret.type = type; + ret.ttlSeconds = ttlSeconds; + ret.name = parsedResult.name; + ret.endOffset = offset + rDataLength; + ret.address = address; + return ret; + } + default: + break; + } + return undefined; +} +//# sourceMappingURL=dns.js.map \ No newline at end of file diff --git a/cjs/dns.js.map b/cjs/dns.js.map new file mode 100644 index 0000000..4c6c0b6 --- /dev/null +++ b/cjs/dns.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dns.js","sourceRoot":"","sources":["../dns.ts"],"names":[],"mappings":";;;AA0CA,gCAOC;AA4CD,wCAeC;AAED,oCA4EC;AA1LY,QAAA,OAAO,GAAG,EAAE,CAAC;AACb,QAAA,OAAO,GAAG,EAAE,CAAC;AACb,QAAA,OAAO,GAAG,EAAE,CAAC;AACb,QAAA,KAAK,GAAG,CAAC,CAAC;AAEvB,MAAa,QAAQ;IACZ,IAAI,GAAG,EAAE,CAAC;IACV,IAAI,GAAG,CAAC,CAAC;IACT,KAAK,GAAG,CAAC,CAAC;IACV,SAAS,GAAG,CAAC,CAAC;CACtB;AALD,4BAKC;AAED,MAAsB,MAAM;IACnB,IAAI,GAAG,CAAC,CAAC;IACT,UAAU,GAAG,CAAC,CAAC;IACf,IAAI,GAAG,EAAE,CAAC;IACV,SAAS,GAAG,CAAC,CAAC,CAAC;CACvB;AALD,wBAKC;AAED,MAAa,SAAU,SAAQ,MAAM;IAC5B,MAAM,GAAG,EAAE,CAAC;CACpB;AAFD,8BAEC;AAED,MAAa,SAAU,SAAQ,MAAM;IAC5B,IAAI,GAAG,EAAE,CAAC;CAClB;AAFD,8BAEC;AAED,MAAa,SAAU,SAAQ,MAAM;IAC5B,QAAQ,GAAG,CAAC,CAAC;IACb,MAAM,GAAG,CAAC,CAAC;IACX,IAAI,GAAG,CAAC,CAAC;IACT,MAAM,GAAG,EAAE,CAAC;CACpB;AALD,8BAKC;AAED,MAAa,OAAQ,SAAQ,MAAM;IAC1B,OAAO,GAAG,CAAC,CAAC;IAEnB,IAAW,UAAU;QACnB,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF;AAND,0BAMC;AAED,SAAgB,UAAU,CAAC,EAAU;IACnC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC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,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC;YAC5B,GAAG,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YAC7B,GAAG,CAAC,SAAS,GAAG,MAAM,GAAG,WAAW,CAAC;YACrC,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;YACtB,OAAO,GAAG,CAAC;QACb,CAAC;QAED;YACE,MAAM;IACV,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"} \ No newline at end of file diff --git a/dist/example.d.ts b/cjs/example.d.ts similarity index 100% rename from dist/example.d.ts rename to cjs/example.d.ts diff --git a/cjs/example.js b/cjs/example.js new file mode 100644 index 0000000..bf4d0c0 --- /dev/null +++ b/cjs/example.js @@ -0,0 +1,102 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("./index.js"); +const messages = __importStar(require("./messages/messages.js")); +const example = async () => { + console.log("searching..."); + const f = new index_js_1.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 index_js_1.Unit(endpoint, port); + await unit.connect(); + console.log("connected"); + unit.on("notify", (msg) => { + console.log("received notify:", msg); + }); + console.log("subscribing for updates..."); + let resp = await unit.send(messages.SubscribeToUpdates("B1202", "LOTMP")); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get System Info request..."); + resp = await unit.send(messages.GetSystemInformation()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get System Config request..."); + resp = await unit.send(messages.GetSystemConfiguration()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Body Status request..."); + resp = await unit.send(messages.GetBodyStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Chemical Status request..."); + resp = await unit.send(messages.GetChemicalStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Heaters request..."); + resp = await unit.send(messages.GetHeaters()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Schedule request..."); + resp = await unit.send(messages.GetSchedule()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Circuit Status request..."); + resp = await unit.send(messages.GetCircuitStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("sending Set Setpoint request..."); + // resp = await unit.send(messages.SetSetpoint("B1202", 97)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("turning off pool..."); + // resp = await unit.send(messages.SetObjectStatus("B1101", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("turning off water feature..."); + // resp = await unit.send(messages.SetObjectStatus("C0003", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("sending Set Heatmode request..."); + // resp = await unit.send(messages.SetHeatMode("B1202", true)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + unit.close(); +}; +example().catch((e) => { + throw e; +}); +//# sourceMappingURL=example.js.map \ No newline at end of file diff --git a/cjs/example.js.map b/cjs/example.js.map new file mode 100644 index 0000000..f0278d4 --- /dev/null +++ b/cjs/example.js.map @@ -0,0 +1 @@ +{"version":3,"file":"example.js","sourceRoot":"","sources":["../example.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,yCAA6C;AAC7C,iEAAmD;AAEnD,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;IACzB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,MAAM,CAAC,GAAG,IAAI,oBAAS,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,KAAK,EAAE,CAAC;IACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAExC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,oEAAoE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAC5F,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IACrC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3B,gCAAgC;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,CAAC,CAAC,CAAC;IAE5D,kDAAkD;IAClD,6DAA6D;IAC7D,+DAA+D;IAE/D,sCAAsC;IACtC,oEAAoE;IACpE,+DAA+D;IAE/D,+CAA+C;IAC/C,oEAAoE;IACpE,+DAA+D;IAE/D,kDAAkD;IAClD,+DAA+D;IAC/D,+DAA+D;IAE/D,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,CAAC,CAAC;AACF,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;IAC7B,MAAM,CAAC,CAAC;AACV,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/finder.d.ts b/cjs/finder.d.ts similarity index 100% rename from dist/finder.d.ts rename to cjs/finder.d.ts diff --git a/cjs/finder.js b/cjs/finder.js new file mode 100644 index 0000000..52966c6 --- /dev/null +++ b/cjs/finder.js @@ -0,0 +1,200 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.FindUnits = exports.UnitInfo = void 0; +const dgram_1 = require("dgram"); +const events_1 = require("events"); +const debug_1 = __importDefault(require("debug")); +const dns_js_1 = require("./dns.js"); +const debugFind = (0, debug_1.default)("ic:find"); +/** + * Contains connection information for an IntelliCenter controller. + */ +class UnitInfo { + name; + hostname; + port; + address; + get addressStr() { + return (0, dns_js_1.ipToString)(this.address); + } + constructor(_name, _hostname, _port, _address) { + this.name = _name; + this.hostname = _hostname; + this.port = _port; + this.address = _address; + } +} +exports.UnitInfo = UnitInfo; +/** + * Broadcasts mDNS packets to the local network to identify any Pentair IntelliCenter controllers connected to it. + * + * Available events: + * + * * `"close"` - fired when the search socket has closed + * * `"error"` - fired when an unrecoverable error has occurred in the search socket + * * `"serverFound"` - fired immediately when an IntelliCenter unit has been located; receives a {@linkcode UnitInfo} argument + */ +class FindUnits extends events_1.EventEmitter { + broadcastInterface; + /** + * Creates a new finder. + * + * @param broadcastInterface the address of the interface to send the broadcast to. If not specified, will use system selection. Only necessary if you have more than one network adapter/interface and want to search on a specific one. + */ + constructor(broadcastInterface) { + super(); + this.broadcastInterface = broadcastInterface; + // construct mDNS packet to ping for intellicenter controllers + this.message = Buffer.alloc(34); + let offset = 0; + offset = this.message.writeUInt16BE(0, offset); // transaction id + offset = this.message.writeUInt16BE(0, offset); // flags: 0x0 (standard query) + offset = this.message.writeUInt16BE(1, offset); // asking 1 question + offset = this.message.writeUInt16BE(0, offset); // answer rr + offset = this.message.writeUInt16BE(0, offset); // authority rr + offset = this.message.writeUInt16BE(0, offset); // additional rr + offset = this.message.writeUInt8("_http".length, offset); + offset += this.message.write("_http", offset); + offset = this.message.writeUInt8("_tcp".length, offset); + offset += this.message.write("_tcp", offset); + offset = this.message.writeUInt8("local".length, offset); + offset += this.message.write("local", offset); + offset = this.message.writeUInt8(0, offset); // no more strings + offset = this.message.writeUInt16BE(dns_js_1.TypePtr, offset); // type + this.message.writeUInt16BE(1, offset); // class: IN + this.finder = (0, dgram_1.createSocket)("udp4"); + this.finder + .on("listening", () => { + if (this.broadcastInterface) { + this.finder.setMulticastInterface(this.broadcastInterface); + } + this.finder.setBroadcast(true); + this.finder.setMulticastTTL(128); + if (!this.bound) { + this.bound = true; + this.sendServerBroadcast(); + } + }) + .on("message", (msg) => { + this.foundServer(msg); + }) + .on("close", () => { + debugFind("Finder socket closed."); + this.emit("close"); + }) + .on("error", (e) => { + debugFind("Finder socket error: %O", e); + this.emit("error", e); + }); + } + finder; + bound = false; + message; + units = []; + /** + * Begins a search and returns immediately. Must close the finder with close() when done with all searches. + * Subscribe to the `"serverFound"` event to receive connected unit information. + */ + search() { + if (!this.bound) { + this.finder.bind(); + } + else { + this.sendServerBroadcast(); + } + } + /** + * Searches for the given amount of time. Must close the finder with close() when done with all searches. + * + * @param searchTimeMs the number of milliseconds to search before giving up and returning found results (default: 5000) + * @returns Promise resolving to a list of discovered {@linkcode UnitInfo}, if any. + */ + async searchAsync(searchTimeMs) { + const p = new Promise((resolve) => { + setTimeout(() => { + if (this.units.length === 0) { + debugFind("No units found searching locally."); + } + this.removeAllListeners(); + resolve(this.units); + }, searchTimeMs ?? 5000); + this.on("serverFound", (unit) => { + debugFind(" found: %o", unit); + this.units.push(unit); + }); + this.search(); + }); + return p; + } + foundServer(msg) { + let flags = 0; + if (msg.length > 4) { + flags = msg.readUInt16BE(2); + const answerBit = 1 << 15; + if ((flags & answerBit) === 0) { + // received query, don't process as answer + return; + } + } + let nextAnswerOffset = 12; + let questions = 0; + if (msg.length >= 6) { + questions = msg.readUInt16BE(4); + let nextQuestionOffset = 12; + for (let i = 0; i < questions; i++) { + const parsed = (0, dns_js_1.GetDNSQuestion)(msg, nextQuestionOffset); + nextQuestionOffset = parsed.endOffset; + } + nextAnswerOffset = nextQuestionOffset; + } + let answers = 0; + if (msg.length >= 8) { + answers = msg.readUInt16BE(6); + } + const records = []; + if (answers > 0) { + for (let i = 0; i < answers; i++) { + if (msg.length <= nextAnswerOffset) { + console.error(`while inspecting dns answers, expected message length > ${nextAnswerOffset.toString()} but it was ${msg.length.toString()}`); + break; + } + const answer = (0, dns_js_1.GetDNSAnswer)(msg, nextAnswerOffset); + if (!answer) { + break; + } + records.push(answer); + nextAnswerOffset = answer.endOffset; + } + } + if (records.find((r) => r.name.startsWith("Pentair -i"))) { + const srv = records.find((r) => r instanceof dns_js_1.SrvRecord); + const a = records.find((r) => r instanceof dns_js_1.ARecord); + if (!srv || !a) { + return; + } + const unit = new UnitInfo(srv.name, a.name, srv.port, a.address); + this.emit("serverFound", unit); + } + else { + debugFind(" found something that wasn't an IntelliCenter unit: %s", records + .filter((r) => r instanceof dns_js_1.PtrRecord) + .map((r) => r.domain) + .join(", ")); + } + } + sendServerBroadcast() { + this.finder.send(this.message, 0, this.message.length, 5353, "224.0.0.251"); + debugFind("Looking for IntelliCenter hosts..."); + } + /** + * Closes the finder socket. + */ + close() { + this.finder.close(); + } +} +exports.FindUnits = FindUnits; +//# sourceMappingURL=finder.js.map \ No newline at end of file diff --git a/cjs/finder.js.map b/cjs/finder.js.map new file mode 100644 index 0000000..f735ff1 --- /dev/null +++ b/cjs/finder.js.map @@ -0,0 +1 @@ +{"version":3,"file":"finder.js","sourceRoot":"","sources":["../finder.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;AAC7C,mCAAsC;AACtC,kDAA0B;AAE1B,qCASkB;AAElB,MAAM,SAAS,GAAG,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAa,QAAQ;IACZ,IAAI,CAAS;IACb,QAAQ,CAAS;IACjB,IAAI,CAAS;IACb,OAAO,CAAS;IAEvB,IAAW,UAAU;QACnB,OAAO,IAAA,mBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,YACE,KAAa,EACb,SAAiB,EACjB,KAAa,EACb,QAAgB;QAEhB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACF;AArBD,4BAqBC;AAED;;;;;;;;GAQG;AACH,MAAa,SAAU,SAAQ,qBAAY;IAMtB;IALnB;;;;OAIG;IACH,YAAmB,kBAA2B;QAC5C,KAAK,EAAE,CAAC;QADS,uBAAkB,GAAlB,kBAAkB,CAAS;QAG5C,8DAA8D;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,iBAAiB;QACjE,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,8BAA8B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/index.d.ts rename to cjs/index.d.ts diff --git a/cjs/index.js b/cjs/index.js new file mode 100644 index 0000000..10da48f --- /dev/null +++ b/cjs/index.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Unit = exports.FindUnits = void 0; +const finder_js_1 = require("./finder.js"); +Object.defineProperty(exports, "FindUnits", { enumerable: true, get: function () { return finder_js_1.FindUnits; } }); +const unit_js_1 = require("./unit.js"); +Object.defineProperty(exports, "Unit", { enumerable: true, get: function () { return unit_js_1.Unit; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/cjs/index.js.map b/cjs/index.js.map new file mode 100644 index 0000000..6536d84 --- /dev/null +++ b/cjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAG/B,0FAHA,qBAAS,OAGA;AAFlB,uCAAiC;AAEb,qFAFX,cAAI,OAEW"} \ No newline at end of file diff --git a/dist/messages/body-status.d.ts b/cjs/messages/body-status.d.ts similarity index 100% rename from dist/messages/body-status.d.ts rename to cjs/messages/body-status.d.ts diff --git a/cjs/messages/body-status.js b/cjs/messages/body-status.js new file mode 100644 index 0000000..28fb10f --- /dev/null +++ b/cjs/messages/body-status.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetBodyStatus = GetBodyStatus; +const request_js_1 = require("./request.js"); +/** + * Requests the status of bodies known to this controller. + * + * The response contains the list of bodies in the `params` field. Each body has + * an `objnam` that should be used to reference that body for future requests. + * When `params`.`STATUS` is `"OFF"`, use `params`.`LSTTMP` to get the temperature + * of the body the last time it was on, or `params`.`TEMP` to get the temperature + * if the `STATUS` is `"ON"`. `LSTTMP` seems to always be accurate, however, whether + * the body is currently on or off. + * + * @returns the object used to issue this request + */ +function GetBodyStatus() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetParamList"; + req.condition = "OBJTYP = BODY"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "ALL"; + reqObj.keys = [ + "OBJTYP: SUBTYP: SNAME: LISTORD: FILTER: LOTMP: TEMP: HITMP: HTSRC: PRIM: SEC: ACT1: ACT2: ACT3: ACT4: CIRCUIT: SPEED: BOOST: SELECT: STATUS: HTMODE : LSTTMP : HEATER : VOL : MANUAL : HNAME : MODE", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=body-status.js.map \ No newline at end of file diff --git a/cjs/messages/body-status.js.map b/cjs/messages/body-status.js.map new file mode 100644 index 0000000..addb925 --- /dev/null +++ b/cjs/messages/body-status.js.map @@ -0,0 +1 @@ +{"version":3,"file":"body-status.js","sourceRoot":"","sources":["../../messages/body-status.ts"],"names":[],"mappings":";;AAcA,sCAcC;AA5BD,6CAAmE;AAEnE;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa;IAC3B,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,eAAe,CAAC;IAChC,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG;QACZ,qMAAqM;KACtM,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/chem-status.d.ts b/cjs/messages/chem-status.d.ts similarity index 100% rename from dist/messages/chem-status.d.ts rename to cjs/messages/chem-status.d.ts diff --git a/cjs/messages/chem-status.js b/cjs/messages/chem-status.js new file mode 100644 index 0000000..70a0f1f --- /dev/null +++ b/cjs/messages/chem-status.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetChemicalStatus = GetChemicalStatus; +const request_js_1 = require("./request.js"); +/** + * Requests the status of chemical controllers known to this controller. + * + * The response contains the list of chemical controllers available in the `objectList` array. + * For example, an IntelliChem may be one of the entries with `objnam` = `"CHM01"`, `params`.`OBJTYP` + * = `"CHEM"`, `params`.`SUBTYP` = `"ICHEM"` while an IntelliChlor salt cell may be `objnam` = `"CHR01"`, + * `params`.`OBJTYP` = `"CHEM"`, `params`.`SUBTYP` = `"ICHLOR"`. IntelliChlor knows the `"SALT"` level + * while IntelliChem knows the `"PH"` values (PHTNK, PHSET, PHVAL), `"ORP"` values (ORPTNK, ORPSET, ORPVAL), + * `"ALK"` (alkalinity), `"CALC"` (calcium hardness), and `"CYACID"` (cyanuric acid). + * + * pH and ORP Set and Val are in their respective units and orders of magnitude (e.g. 7.6, 750) while the TNK + * levels seem to be on a scale of 1-7 (so "7" would be 100% full). + * + * @returns the object used to issue this request + */ +function GetChemicalStatus() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetParamList"; + req.condition = "OBJTYP = CHEM"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "ALL"; + reqObj.keys = [ + "OBJTYP: SUBTYP: SNAME: LISTORD : BODY: PHVAL: ORPVAL: SINDEX : PRIM: SEC : PHTNK : ORPTNK : ALK : CALC : CYACID : SUPER : SALT: COMUART: PHSET: ORPSET: TIMOUT : QUALTY ", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=chem-status.js.map \ No newline at end of file diff --git a/cjs/messages/chem-status.js.map b/cjs/messages/chem-status.js.map new file mode 100644 index 0000000..3088bae --- /dev/null +++ b/cjs/messages/chem-status.js.map @@ -0,0 +1 @@ +{"version":3,"file":"chem-status.js","sourceRoot":"","sources":["../../messages/chem-status.ts"],"names":[],"mappings":";;AAiBA,8CAcC;AA/BD,6CAAmE;AAEnE;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB;IAC/B,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,eAAe,CAAC;IAChC,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG;QACZ,0KAA0K;KAC3K,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/circuit-status.d.ts b/cjs/messages/circuit-status.d.ts similarity index 100% rename from dist/messages/circuit-status.d.ts rename to cjs/messages/circuit-status.d.ts diff --git a/cjs/messages/circuit-status.js b/cjs/messages/circuit-status.js new file mode 100644 index 0000000..9336e1b --- /dev/null +++ b/cjs/messages/circuit-status.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetCircuitStatus = GetCircuitStatus; +const request_js_1 = require("./request.js"); +/** + * Requests the list of circuits known to this controller. + * + * The response contains an `objectList` populated with circuit information. + * + * @returns the object used to issue this request + */ +function GetCircuitStatus() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetParamList"; + req.condition = "OBJTYP = CIRCUIT"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "ALL"; + reqObj.keys = [ + "OBJNAM", + "OBJTYP", + "SUBTYP", + "STATUS", + "BODY", + "SNAME", + "HNAME", + "FREEZE", + "DNTSTP", + "HNAME", + "TIME", + "FEATR", + "USAGE", + "LIMIT", + "USE", + "SHOMNU", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=circuit-status.js.map \ No newline at end of file diff --git a/cjs/messages/circuit-status.js.map b/cjs/messages/circuit-status.js.map new file mode 100644 index 0000000..4cceaef --- /dev/null +++ b/cjs/messages/circuit-status.js.map @@ -0,0 +1 @@ +{"version":3,"file":"circuit-status.js","sourceRoot":"","sources":["../../messages/circuit-status.ts"],"names":[],"mappings":";;AASA,4CA6BC;AAtCD,6CAAmE;AAEnE;;;;;;GAMG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,kBAAkB,CAAC;IACnC,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG;QACZ,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,MAAM;QACN,OAAO;QACP,OAAO;QACP,QAAQ;QACR,QAAQ;QACR,OAAO;QACP,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,KAAK;QACL,QAAQ;KACT,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/configuration.d.ts b/cjs/messages/configuration.d.ts similarity index 100% rename from dist/messages/configuration.d.ts rename to cjs/messages/configuration.d.ts diff --git a/cjs/messages/configuration.js b/cjs/messages/configuration.js new file mode 100644 index 0000000..facfb50 --- /dev/null +++ b/cjs/messages/configuration.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetSystemConfiguration = GetSystemConfiguration; +const request_js_1 = require("./request.js"); +/** + * Requests the configuration of bodies and circuits available to this controller. + * + * The response contains the list of bodies and circuits under the `answer` field. + * Each object has an `objnam` that should be used to reference that object for future requests, + * and `params`.`SNAME` is the user-entered friendly name that can be displayed for the object. + * `params`.`OBJTYP` will be either BODY or CIRCUIT depending on the object it's describing. + * + * Some objects, such as the Pool body, will have the `params`.`OBJLIST` array populated with + * a series of attached objects such as a chlorinator device. + * + * @returns the object used to issue this request + */ +function GetSystemConfiguration() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetQuery"; + req.queryName = "GetConfiguration"; + req.arguments = ""; + return req; +} +//# sourceMappingURL=configuration.js.map \ No newline at end of file diff --git a/cjs/messages/configuration.js.map b/cjs/messages/configuration.js.map new file mode 100644 index 0000000..60d5cc2 --- /dev/null +++ b/cjs/messages/configuration.js.map @@ -0,0 +1 @@ +{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../messages/configuration.ts"],"names":[],"mappings":";;AAeA,wDAOC;AAtBD,6CAAqD;AAErD;;;;;;;;;;;;GAYG;AACH,SAAgB,sBAAsB;IACpC,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC;IACzB,GAAG,CAAC,SAAS,GAAG,kBAAkB,CAAC;IACnC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;IAEnB,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/get-heater.d.ts b/cjs/messages/get-heater.d.ts similarity index 100% rename from dist/messages/get-heater.d.ts rename to cjs/messages/get-heater.d.ts diff --git a/cjs/messages/get-heater.js b/cjs/messages/get-heater.js new file mode 100644 index 0000000..e79c9c8 --- /dev/null +++ b/cjs/messages/get-heater.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetHeaters = GetHeaters; +const request_js_1 = require("./request.js"); +/** + * Requests the list of heaters known to this controller. + * + * The response contains an `objectList` populated with heater information. + * + * @returns the object used to issue this request + */ +function GetHeaters() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetParamList"; + req.condition = "OBJTYP = HEATER"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "ALL"; + reqObj.keys = [ + "OBJTYP: SUBTYP: SNAME: LISTORD: STATUS: PERMIT: TIMOUT: READY: HTMODE : SHOMNU : COOL : COMUART : BODY : HNAME : START : STOP : HEATING : BOOST : TIME : DLY : MODE", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=get-heater.js.map \ No newline at end of file diff --git a/cjs/messages/get-heater.js.map b/cjs/messages/get-heater.js.map new file mode 100644 index 0000000..27abc6f --- /dev/null +++ b/cjs/messages/get-heater.js.map @@ -0,0 +1 @@ +{"version":3,"file":"get-heater.js","sourceRoot":"","sources":["../../messages/get-heater.ts"],"names":[],"mappings":";;AASA,gCAcC;AAvBD,6CAAmE;AAEnE;;;;;;GAMG;AACH,SAAgB,UAAU;IACxB,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,iBAAiB,CAAC;IAClC,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG;QACZ,qKAAqK;KACtK,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/messages.d.ts b/cjs/messages/messages.d.ts similarity index 51% rename from dist/messages/messages.d.ts rename to cjs/messages/messages.d.ts index 35e1881..5fdd4a3 100644 --- a/dist/messages/messages.d.ts +++ b/cjs/messages/messages.d.ts @@ -9,16 +9,4 @@ import { SetHeatMode } from "./set-heater.js"; import { SetObjectStatus } from "./set-object-status.js"; import { SetSetpoint } from "./setpoint.js"; import { GetSystemInformation } from "./system-info.js"; -export declare const messages: { - GetBodyStatus: typeof GetBodyStatus; - GetChemicalStatus: typeof GetChemicalStatus; - GetCircuitStatus: typeof GetCircuitStatus; - GetHeaters: typeof GetHeaters; - GetSchedule: typeof GetSchedule; - GetSystemConfiguration: typeof GetSystemConfiguration; - GetSystemInformation: typeof GetSystemInformation; - SetHeatMode: typeof SetHeatMode; - SetObjectStatus: typeof SetObjectStatus; - SetSetpoint: typeof SetSetpoint; - SubscribeToUpdates: typeof SubscribeToUpdates; -}; +export { GetBodyStatus, GetChemicalStatus, GetCircuitStatus, GetHeaters, GetSchedule, GetSystemConfiguration, GetSystemInformation, SetHeatMode, SetObjectStatus, SetSetpoint, SubscribeToUpdates, }; diff --git a/cjs/messages/messages.js b/cjs/messages/messages.js new file mode 100644 index 0000000..eb2ee6f --- /dev/null +++ b/cjs/messages/messages.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SubscribeToUpdates = exports.SetSetpoint = exports.SetObjectStatus = exports.SetHeatMode = exports.GetSystemInformation = exports.GetSystemConfiguration = exports.GetSchedule = exports.GetHeaters = exports.GetCircuitStatus = exports.GetChemicalStatus = exports.GetBodyStatus = void 0; +const body_status_js_1 = require("./body-status.js"); +Object.defineProperty(exports, "GetBodyStatus", { enumerable: true, get: function () { return body_status_js_1.GetBodyStatus; } }); +const chem_status_js_1 = require("./chem-status.js"); +Object.defineProperty(exports, "GetChemicalStatus", { enumerable: true, get: function () { return chem_status_js_1.GetChemicalStatus; } }); +const circuit_status_js_1 = require("./circuit-status.js"); +Object.defineProperty(exports, "GetCircuitStatus", { enumerable: true, get: function () { return circuit_status_js_1.GetCircuitStatus; } }); +const configuration_js_1 = require("./configuration.js"); +Object.defineProperty(exports, "GetSystemConfiguration", { enumerable: true, get: function () { return configuration_js_1.GetSystemConfiguration; } }); +const get_heater_js_1 = require("./get-heater.js"); +Object.defineProperty(exports, "GetHeaters", { enumerable: true, get: function () { return get_heater_js_1.GetHeaters; } }); +const notify_js_1 = require("./notify.js"); +Object.defineProperty(exports, "SubscribeToUpdates", { enumerable: true, get: function () { return notify_js_1.SubscribeToUpdates; } }); +const schedule_js_1 = require("./schedule.js"); +Object.defineProperty(exports, "GetSchedule", { enumerable: true, get: function () { return schedule_js_1.GetSchedule; } }); +const set_heater_js_1 = require("./set-heater.js"); +Object.defineProperty(exports, "SetHeatMode", { enumerable: true, get: function () { return set_heater_js_1.SetHeatMode; } }); +const set_object_status_js_1 = require("./set-object-status.js"); +Object.defineProperty(exports, "SetObjectStatus", { enumerable: true, get: function () { return set_object_status_js_1.SetObjectStatus; } }); +const setpoint_js_1 = require("./setpoint.js"); +Object.defineProperty(exports, "SetSetpoint", { enumerable: true, get: function () { return setpoint_js_1.SetSetpoint; } }); +const system_info_js_1 = require("./system-info.js"); +Object.defineProperty(exports, "GetSystemInformation", { enumerable: true, get: function () { return system_info_js_1.GetSystemInformation; } }); +//# sourceMappingURL=messages.js.map \ No newline at end of file diff --git a/cjs/messages/messages.js.map b/cjs/messages/messages.js.map new file mode 100644 index 0000000..18894bc --- /dev/null +++ b/cjs/messages/messages.js.map @@ -0,0 +1 @@ +{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../messages/messages.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAa/C,8FAbO,8BAAa,OAaP;AAZf,qDAAqD;AAanD,kGAbO,kCAAiB,OAaP;AAZnB,2DAAuD;AAarD,iGAbO,oCAAgB,OAaP;AAZlB,yDAA4D;AAe1D,uGAfO,yCAAsB,OAeP;AAdxB,mDAA6C;AAY3C,2FAZO,0BAAU,OAYP;AAXZ,2CAAiD;AAkB/C,mGAlBO,8BAAkB,OAkBP;AAjBpB,+CAA4C;AAW1C,4FAXO,yBAAW,OAWP;AAVb,mDAA8C;AAa5C,4FAbO,2BAAW,OAaP;AAZb,iEAAyD;AAavD,gGAbO,sCAAe,OAaP;AAZjB,+CAA4C;AAa1C,4FAbO,yBAAW,OAaP;AAZb,qDAAwD;AAStD,qGATO,qCAAoB,OASP"} \ No newline at end of file diff --git a/dist/messages/notify.d.ts b/cjs/messages/notify.d.ts similarity index 100% rename from dist/messages/notify.d.ts rename to cjs/messages/notify.d.ts diff --git a/cjs/messages/notify.js b/cjs/messages/notify.js new file mode 100644 index 0000000..c66cd9e --- /dev/null +++ b/cjs/messages/notify.js @@ -0,0 +1,35 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SubscribeToUpdates = SubscribeToUpdates; +const request_js_1 = require("./request.js"); +/** + * Requests to subscribe for updates to the given keys. + * + * Keys and objnam should be given matching an objnam known to the controller and a key for that object. + * {@linkcode ICParam} fields are the known list of keys available to subscribe to. + * + * The response contains an acknowledgement of success or failure. When the given keys change, the `Unit` will + * emit a `"notify"` event with an {@linkcode ICResponse} payload for the new values. + * + * @param objnam the name of the object to subscribe to updates on + * @param keys the key or list of keys to subscribe to updates on this object for + * @returns the object used to issue this request + */ +function SubscribeToUpdates(objnam, keys) { + const req = (0, request_js_1.GetRequest)(); + req.command = "RequestParamList"; + req.objectList = []; + let ks; + if (Array.isArray(keys)) { + ks = keys; + } + else { + ks = [keys]; + } + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = objnam; + reqObj.keys = ks; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=notify.js.map \ No newline at end of file diff --git a/cjs/messages/notify.js.map b/cjs/messages/notify.js.map new file mode 100644 index 0000000..29b97db --- /dev/null +++ b/cjs/messages/notify.js.map @@ -0,0 +1 @@ +{"version":3,"file":"notify.js","sourceRoot":"","sources":["../../messages/notify.ts"],"names":[],"mappings":";;AAoBA,gDAqBC;AAzCD,6CAAmE;AAOnE;;;;;;;;;;;;GAYG;AACH,SAAgB,kBAAkB,CAChC,MAAc,EACd,IAAuB;IAEvB,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,kBAAkB,CAAC;IACjC,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,IAAI,EAAY,CAAC;IACjB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,EAAE,GAAG,IAAI,CAAC;IACZ,CAAC;SAAM,CAAC;QACN,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/param.d.ts b/cjs/messages/param.d.ts similarity index 100% rename from dist/messages/param.d.ts rename to cjs/messages/param.d.ts diff --git a/cjs/messages/param.js b/cjs/messages/param.js new file mode 100644 index 0000000..14c3c78 --- /dev/null +++ b/cjs/messages/param.js @@ -0,0 +1,133 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ICParam = void 0; +class ICParam { + // "": "PROGRESS"; + ABSMAX; + ABSMIN; + ACT; + ACT1; + ACT2; + ACT3; + ACT4; + ADDRESS; + ALK; + AVAIL; + BADGE; + BODY; + BOOST; + CALC; + CALIB; + CHILD; + CIRCUIT; + CITY; + CLK24A; + COMUART; + COOL; + COOLING; + COUNT; + COUNTRY; + CYACID; + DAY; // list of characters for each day. MTWRFAU: M=Monday, T=Tuesday, W=Wednesday, R=Thursday, F=Friday, A=Saturday, U=Sunday. could be empty to mean "no days assigned" + DLSTIM; + DLY; + DNTSTP; + EMAIL; + EMAIL2; + ENABLE; + FEATR; + FILTER; + FREEZE; + GPM; + GROUP; + HEATER; // name of a heater circuit, e.g. "H0001". "00000" means unset/none. also seen to contain the string "HOLD" in some contexts such as when retrieving scheduling information. + HEATING; + HITMP; // high temperature threshold in whatever units the system is set to. "78" means 78 degrees fahrenheit for a system in F, "30" means 30 degrees celsius for a system in C + HNAME; + HTMODE; + HTSRC; + IN; + LIMIT; + LISTORD; // sorting order. "2", "3", "4", etc. + LOCX; + LOCY; + LOTMP; + LSTTMP; + MANHT; + MANOVR; + MANUAL; + MAX; + MAXF; + MIN; + MINF; + MODE; // seems to be a number, e.g. "0" + NAME; + OBJLIST; + OBJNAM; + OBJTYP; + OFFSET; + ORPSET; + ORPTNK; + ORPVAL; + PARENT; + PARTY; + PASSWRD; + PERMIT; + PHONE; + PHONE2; + PHSET; + PHTNK; + PHVAL; + PRIM; + PRIMFLO; + PRIMTIM; + PRIOR; + PROBE; + PROPNAME; + PWR; + QUALTY; + READY; + RLY; + RPM; + SALT; + SEC; + SELECT; + SERVICE; + SETTMP; + SETTMPNC; + SHARE; + SHOMNU; + SINDEX; + SINGLE; + SNAME; // friendly name for a circuit, e.g. "Pool" + SOURCE; + SMTSRT; // stringified 16-bit bitfield, maybe? "65535" + SPEED; + SRIS; + SSET; + START; // seems to be very context-sensitive start value. sometimes a hint for how to interpret the TIME field ("ABSTIM"), other times as a single number ("6", in Heater response), and others as perhaps a date (in format "MM,DD,YY" where leading 0s are replaced with spaces, e.g. "12,30,24" vs " 1, 6,25") + STATE; + STATIC; + STATUS; + STOP; // seems to be very context-sensitive stop value. sometimes a hint for how to interpret the TIME field ("ABSTIM"), other times as a single number ("3", in Heater response), and others as perhaps a date (in format "MM,DD,YY" where leading 0s are replaced with spaces, e.g. "12,30,24" vs " 1, 6,25") + SUBTYP; + SUPER; + SWIM; + SYNC; + SYSTIM; + TEMP; + TIME; // start time in "hh,mm,ss" format (24hr) + TIMOUT; // seems to sometimes be end time in "hh,mm,ss" format (24hr), i guess that means "timeout" as in "time that this runs out" or something; other times a duration as number of seconds, e.g. "86400" + TIMZON; // timezone offset from UTC, e.g. "-6" + UPDATE; // seems to be a date in "MM/DD/YY" format + USAGE; + USE; + VACFLO; // vacation...flow? + VACTIM; // vacation time? + VALVE; + VER; + VOL; + ZIP; +} +exports.ICParam = ICParam; +//# sourceMappingURL=param.js.map \ No newline at end of file diff --git a/cjs/messages/param.js.map b/cjs/messages/param.js.map new file mode 100644 index 0000000..5745e41 --- /dev/null +++ b/cjs/messages/param.js.map @@ -0,0 +1 @@ +{"version":3,"file":"param.js","sourceRoot":"","sources":["../../messages/param.ts"],"names":[],"mappings":";;;AAAA,MAAa,OAAO;IAClB,kBAAkB;IACX,MAAM,CAAU;IAChB,MAAM,CAAU;IAChB,GAAG,CAAU;IACb,IAAI,CAAU;IACd,IAAI,CAAU;IACd,IAAI,CAAU;IACd,IAAI,CAAU;IACd,OAAO,CAAU;IACjB,GAAG,CAAU;IACb,KAAK,CAA0B;IAC/B,KAAK,CAAU;IACf,IAAI,CAAU;IACd,KAAK,CAAU;IACf,IAAI,CAAU;IACd,KAAK,CAAU;IACf,KAAK,CAAU;IACf,OAAO,CAAU;IACjB,IAAI,CAAU;IACd,MAAM,CAAU;IAChB,OAAO,CAAU;IACjB,IAAI,CAAU;IACd,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,GAAG,CAAU,CAAC,oKAAoK;IAClL,MAAM,CAA2B;IACjC,GAAG,CAAU;IACb,MAAM,CAAU;IAChB,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,MAAM,CAA2B;IACjC,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,MAAM,CAAU;IAChB,GAAG,CAAU;IACb,KAAK,CAAU;IACf,MAAM,CAAU,CAAC,4KAA4K;IAC7L,OAAO,CAA4B;IACnC,KAAK,CAAU,CAAC,yKAAyK;IACzL,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,KAAK,CAAU;IACf,EAAE,CAAU;IACZ,KAAK,CAAU;IACf,OAAO,CAAU,CAAC,qCAAqC;IACvD,IAAI,CAAU;IACd,IAAI,CAAU;IACd,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,KAAK,CAA0B;IAC/B,MAAM,CAA2B;IACjC,MAAM,CAAU;IAChB,GAAG,CAAU;IACb,IAAI,CAAU;IACd,GAA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K,CAAU;IACf,GAAG,CAAU;IACb,MAAM,CAA2B,CAAC,mBAAmB;IACrD,MAAM,CAA2B,CAAC,iBAAiB;IACnD,KAAK,CAA0B;IAC/B,GAAG,CAAU;IACb,GAAG,CAAU;IACb,GAAG,CAAU;CACrB;AA/HD,0BA+HC"} \ No newline at end of file diff --git a/dist/messages/request.d.ts b/cjs/messages/request.d.ts similarity index 100% rename from dist/messages/request.d.ts rename to cjs/messages/request.d.ts diff --git a/cjs/messages/request.js b/cjs/messages/request.js new file mode 100644 index 0000000..bef4232 --- /dev/null +++ b/cjs/messages/request.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ICRequest = exports.ICRequestObj = void 0; +exports.GetRequest = GetRequest; +const uuid_1 = require("uuid"); +class ICRequestObj { + objnam = ""; + keys = []; + params; +} +exports.ICRequestObj = ICRequestObj; +class ICRequest { + condition; + objectList; + queryName; + arguments; + command = ""; + messageID = ""; +} +exports.ICRequest = ICRequest; +function GetRequest() { + const req = new ICRequest(); + req.messageID = (0, uuid_1.v4)(); + return req; +} +//# sourceMappingURL=request.js.map \ No newline at end of file diff --git a/cjs/messages/request.js.map b/cjs/messages/request.js.map new file mode 100644 index 0000000..802063a --- /dev/null +++ b/cjs/messages/request.js.map @@ -0,0 +1 @@ +{"version":3,"file":"request.js","sourceRoot":"","sources":["../../messages/request.ts"],"names":[],"mappings":";;;AAkBA,gCAIC;AAtBD,+BAAoC;AAGpC,MAAa,YAAY;IAChB,MAAM,GAAG,EAAE,CAAC;IACZ,IAAI,GAAa,EAAE,CAAC;IACpB,MAAM,CAAW;CACzB;AAJD,oCAIC;AAED,MAAa,SAAS;IACb,SAAS,CAAU;IACnB,UAAU,CAAkB;IAC5B,SAAS,CAAU;IACnB,SAAS,CAAqB;IAC9B,OAAO,GAAG,EAAE,CAAC;IACb,SAAS,GAAG,EAAE,CAAC;CACvB;AAPD,8BAOC;AAED,SAAgB,UAAU;IACxB,MAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC;IAC5B,GAAG,CAAC,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/response.d.ts b/cjs/messages/response.d.ts similarity index 100% rename from dist/messages/response.d.ts rename to cjs/messages/response.d.ts diff --git a/cjs/messages/response.js b/cjs/messages/response.js new file mode 100644 index 0000000..9dced20 --- /dev/null +++ b/cjs/messages/response.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ICResponse = exports.ICResponseObj = void 0; +class ICResponseObj { + objnam = ""; + params; +} +exports.ICResponseObj = ICResponseObj; +class ICResponse { + command = ""; + messageID = ""; + response = ""; + objectList; + queryName; + answer; + timeSince; + timeNow; +} +exports.ICResponse = ICResponse; +//# sourceMappingURL=response.js.map \ No newline at end of file diff --git a/cjs/messages/response.js.map b/cjs/messages/response.js.map new file mode 100644 index 0000000..0c5694a --- /dev/null +++ b/cjs/messages/response.js.map @@ -0,0 +1 @@ +{"version":3,"file":"response.js","sourceRoot":"","sources":["../../messages/response.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IACjB,MAAM,GAAG,EAAE,CAAC;IACZ,MAAM,CAAW;CACzB;AAHD,sCAGC;AAED,MAAa,UAAU;IACd,OAAO,GAAG,EAAE,CAAC;IACb,SAAS,GAAG,EAAE,CAAC;IACf,QAAQ,GAAG,EAAE,CAAC;IACd,UAAU,CAAmB;IAC7B,SAAS,CAAU;IACnB,MAAM,CAAmB;IACzB,SAAS,CAAU;IACnB,OAAO,CAAU;CACzB;AATD,gCASC"} \ No newline at end of file diff --git a/dist/messages/schedule.d.ts b/cjs/messages/schedule.d.ts similarity index 100% rename from dist/messages/schedule.d.ts rename to cjs/messages/schedule.d.ts diff --git a/cjs/messages/schedule.js b/cjs/messages/schedule.js new file mode 100644 index 0000000..930ee47 --- /dev/null +++ b/cjs/messages/schedule.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetSchedule = GetSchedule; +const request_js_1 = require("./request.js"); +/** + * Requests the list of schedules set on this controller. + * + * The response contains an `objectList` populated with schedule information. + * + * @returns the object used to issue this request + */ +function GetSchedule() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GetParamList"; + req.condition = "OBJTYP=SCHED"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "ALL"; + reqObj.keys = [ + "OBJNAM : OBJTYP : LISTORD : CIRCUIT : SNAME : DAY : SINGLE : START : TIME : STOP : TIMOUT : GROUP : HEATER : COOLING : LOTMP : SMTSRT : STATUS : DNTSTP : ACT : MODE : AVAIL: VACFLO : VACTIM : UPDATE", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=schedule.js.map \ No newline at end of file diff --git a/cjs/messages/schedule.js.map b/cjs/messages/schedule.js.map new file mode 100644 index 0000000..909b05f --- /dev/null +++ b/cjs/messages/schedule.js.map @@ -0,0 +1 @@ +{"version":3,"file":"schedule.js","sourceRoot":"","sources":["../../messages/schedule.ts"],"names":[],"mappings":";;AASA,kCAcC;AAvBD,6CAAmE;AAEnE;;;;;;GAMG;AACH,SAAgB,WAAW;IACzB,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,cAAc,CAAC;IAC/B,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG;QACZ,wMAAwM;KACzM,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/set-heater.d.ts b/cjs/messages/set-heater.d.ts similarity index 100% rename from dist/messages/set-heater.d.ts rename to cjs/messages/set-heater.d.ts diff --git a/cjs/messages/set-heater.js b/cjs/messages/set-heater.js new file mode 100644 index 0000000..af43f9c --- /dev/null +++ b/cjs/messages/set-heater.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SetHeatMode = SetHeatMode; +const param_js_1 = require("./param.js"); +const request_js_1 = require("./request.js"); +/** + * Requests to turn a body's heater on or off. + * + * This is very WIP. For my pool and my heater configuration, the MODE needs to be 11 to enable my + * heater and 1 to disable all heaters. I have a feeling 11 is unique to my system's configuration, + * but I can't yet determine how to know what 11 maps to in order to make this more generic. + * + * Note that this doesn't necessarily start heating the body by itself - if the body's pump is + * currently off, enabling the heater will not turn it on. If the pump/body is on, then this will + * enable the heater and no further action is required. + * + * @returns the object used to issue this request + */ +function SetHeatMode(bodyObjnam, enabled) { + const req = (0, request_js_1.GetRequest)(); + req.command = "SetParamList"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = bodyObjnam; + reqObj.params = new param_js_1.ICParam(); + reqObj.params.MODE = enabled ? "11" : "1"; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=set-heater.js.map \ No newline at end of file diff --git a/cjs/messages/set-heater.js.map b/cjs/messages/set-heater.js.map new file mode 100644 index 0000000..df5535a --- /dev/null +++ b/cjs/messages/set-heater.js.map @@ -0,0 +1 @@ +{"version":3,"file":"set-heater.js","sourceRoot":"","sources":["../../messages/set-heater.ts"],"names":[],"mappings":";;AAgBA,kCAYC;AA5BD,yCAAqC;AACrC,6CAAmE;AAEnE;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CAAC,UAAkB,EAAE,OAAgB;IAC9D,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,UAAU,CAAC;IAC3B,MAAM,CAAC,MAAM,GAAG,IAAI,kBAAO,EAAE,CAAC;IAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1C,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/set-object-status.d.ts b/cjs/messages/set-object-status.d.ts similarity index 100% rename from dist/messages/set-object-status.d.ts rename to cjs/messages/set-object-status.d.ts diff --git a/cjs/messages/set-object-status.js b/cjs/messages/set-object-status.js new file mode 100644 index 0000000..7d1f491 --- /dev/null +++ b/cjs/messages/set-object-status.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SetObjectStatus = SetObjectStatus; +const param_js_1 = require("./param.js"); +const request_js_1 = require("./request.js"); +/** + * Requests to change the status of objects known to this controller. + * + * Turns one or more objects on or off. Use the `objnam` of the circuit to be set. + * + * @returns the object used to issue this request + */ +function SetObjectStatus(object, status) { + const req = (0, request_js_1.GetRequest)(); + req.command = "SetParamList"; + req.objectList = []; + let objects; + if (Array.isArray(object)) { + objects = object; + } + else { + objects = [object]; + } + for (const i of objects) { + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = i; + reqObj.params = new param_js_1.ICParam(); + reqObj.params.STATUS = status ? "ON" : "OFF"; + req.objectList.push(reqObj); + } + return req; +} +//# sourceMappingURL=set-object-status.js.map \ No newline at end of file diff --git a/cjs/messages/set-object-status.js.map b/cjs/messages/set-object-status.js.map new file mode 100644 index 0000000..9b0c706 --- /dev/null +++ b/cjs/messages/set-object-status.js.map @@ -0,0 +1 @@ +{"version":3,"file":"set-object-status.js","sourceRoot":"","sources":["../../messages/set-object-status.ts"],"names":[],"mappings":";;AAUA,0CAwBC;AAlCD,yCAAqC;AACrC,6CAAmE;AAEnE;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,MAAyB,EACzB,MAAe;IAEf,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,IAAI,OAAiB,CAAC;IACtB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;QAClC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,MAAM,CAAC,MAAM,GAAG,IAAI,kBAAO,EAAE,CAAC;QAC9B,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAC7C,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/setpoint.d.ts b/cjs/messages/setpoint.d.ts similarity index 100% rename from dist/messages/setpoint.d.ts rename to cjs/messages/setpoint.d.ts diff --git a/cjs/messages/setpoint.js b/cjs/messages/setpoint.js new file mode 100644 index 0000000..26aa266 --- /dev/null +++ b/cjs/messages/setpoint.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SetSetpoint = SetSetpoint; +const param_js_1 = require("./param.js"); +const request_js_1 = require("./request.js"); +/** + * Requests to change the setpoint of a temperature circuit. + * + * Use the `objnam` of the circuit to be set and give the temperature in the same units that the + * controller is set to (so, give a number in Celsius if the system is in Celsius or Fahrenheit + * if the system is in Fahrenheit). + * + * @returns the object used to issue this request + */ +function SetSetpoint(objnam, setpoint) { + const req = (0, request_js_1.GetRequest)(); + req.command = "SetParamList"; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = objnam; + reqObj.params = new param_js_1.ICParam(); + reqObj.params.LOTMP = setpoint.toString(); + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=setpoint.js.map \ No newline at end of file diff --git a/cjs/messages/setpoint.js.map b/cjs/messages/setpoint.js.map new file mode 100644 index 0000000..2f66680 --- /dev/null +++ b/cjs/messages/setpoint.js.map @@ -0,0 +1 @@ +{"version":3,"file":"setpoint.js","sourceRoot":"","sources":["../../messages/setpoint.ts"],"names":[],"mappings":";;AAYA,kCAYC;AAxBD,yCAAqC;AACrC,6CAAmE;AAEnE;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,MAAc,EAAE,QAAgB;IAC1D,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,MAAM,GAAG,IAAI,kBAAO,EAAE,CAAC;IAC9B,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC1C,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/dist/messages/system-info.d.ts b/cjs/messages/system-info.d.ts similarity index 100% rename from dist/messages/system-info.d.ts rename to cjs/messages/system-info.d.ts diff --git a/cjs/messages/system-info.js b/cjs/messages/system-info.js new file mode 100644 index 0000000..18c1ada --- /dev/null +++ b/cjs/messages/system-info.js @@ -0,0 +1,46 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GetSystemInformation = GetSystemInformation; +const request_js_1 = require("./request.js"); +/** + * Requests information about this controller such as owner, address, etc. + * + * @returns the object used to issue this request + */ +function GetSystemInformation() { + const req = (0, request_js_1.GetRequest)(); + req.command = "GETPARAMLIST"; + req.condition = ""; + req.objectList = []; + const reqObj = new request_js_1.ICRequestObj(); + reqObj.objnam = "_5451"; + reqObj.keys = [ + "VER", + "MODE", + "ZIP", + "TIMZON", + "PROPNAME", + "NAME", + "ADDRESS", + "CITY", + "STATE", + "PHONE", + "PHONE2", + "EMAIL", + "EMAIL2", + "COUNTRY", + "PHONE", + "LOCX", + "LOCY", + "AVAIL", + "SERVICE", + "UPDATE", + "PROGRESS", + "IN", + "VALVE", + "HEATING", + ]; + req.objectList.push(reqObj); + return req; +} +//# sourceMappingURL=system-info.js.map \ No newline at end of file diff --git a/cjs/messages/system-info.js.map b/cjs/messages/system-info.js.map new file mode 100644 index 0000000..ba91c5c --- /dev/null +++ b/cjs/messages/system-info.js.map @@ -0,0 +1 @@ +{"version":3,"file":"system-info.js","sourceRoot":"","sources":["../../messages/system-info.ts"],"names":[],"mappings":";;AAOA,oDAqCC;AA5CD,6CAAmE;AAEnE;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,MAAM,GAAG,GAAG,IAAA,uBAAU,GAAE,CAAC;IACzB,GAAG,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7B,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;IACnB,GAAG,CAAC,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,yBAAY,EAAE,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,IAAI,GAAG;QACZ,KAAK;QACL,MAAM;QACN,KAAK;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,SAAS;QACT,OAAO;QACP,MAAM;QACN,MAAM;QACN,OAAO;QACP,SAAS;QACT,QAAQ;QACR,UAAU;QACV,IAAI;QACJ,OAAO;QACP,SAAS;KACV,CAAC;IACF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC"} \ No newline at end of file diff --git a/cjs/package.json b/cjs/package.json new file mode 100644 index 0000000..90c11b8 --- /dev/null +++ b/cjs/package.json @@ -0,0 +1 @@ +{"type": "commonjs"} diff --git a/dist/unit.d.ts b/cjs/unit.d.ts similarity index 100% rename from dist/unit.d.ts rename to cjs/unit.d.ts diff --git a/cjs/unit.js b/cjs/unit.js new file mode 100644 index 0000000..fdde91b --- /dev/null +++ b/cjs/unit.js @@ -0,0 +1,144 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Unit = void 0; +const events_1 = require("events"); +const ws_1 = require("ws"); +const debug_1 = __importDefault(require("debug")); +const debugUnit = (0, debug_1.default)("ic:unit"); +/** + * Contains methods to connect to and communicate with an IntelliCenter controller. + * + * Call `connect` to connect to the unit. + * Use `send` to send a message. + * Subscribe to events to process socket conditions, notify updates, and message responses (if not `await`ing the response) + * + * Available events: + * + * * `"response-{messageID}"` - fired once per message sent with `send()` where {messageID} is the ID specified in the {@linkcode ICRequest} given to `send()` + * * `"notify"` - fired when an update is available to a property previously subscribed to via a {@linkcode SubscribeToUpdates} request + * * `"close"` - fired any time the client is closed by any means (timeout, by request, error, etc.) + * * `"open"` - fired when the socket connects to the unit successfully + * * `"error"` - fired when the socket encounters an unrecoverable error and will close + * * `"timeout"` - fired when the socket has not received a ping response within the allowed threshold and will close + * * `"connected"` - fired when a connection has completed successfully + */ +class Unit extends events_1.EventEmitter { + endpoint; + port; + client; + pingTimeout; + pingTimer; + pingInterval = 60000; + constructor(endpoint, port = 6680) { + super(); + this.endpoint = endpoint; + this.port = port; + this.endpoint = endpoint; + this.port = port; + } + /** + * Connects to the specified unit and maintains a connection to it until `close()` is called. + */ + async connect() { + if (this.client) { + throw new Error("can't open a client that is already open"); + } + debugUnit(`connecting to ws://${this.endpoint}:${this.port.toString()}`); + this.client = new ws_1.WebSocket(`ws://${this.endpoint}:${this.port.toString()}`); + const { heartbeat, onClientMessage, socketCleanup } = this; + this.client.on("error", (evt) => { + // todo: emit event so we can reconnect? auto reconnect? + debugUnit("error in websocket: $o", evt); + this.emit("error"); + socketCleanup(); + }); + this.client.on("open", () => { + this.emit("open"); + heartbeat(); + }); + this.client.on("ping", heartbeat); + this.client.on("pong", heartbeat); + this.client.on("close", socketCleanup); + this.client.on("message", onClientMessage); + this.pingTimer = setInterval(() => { + debugUnit("sending ping"); + this.client?.ping(); + }, this.pingInterval); + await new Promise((resolve, reject) => { + this.client?.once("error", reject); + this.client?.once("open", resolve); + }); + debugUnit("connected"); + this.emit("connected"); + } + /** + * Closes the connection to the unit. + */ + close() { + if (!this.client) { + return; + } + debugUnit("closing connection by request"); + this.emit("close"); + this.client.close(); + } + socketCleanup = () => { + debugUnit("socket cleanup"); + this.client?.removeAllListeners(); + this.client = undefined; + if (this.pingTimeout) { + clearTimeout(this.pingTimeout); + this.pingTimeout = undefined; + } + if (this.pingTimer) { + clearInterval(this.pingTimer); + this.pingTimer = undefined; + } + }; + heartbeat = () => { + debugUnit("received heartbeat"); + clearTimeout(this.pingTimeout); + this.pingTimeout = setTimeout(() => { + debugUnit("terminating connection due to heartbeat timeout"); + this.emit("timeout"); + this.client?.terminate(); + this.socketCleanup(); + }, this.pingInterval + 5000); + }; + onClientMessage = (msg) => { + debugUnit("message received, length %d", msg.length); + const respObj = JSON.parse(msg.toString()); + if (respObj.command.toLowerCase() === "notifylist") { + debugUnit(" it's a subscription confirmation or update"); + this.emit(`notify`, respObj); + } + this.emit(`response-${respObj.messageID}`, respObj); + }; + /** + * Sends a request to the unit. + * + * @param request an message from {@linkcode messages} to send to the unit. + * @returns a promise that resolves into the {@linkcode ICResponse} with information about the request. + */ + async send(request) { + if (!this.client) { + return await new Promise(() => { + throw new Error("client not connected"); + }); + } + const payload = JSON.stringify(request); + debugUnit("sending message of length %d with id %s", payload.length, request.messageID); + this.client.send(payload); + return await new Promise((resolve) => { + this.once(`response-${request.messageID}`, (resp) => { + debugUnit(" returning response to message %s", request.messageID); + resolve(resp); + }); + }); + } +} +exports.Unit = Unit; +//# sourceMappingURL=unit.js.map \ No newline at end of file diff --git a/cjs/unit.js.map b/cjs/unit.js.map new file mode 100644 index 0000000..27ffe60 --- /dev/null +++ b/cjs/unit.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unit.js","sourceRoot":"","sources":["../unit.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAsC;AACtC,2BAA+B;AAC/B,kDAA0B;AAU1B,MAAM,SAAS,GAAG,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;AAEnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,IAAK,SAAQ,qBAAY;IAO3B;IACA;IAPD,MAAM,CAAa;IACnB,WAAW,CAAiC;IAC5C,SAAS,CAAkC;IAC3C,YAAY,GAAG,KAAK,CAAC;IAE7B,YACS,QAAgB,EAChB,OAAO,IAAI;QAElB,KAAK,EAAE,CAAC;QAHD,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAO;QAIlB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,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C,YAAY,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,IAAgB,EAAE,EAAE;gBAC9D,SAAS,CAAC,oCAAoC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;gBACnE,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9ID,oBA8IC"} \ No newline at end of file diff --git a/dist/example.js b/dist/example.js deleted file mode 100644 index 6ef7897..0000000 --- a/dist/example.js +++ /dev/null @@ -1,63 +0,0 @@ -"use strict"; -import { FindUnits, Unit } from "./index.js"; -import { messages } from "./messages/messages.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"); -unit.on("notify", (msg) => { - console.log("received notify:", msg); -}); -console.log("subscribing for updates..."); -let resp = await unit.send(messages.SubscribeToUpdates("B1202", "LOTMP")); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get System Info request..."); -resp = await unit.send(messages.GetSystemInformation()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get System Config request..."); -resp = await unit.send(messages.GetSystemConfiguration()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get Body Status request..."); -resp = await unit.send(messages.GetBodyStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get Chemical Status request..."); -resp = await unit.send(messages.GetChemicalStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get Heaters request..."); -resp = await unit.send(messages.GetHeaters()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get Schedule request..."); -resp = await unit.send(messages.GetSchedule()); -console.log("got response:", JSON.stringify(resp, null, 2)); -console.log("sending Get Circuit Status request..."); -resp = await unit.send(messages.GetCircuitStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); -// console.log("sending Set Setpoint request..."); -// resp = await unit.send(messages.SetSetpoint("B1202", 97)); -// console.log("got response:", JSON.stringify(resp, null, 2)); -// console.log("turning off pool..."); -// resp = await unit.send(messages.SetObjectStatus("B1101", false)); -// console.log("got response:", JSON.stringify(resp, null, 2)); -// console.log("turning off water feature..."); -// resp = await unit.send(messages.SetObjectStatus("C0003", false)); -// console.log("got response:", JSON.stringify(resp, null, 2)); -// console.log("sending Set Heatmode request..."); -// resp = await unit.send(messages.SetHeatMode("B1202", true)); -// console.log("got response:", JSON.stringify(resp, null, 2)); -unit.close(); -//# sourceMappingURL=example.js.map \ No newline at end of file diff --git a/dist/example.js.map b/dist/example.js.map deleted file mode 100644 index afd304b..0000000 --- a/dist/example.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"example.js","sourceRoot":"","sources":["../example.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAC5B,MAAM,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC,KAAK,EAAE,CAAC;AACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;AAExC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC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e,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE5D,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACrD,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACpD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE5D,kDAAkD;AAClD,6DAA6D;AAC7D,+DAA+D;AAE/D,sCAAsC;AACtC,oEAAoE;AACpE,+DAA+D;AAE/D,+CAA+C;AAC/C,oEAAoE;AACpE,+DAA+D;AAE/D,kDAAkD;AAClD,+DAA+D;AAC/D,+DAA+D;AAE/D,IAAI,CAAC,KAAK,EAAE,CAAC"} \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index 055d0a9..1770a17 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,6 +14,6 @@ export default tseslint.config( }, }, { - ignores: ["dist/**", "eslint.config.mjs"], + ignores: ["cjs/**", "esm/**", "eslint.config.mjs"], }, ); diff --git a/esm/dns.d.ts b/esm/dns.d.ts new file mode 100644 index 0000000..f661c49 --- /dev/null +++ b/esm/dns.d.ts @@ -0,0 +1,35 @@ +export declare const TypeTxt = 16; +export declare const TypePtr = 12; +export declare const TypeSrv = 33; +export declare const TypeA = 1; +export declare class Question { + name: string; + type: number; + class: number; + endOffset: number; +} +export declare abstract class Record { + type: number; + ttlSeconds: number; + name: string; + endOffset: number; +} +export declare class PtrRecord extends Record { + domain: string; +} +export declare class TxtRecord extends Record { + text: string; +} +export declare class SrvRecord extends Record { + priority: number; + weight: number; + port: number; + target: string; +} +export declare class ARecord extends Record { + address: number; + get addressStr(): string; +} +export declare function ipToString(ip: number): string; +export declare function GetDNSQuestion(msg: Buffer, startOffset: number): Question; +export declare function GetDNSAnswer(msg: Buffer, startOffset: number): Record | undefined; diff --git a/dist/dns.js b/esm/dns.js similarity index 100% rename from dist/dns.js rename to esm/dns.js diff --git a/dist/dns.js.map b/esm/dns.js.map similarity index 100% rename from dist/dns.js.map rename to esm/dns.js.map diff --git a/esm/example.d.ts b/esm/example.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/esm/example.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/esm/example.js b/esm/example.js new file mode 100644 index 0000000..53ce7e6 --- /dev/null +++ b/esm/example.js @@ -0,0 +1,68 @@ +"use strict"; +import { FindUnits, Unit } from "./index.js"; +import * as messages from "./messages/messages.js"; +const example = async () => { + 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"); + unit.on("notify", (msg) => { + console.log("received notify:", msg); + }); + console.log("subscribing for updates..."); + let resp = await unit.send(messages.SubscribeToUpdates("B1202", "LOTMP")); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get System Info request..."); + resp = await unit.send(messages.GetSystemInformation()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get System Config request..."); + resp = await unit.send(messages.GetSystemConfiguration()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Body Status request..."); + resp = await unit.send(messages.GetBodyStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Chemical Status request..."); + resp = await unit.send(messages.GetChemicalStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Heaters request..."); + resp = await unit.send(messages.GetHeaters()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Schedule request..."); + resp = await unit.send(messages.GetSchedule()); + console.log("got response:", JSON.stringify(resp, null, 2)); + console.log("sending Get Circuit Status request..."); + resp = await unit.send(messages.GetCircuitStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("sending Set Setpoint request..."); + // resp = await unit.send(messages.SetSetpoint("B1202", 97)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("turning off pool..."); + // resp = await unit.send(messages.SetObjectStatus("B1101", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("turning off water feature..."); + // resp = await unit.send(messages.SetObjectStatus("C0003", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + // console.log("sending Set Heatmode request..."); + // resp = await unit.send(messages.SetHeatMode("B1202", true)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + unit.close(); +}; +example().catch((e) => { + throw e; +}); +//# sourceMappingURL=example.js.map \ No newline at end of file diff --git a/esm/example.js.map b/esm/example.js.map new file mode 100644 index 0000000..749af8d --- /dev/null +++ b/esm/example.js.map @@ -0,0 +1 @@ +{"version":3,"file":"example.js","sourceRoot":"","sources":["../example.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AAEnD,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;IACzB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,MAAM,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,KAAK,EAAE,CAAC;IACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAExC,IAAI,KAAK,CAAC,MAAM,KA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AC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAE5D,kDAAkD;IAClD,6DAA6D;IAC7D,+DAA+D;IAE/D,sCAAsC;IACtC,oEAAoE;IACpE,+DAA+D;IAE/D,+CAA+C;IAC/C,oEAAoE;IACpE,+DAA+D;IAE/D,kDAAkD;IAClD,+DAA+D;IAC/D,+DAA+D;IAE/D,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,CAAC,CAAC;AACF,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;IAC7B,MAAM,CAAC,CAAC;AACV,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/esm/finder.d.ts b/esm/finder.d.ts new file mode 100644 index 0000000..c005918 --- /dev/null +++ b/esm/finder.d.ts @@ -0,0 +1,52 @@ +import { EventEmitter } from "events"; +/** + * Contains connection information for an IntelliCenter controller. + */ +export declare class UnitInfo { + name: string; + hostname: string; + port: number; + address: number; + get addressStr(): string; + constructor(_name: string, _hostname: string, _port: number, _address: number); +} +/** + * Broadcasts mDNS packets to the local network to identify any Pentair IntelliCenter controllers connected to it. + * + * Available events: + * + * * `"close"` - fired when the search socket has closed + * * `"error"` - fired when an unrecoverable error has occurred in the search socket + * * `"serverFound"` - fired immediately when an IntelliCenter unit has been located; receives a {@linkcode UnitInfo} argument + */ +export declare class FindUnits extends EventEmitter { + broadcastInterface?: string | undefined; + /** + * Creates a new finder. + * + * @param broadcastInterface the address of the interface to send the broadcast to. If not specified, will use system selection. Only necessary if you have more than one network adapter/interface and want to search on a specific one. + */ + constructor(broadcastInterface?: string | undefined); + private finder; + private bound; + private message; + private units; + /** + * Begins a search and returns immediately. Must close the finder with close() when done with all searches. + * Subscribe to the `"serverFound"` event to receive connected unit information. + */ + search(): void; + /** + * Searches for the given amount of time. Must close the finder with close() when done with all searches. + * + * @param searchTimeMs the number of milliseconds to search before giving up and returning found results (default: 5000) + * @returns Promise resolving to a list of discovered {@linkcode UnitInfo}, if any. + */ + searchAsync(searchTimeMs?: number): Promise; + private foundServer; + private sendServerBroadcast; + /** + * Closes the finder socket. + */ + close(): void; +} diff --git a/dist/finder.js b/esm/finder.js similarity index 100% rename from dist/finder.js rename to esm/finder.js diff --git a/dist/finder.js.map b/esm/finder.js.map similarity index 100% rename from dist/finder.js.map rename to esm/finder.js.map diff --git a/esm/index.d.ts b/esm/index.d.ts new file mode 100644 index 0000000..3f42f37 --- /dev/null +++ b/esm/index.d.ts @@ -0,0 +1,3 @@ +import { FindUnits } from "./finder.js"; +import { Unit } from "./unit.js"; +export { FindUnits, Unit }; diff --git a/dist/index.js b/esm/index.js similarity index 100% rename from dist/index.js rename to esm/index.js diff --git a/dist/index.js.map b/esm/index.js.map similarity index 100% rename from dist/index.js.map rename to esm/index.js.map diff --git a/esm/messages/body-status.d.ts b/esm/messages/body-status.d.ts new file mode 100644 index 0000000..d2996fb --- /dev/null +++ b/esm/messages/body-status.d.ts @@ -0,0 +1,14 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the status of bodies known to this controller. + * + * The response contains the list of bodies in the `params` field. Each body has + * an `objnam` that should be used to reference that body for future requests. + * When `params`.`STATUS` is `"OFF"`, use `params`.`LSTTMP` to get the temperature + * of the body the last time it was on, or `params`.`TEMP` to get the temperature + * if the `STATUS` is `"ON"`. `LSTTMP` seems to always be accurate, however, whether + * the body is currently on or off. + * + * @returns the object used to issue this request + */ +export declare function GetBodyStatus(): ICRequest; diff --git a/dist/messages/body-status.js b/esm/messages/body-status.js similarity index 100% rename from dist/messages/body-status.js rename to esm/messages/body-status.js diff --git a/dist/messages/body-status.js.map b/esm/messages/body-status.js.map similarity index 100% rename from dist/messages/body-status.js.map rename to esm/messages/body-status.js.map diff --git a/esm/messages/chem-status.d.ts b/esm/messages/chem-status.d.ts new file mode 100644 index 0000000..1eb7fc8 --- /dev/null +++ b/esm/messages/chem-status.d.ts @@ -0,0 +1,17 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the status of chemical controllers known to this controller. + * + * The response contains the list of chemical controllers available in the `objectList` array. + * For example, an IntelliChem may be one of the entries with `objnam` = `"CHM01"`, `params`.`OBJTYP` + * = `"CHEM"`, `params`.`SUBTYP` = `"ICHEM"` while an IntelliChlor salt cell may be `objnam` = `"CHR01"`, + * `params`.`OBJTYP` = `"CHEM"`, `params`.`SUBTYP` = `"ICHLOR"`. IntelliChlor knows the `"SALT"` level + * while IntelliChem knows the `"PH"` values (PHTNK, PHSET, PHVAL), `"ORP"` values (ORPTNK, ORPSET, ORPVAL), + * `"ALK"` (alkalinity), `"CALC"` (calcium hardness), and `"CYACID"` (cyanuric acid). + * + * pH and ORP Set and Val are in their respective units and orders of magnitude (e.g. 7.6, 750) while the TNK + * levels seem to be on a scale of 1-7 (so "7" would be 100% full). + * + * @returns the object used to issue this request + */ +export declare function GetChemicalStatus(): ICRequest; diff --git a/dist/messages/chem-status.js b/esm/messages/chem-status.js similarity index 100% rename from dist/messages/chem-status.js rename to esm/messages/chem-status.js diff --git a/dist/messages/chem-status.js.map b/esm/messages/chem-status.js.map similarity index 100% rename from dist/messages/chem-status.js.map rename to esm/messages/chem-status.js.map diff --git a/esm/messages/circuit-status.d.ts b/esm/messages/circuit-status.d.ts new file mode 100644 index 0000000..af474b7 --- /dev/null +++ b/esm/messages/circuit-status.d.ts @@ -0,0 +1,9 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the list of circuits known to this controller. + * + * The response contains an `objectList` populated with circuit information. + * + * @returns the object used to issue this request + */ +export declare function GetCircuitStatus(): ICRequest; diff --git a/dist/messages/circuit-status.js b/esm/messages/circuit-status.js similarity index 100% rename from dist/messages/circuit-status.js rename to esm/messages/circuit-status.js diff --git a/dist/messages/circuit-status.js.map b/esm/messages/circuit-status.js.map similarity index 100% rename from dist/messages/circuit-status.js.map rename to esm/messages/circuit-status.js.map diff --git a/esm/messages/configuration.d.ts b/esm/messages/configuration.d.ts new file mode 100644 index 0000000..b023465 --- /dev/null +++ b/esm/messages/configuration.d.ts @@ -0,0 +1,15 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the configuration of bodies and circuits available to this controller. + * + * The response contains the list of bodies and circuits under the `answer` field. + * Each object has an `objnam` that should be used to reference that object for future requests, + * and `params`.`SNAME` is the user-entered friendly name that can be displayed for the object. + * `params`.`OBJTYP` will be either BODY or CIRCUIT depending on the object it's describing. + * + * Some objects, such as the Pool body, will have the `params`.`OBJLIST` array populated with + * a series of attached objects such as a chlorinator device. + * + * @returns the object used to issue this request + */ +export declare function GetSystemConfiguration(): ICRequest; diff --git a/dist/messages/configuration.js b/esm/messages/configuration.js similarity index 100% rename from dist/messages/configuration.js rename to esm/messages/configuration.js diff --git a/dist/messages/configuration.js.map b/esm/messages/configuration.js.map similarity index 100% rename from dist/messages/configuration.js.map rename to esm/messages/configuration.js.map diff --git a/esm/messages/get-heater.d.ts b/esm/messages/get-heater.d.ts new file mode 100644 index 0000000..4add7c1 --- /dev/null +++ b/esm/messages/get-heater.d.ts @@ -0,0 +1,9 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the list of heaters known to this controller. + * + * The response contains an `objectList` populated with heater information. + * + * @returns the object used to issue this request + */ +export declare function GetHeaters(): ICRequest; diff --git a/dist/messages/get-heater.js b/esm/messages/get-heater.js similarity index 100% rename from dist/messages/get-heater.js rename to esm/messages/get-heater.js diff --git a/dist/messages/get-heater.js.map b/esm/messages/get-heater.js.map similarity index 100% rename from dist/messages/get-heater.js.map rename to esm/messages/get-heater.js.map diff --git a/esm/messages/messages.d.ts b/esm/messages/messages.d.ts new file mode 100644 index 0000000..5fdd4a3 --- /dev/null +++ b/esm/messages/messages.d.ts @@ -0,0 +1,12 @@ +import { GetBodyStatus } from "./body-status.js"; +import { GetChemicalStatus } from "./chem-status.js"; +import { GetCircuitStatus } from "./circuit-status.js"; +import { GetSystemConfiguration } from "./configuration.js"; +import { GetHeaters } from "./get-heater.js"; +import { SubscribeToUpdates } from "./notify.js"; +import { GetSchedule } from "./schedule.js"; +import { SetHeatMode } from "./set-heater.js"; +import { SetObjectStatus } from "./set-object-status.js"; +import { SetSetpoint } from "./setpoint.js"; +import { GetSystemInformation } from "./system-info.js"; +export { GetBodyStatus, GetChemicalStatus, GetCircuitStatus, GetHeaters, GetSchedule, GetSystemConfiguration, GetSystemInformation, SetHeatMode, SetObjectStatus, SetSetpoint, SubscribeToUpdates, }; diff --git a/dist/messages/messages.js b/esm/messages/messages.js similarity index 70% rename from dist/messages/messages.js rename to esm/messages/messages.js index 35e24af..52c9c01 100644 --- a/dist/messages/messages.js +++ b/esm/messages/messages.js @@ -9,17 +9,5 @@ import { SetHeatMode } from "./set-heater.js"; import { SetObjectStatus } from "./set-object-status.js"; import { SetSetpoint } from "./setpoint.js"; import { GetSystemInformation } from "./system-info.js"; -export const messages = { - GetBodyStatus, - GetChemicalStatus, - GetCircuitStatus, - GetHeaters, - GetSchedule, - GetSystemConfiguration, - GetSystemInformation, - SetHeatMode, - SetObjectStatus, - SetSetpoint, - SubscribeToUpdates, -}; +export { GetBodyStatus, GetChemicalStatus, GetCircuitStatus, GetHeaters, GetSchedule, GetSystemConfiguration, GetSystemInformation, SetHeatMode, SetObjectStatus, SetSetpoint, SubscribeToUpdates, }; //# sourceMappingURL=messages.js.map \ No newline at end of file diff --git a/dist/messages/messages.js.map b/esm/messages/messages.js.map similarity index 75% rename from dist/messages/messages.js.map rename to esm/messages/messages.js.map index 11ea851..94265ef 100644 --- a/dist/messages/messages.js.map +++ b/esm/messages/messages.js.map @@ -1 +1 @@ -{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../messages/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,aAAa;IACb,iBAAiB;IACjB,gBAAgB;IAChB,UAAU;IACV,WAAW;IACX,sBAAsB;IACtB,oBAAoB;IACpB,WAAW;IACX,eAAe;IACf,WAAW;IACX,kBAAkB;CACnB,CAAC"} \ No newline at end of file +{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../messages/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,WAAW,EACX,kBAAkB,GACnB,CAAC"} \ No newline at end of file diff --git a/esm/messages/notify.d.ts b/esm/messages/notify.d.ts new file mode 100644 index 0000000..d799a6f --- /dev/null +++ b/esm/messages/notify.d.ts @@ -0,0 +1,15 @@ +import { ICRequest } from "./request.js"; +/** + * Requests to subscribe for updates to the given keys. + * + * Keys and objnam should be given matching an objnam known to the controller and a key for that object. + * {@linkcode ICParam} fields are the known list of keys available to subscribe to. + * + * The response contains an acknowledgement of success or failure. When the given keys change, the `Unit` will + * emit a `"notify"` event with an {@linkcode ICResponse} payload for the new values. + * + * @param objnam the name of the object to subscribe to updates on + * @param keys the key or list of keys to subscribe to updates on this object for + * @returns the object used to issue this request + */ +export declare function SubscribeToUpdates(objnam: string, keys: string | string[]): ICRequest; diff --git a/dist/messages/notify.js b/esm/messages/notify.js similarity index 100% rename from dist/messages/notify.js rename to esm/messages/notify.js diff --git a/dist/messages/notify.js.map b/esm/messages/notify.js.map similarity index 100% rename from dist/messages/notify.js.map rename to esm/messages/notify.js.map diff --git a/esm/messages/param.d.ts b/esm/messages/param.d.ts new file mode 100644 index 0000000..881ecfe --- /dev/null +++ b/esm/messages/param.d.ts @@ -0,0 +1,127 @@ +export declare class ICParam { + ABSMAX?: string; + ABSMIN?: string; + ACT?: string; + ACT1?: string; + ACT2?: string; + ACT3?: string; + ACT4?: string; + ADDRESS?: string; + ALK?: string; + AVAIL?: "AVAIL" | "ON" | "OFF"; + BADGE?: string; + BODY?: string; + BOOST?: string; + CALC?: string; + CALIB?: string; + CHILD?: string; + CIRCUIT?: string; + CITY?: string; + CLK24A?: string; + COMUART?: string; + COOL?: string; + COOLING?: string; + COUNT?: string; + COUNTRY?: string; + CYACID?: string; + DAY?: string; + DLSTIM?: "DLSTIM" | "ON" | "OFF"; + DLY?: string; + DNTSTP?: string; + EMAIL?: string; + EMAIL2?: string; + ENABLE?: "ENABLE" | "ON" | "OFF"; + FEATR?: string; + FILTER?: string; + FREEZE?: string; + GPM?: string; + GROUP?: string; + HEATER?: string; + HEATING?: "HEATING" | "ON" | "OFF"; + HITMP?: string; + HNAME?: string; + HTMODE?: string; + HTSRC?: string; + IN?: string; + LIMIT?: string; + LISTORD?: string; + LOCX?: string; + LOCY?: string; + LOTMP?: string; + LSTTMP?: string; + MANHT?: "MANHT" | "ON" | "OFF"; + MANOVR?: "MANOVR" | "ON" | "OFF"; + MANUAL?: string; + MAX?: string; + MAXF?: string; + MIN?: string; + MINF?: string; + MODE?: string; + NAME?: string; + OBJLIST?: ICParam[]; + OBJNAM?: string; + OBJTYP?: string; + OFFSET?: string; + ORPSET?: string; + ORPTNK?: string; + ORPVAL?: string; + PARENT?: string; + PARTY?: string; + PASSWRD?: string; + PERMIT?: string; + PHONE?: string; + PHONE2?: string; + PHSET?: string; + PHTNK?: string; + PHVAL?: string; + PRIM?: string; + PRIMFLO?: string; + PRIMTIM?: string; + PRIOR?: string; + PROBE?: string; + PROPNAME?: string; + PWR?: string; + QUALTY?: string; + READY?: string; + RLY?: string; + RPM?: string; + SALT?: string; + SEC?: string; + SELECT?: string; + SERVICE?: "SERVICE" | "AUTO" | "TIMEOUT"; + SETTMP?: string; + SETTMPNC?: string; + SHARE?: string; + SHOMNU?: string; + SINDEX?: string; + SINGLE?: "SINGLE" | "ON" | "OFF"; + SNAME?: string; + SOURCE?: string; + SMTSRT?: string; + SPEED?: string; + SRIS?: string; + SSET?: string; + START?: string; + STATE?: string; + STATIC?: string; + STATUS?: "STATUS" | "ON" | "OFF"; + STOP?: string; + SUBTYP?: string; + SUPER?: "SUPER" | "ON" | "OFF"; + SWIM?: string; + SYNC?: string; + SYSTIM?: string; + TEMP?: string; + TIME?: string; + TIMOUT?: string; + TIMZON?: string; + UPDATE?: string; + USAGE?: string; + USE?: string; + VACFLO?: "VACFLO" | "ON" | "OFF"; + VACTIM?: "VACTIM" | "ON" | "OFF"; + VALVE?: "VALVE" | "ON" | "OFF"; + VER?: string; + VOL?: string; + ZIP?: string; +} diff --git a/dist/messages/param.js b/esm/messages/param.js similarity index 100% rename from dist/messages/param.js rename to esm/messages/param.js diff --git a/dist/messages/param.js.map b/esm/messages/param.js.map similarity index 100% rename from dist/messages/param.js.map rename to esm/messages/param.js.map diff --git a/esm/messages/request.d.ts b/esm/messages/request.d.ts new file mode 100644 index 0000000..4823bcc --- /dev/null +++ b/esm/messages/request.d.ts @@ -0,0 +1,15 @@ +import { ICParam } from "./param.js"; +export declare class ICRequestObj { + objnam: string; + keys: string[]; + params?: ICParam; +} +export declare class ICRequest { + condition?: string; + objectList?: ICRequestObj[]; + queryName?: string; + arguments?: string[] | string; + command: string; + messageID: string; +} +export declare function GetRequest(): ICRequest; diff --git a/dist/messages/request.js b/esm/messages/request.js similarity index 100% rename from dist/messages/request.js rename to esm/messages/request.js diff --git a/dist/messages/request.js.map b/esm/messages/request.js.map similarity index 100% rename from dist/messages/request.js.map rename to esm/messages/request.js.map diff --git a/esm/messages/response.d.ts b/esm/messages/response.d.ts new file mode 100644 index 0000000..2feeeb9 --- /dev/null +++ b/esm/messages/response.d.ts @@ -0,0 +1,15 @@ +import { ICParam } from "./param.js"; +export declare class ICResponseObj { + objnam: string; + params?: ICParam; +} +export declare class ICResponse { + command: string; + messageID: string; + response: string; + objectList?: ICResponseObj[]; + queryName?: string; + answer?: ICResponseObj[]; + timeSince?: string; + timeNow?: string; +} diff --git a/dist/messages/response.js b/esm/messages/response.js similarity index 100% rename from dist/messages/response.js rename to esm/messages/response.js diff --git a/dist/messages/response.js.map b/esm/messages/response.js.map similarity index 100% rename from dist/messages/response.js.map rename to esm/messages/response.js.map diff --git a/esm/messages/schedule.d.ts b/esm/messages/schedule.d.ts new file mode 100644 index 0000000..a903954 --- /dev/null +++ b/esm/messages/schedule.d.ts @@ -0,0 +1,9 @@ +import { ICRequest } from "./request.js"; +/** + * Requests the list of schedules set on this controller. + * + * The response contains an `objectList` populated with schedule information. + * + * @returns the object used to issue this request + */ +export declare function GetSchedule(): ICRequest; diff --git a/dist/messages/schedule.js b/esm/messages/schedule.js similarity index 100% rename from dist/messages/schedule.js rename to esm/messages/schedule.js diff --git a/dist/messages/schedule.js.map b/esm/messages/schedule.js.map similarity index 100% rename from dist/messages/schedule.js.map rename to esm/messages/schedule.js.map diff --git a/esm/messages/set-heater.d.ts b/esm/messages/set-heater.d.ts new file mode 100644 index 0000000..3a89ecb --- /dev/null +++ b/esm/messages/set-heater.d.ts @@ -0,0 +1,15 @@ +import { ICRequest } from "./request.js"; +/** + * Requests to turn a body's heater on or off. + * + * This is very WIP. For my pool and my heater configuration, the MODE needs to be 11 to enable my + * heater and 1 to disable all heaters. I have a feeling 11 is unique to my system's configuration, + * but I can't yet determine how to know what 11 maps to in order to make this more generic. + * + * Note that this doesn't necessarily start heating the body by itself - if the body's pump is + * currently off, enabling the heater will not turn it on. If the pump/body is on, then this will + * enable the heater and no further action is required. + * + * @returns the object used to issue this request + */ +export declare function SetHeatMode(bodyObjnam: string, enabled: boolean): ICRequest; diff --git a/dist/messages/set-heater.js b/esm/messages/set-heater.js similarity index 100% rename from dist/messages/set-heater.js rename to esm/messages/set-heater.js diff --git a/dist/messages/set-heater.js.map b/esm/messages/set-heater.js.map similarity index 100% rename from dist/messages/set-heater.js.map rename to esm/messages/set-heater.js.map diff --git a/esm/messages/set-object-status.d.ts b/esm/messages/set-object-status.d.ts new file mode 100644 index 0000000..73932eb --- /dev/null +++ b/esm/messages/set-object-status.d.ts @@ -0,0 +1,9 @@ +import { ICRequest } from "./request.js"; +/** + * Requests to change the status of objects known to this controller. + * + * Turns one or more objects on or off. Use the `objnam` of the circuit to be set. + * + * @returns the object used to issue this request + */ +export declare function SetObjectStatus(object: string | string[], status: boolean): ICRequest; diff --git a/dist/messages/set-object-status.js b/esm/messages/set-object-status.js similarity index 100% rename from dist/messages/set-object-status.js rename to esm/messages/set-object-status.js diff --git a/dist/messages/set-object-status.js.map b/esm/messages/set-object-status.js.map similarity index 100% rename from dist/messages/set-object-status.js.map rename to esm/messages/set-object-status.js.map diff --git a/esm/messages/setpoint.d.ts b/esm/messages/setpoint.d.ts new file mode 100644 index 0000000..0d6823e --- /dev/null +++ b/esm/messages/setpoint.d.ts @@ -0,0 +1,11 @@ +import { ICRequest } from "./request.js"; +/** + * Requests to change the setpoint of a temperature circuit. + * + * Use the `objnam` of the circuit to be set and give the temperature in the same units that the + * controller is set to (so, give a number in Celsius if the system is in Celsius or Fahrenheit + * if the system is in Fahrenheit). + * + * @returns the object used to issue this request + */ +export declare function SetSetpoint(objnam: string, setpoint: number): ICRequest; diff --git a/dist/messages/setpoint.js b/esm/messages/setpoint.js similarity index 100% rename from dist/messages/setpoint.js rename to esm/messages/setpoint.js diff --git a/dist/messages/setpoint.js.map b/esm/messages/setpoint.js.map similarity index 100% rename from dist/messages/setpoint.js.map rename to esm/messages/setpoint.js.map diff --git a/esm/messages/system-info.d.ts b/esm/messages/system-info.d.ts new file mode 100644 index 0000000..8672ac5 --- /dev/null +++ b/esm/messages/system-info.d.ts @@ -0,0 +1,7 @@ +import { ICRequest } from "./request.js"; +/** + * Requests information about this controller such as owner, address, etc. + * + * @returns the object used to issue this request + */ +export declare function GetSystemInformation(): ICRequest; diff --git a/dist/messages/system-info.js b/esm/messages/system-info.js similarity index 100% rename from dist/messages/system-info.js rename to esm/messages/system-info.js diff --git a/dist/messages/system-info.js.map b/esm/messages/system-info.js.map similarity index 100% rename from dist/messages/system-info.js.map rename to esm/messages/system-info.js.map diff --git a/esm/package.json b/esm/package.json new file mode 100644 index 0000000..b89a8b3 --- /dev/null +++ b/esm/package.json @@ -0,0 +1 @@ +{"type": "module"} diff --git a/esm/unit.d.ts b/esm/unit.d.ts new file mode 100644 index 0000000..dae4de6 --- /dev/null +++ b/esm/unit.d.ts @@ -0,0 +1,47 @@ +import { EventEmitter } from "events"; +import { ICRequest } from "./messages/request.js"; +import { ICResponse } from "./messages/response.js"; +/** + * Contains methods to connect to and communicate with an IntelliCenter controller. + * + * Call `connect` to connect to the unit. + * Use `send` to send a message. + * Subscribe to events to process socket conditions, notify updates, and message responses (if not `await`ing the response) + * + * Available events: + * + * * `"response-{messageID}"` - fired once per message sent with `send()` where {messageID} is the ID specified in the {@linkcode ICRequest} given to `send()` + * * `"notify"` - fired when an update is available to a property previously subscribed to via a {@linkcode SubscribeToUpdates} request + * * `"close"` - fired any time the client is closed by any means (timeout, by request, error, etc.) + * * `"open"` - fired when the socket connects to the unit successfully + * * `"error"` - fired when the socket encounters an unrecoverable error and will close + * * `"timeout"` - fired when the socket has not received a ping response within the allowed threshold and will close + * * `"connected"` - fired when a connection has completed successfully + */ +export declare class Unit extends EventEmitter { + endpoint: string; + port: number; + private client?; + private pingTimeout?; + private pingTimer?; + private pingInterval; + constructor(endpoint: string, port?: number); + /** + * Connects to the specified unit and maintains a connection to it until `close()` is called. + */ + connect(): Promise; + /** + * Closes the connection to the unit. + */ + close(): void; + private socketCleanup; + private heartbeat; + private onClientMessage; + /** + * Sends a request to the unit. + * + * @param request an message from {@linkcode messages} to send to the unit. + * @returns a promise that resolves into the {@linkcode ICResponse} with information about the request. + */ + send(request: ICRequest): Promise; +} diff --git a/dist/unit.js b/esm/unit.js similarity index 100% rename from dist/unit.js rename to esm/unit.js diff --git a/dist/unit.js.map b/esm/unit.js.map similarity index 100% rename from dist/unit.js.map rename to esm/unit.js.map diff --git a/example.ts b/example.ts index 48fe23f..fbd28b5 100644 --- a/example.ts +++ b/example.ts @@ -1,85 +1,90 @@ "use strict"; import { FindUnits, Unit } from "./index.js"; -import { messages } from "./messages/messages.js"; +import * as messages from "./messages/messages.js"; -console.log("searching..."); -const f = new FindUnits(); -const units = await f.searchAsync(1000); -f.close(); -console.log("Discovered units:", units); +const example = async () => { + 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 === 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)}`, - ); -} + 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 = units[0].addressStr; + const port = units[0].port; -// const endpoint = "10.0.0.41"; -// const port = 6680; + // 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("connecting to intellicenter device at", endpoint, "port", port); + const unit = new Unit(endpoint, port); + await unit.connect(); + console.log("connected"); -unit.on("notify", (msg) => { - console.log("received notify:", msg); + unit.on("notify", (msg) => { + console.log("received notify:", msg); + }); + + console.log("subscribing for updates..."); + let resp = await unit.send(messages.SubscribeToUpdates("B1202", "LOTMP")); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get System Info request..."); + resp = await unit.send(messages.GetSystemInformation()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get System Config request..."); + resp = await unit.send(messages.GetSystemConfiguration()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get Body Status request..."); + resp = await unit.send(messages.GetBodyStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get Chemical Status request..."); + resp = await unit.send(messages.GetChemicalStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get Heaters request..."); + resp = await unit.send(messages.GetHeaters()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get Schedule request..."); + resp = await unit.send(messages.GetSchedule()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + console.log("sending Get Circuit Status request..."); + resp = await unit.send(messages.GetCircuitStatus()); + console.log("got response:", JSON.stringify(resp, null, 2)); + + // console.log("sending Set Setpoint request..."); + // resp = await unit.send(messages.SetSetpoint("B1202", 97)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + + // console.log("turning off pool..."); + // resp = await unit.send(messages.SetObjectStatus("B1101", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + + // console.log("turning off water feature..."); + // resp = await unit.send(messages.SetObjectStatus("C0003", false)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + + // console.log("sending Set Heatmode request..."); + // resp = await unit.send(messages.SetHeatMode("B1202", true)); + // console.log("got response:", JSON.stringify(resp, null, 2)); + + unit.close(); +}; +example().catch((e: unknown) => { + throw e; }); - -console.log("subscribing for updates..."); -let resp = await unit.send(messages.SubscribeToUpdates("B1202", "LOTMP")); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get System Info request..."); -resp = await unit.send(messages.GetSystemInformation()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get System Config request..."); -resp = await unit.send(messages.GetSystemConfiguration()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get Body Status request..."); -resp = await unit.send(messages.GetBodyStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get Chemical Status request..."); -resp = await unit.send(messages.GetChemicalStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get Heaters request..."); -resp = await unit.send(messages.GetHeaters()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get Schedule request..."); -resp = await unit.send(messages.GetSchedule()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -console.log("sending Get Circuit Status request..."); -resp = await unit.send(messages.GetCircuitStatus()); -console.log("got response:", JSON.stringify(resp, null, 2)); - -// console.log("sending Set Setpoint request..."); -// resp = await unit.send(messages.SetSetpoint("B1202", 97)); -// console.log("got response:", JSON.stringify(resp, null, 2)); - -// console.log("turning off pool..."); -// resp = await unit.send(messages.SetObjectStatus("B1101", false)); -// console.log("got response:", JSON.stringify(resp, null, 2)); - -// console.log("turning off water feature..."); -// resp = await unit.send(messages.SetObjectStatus("C0003", false)); -// console.log("got response:", JSON.stringify(resp, null, 2)); - -// console.log("sending Set Heatmode request..."); -// resp = await unit.send(messages.SetHeatMode("B1202", true)); -// console.log("got response:", JSON.stringify(resp, null, 2)); - -unit.close(); diff --git a/messages/messages.ts b/messages/messages.ts index f02c2f5..597589d 100644 --- a/messages/messages.ts +++ b/messages/messages.ts @@ -10,7 +10,7 @@ import { SetObjectStatus } from "./set-object-status.js"; import { SetSetpoint } from "./setpoint.js"; import { GetSystemInformation } from "./system-info.js"; -export const messages = { +export { GetBodyStatus, GetChemicalStatus, GetCircuitStatus, diff --git a/package-lock.json b/package-lock.json index 7b0e5d5..3fa8603 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "devDependencies": { "@eslint/js": "^9.17.0", "@types/debug": "^4.1.12", + "@types/uuid": "^10.0.0", "@types/ws": "^8.5.13", "eslint": "^9.17.0", "markdownlint-cli2": "^0.17.1", @@ -327,6 +328,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ws": { "version": "8.5.13", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz", diff --git a/package.json b/package.json index f6e04bf..4412312 100644 --- a/package.json +++ b/package.json @@ -22,15 +22,59 @@ "author": "Parnic", "type": "module", "exports": { - ".": "./dist/index.js", - "./unit": "./dist/unit.js", - "./finder": "./dist/finder.js", - "./messages": "./dist/messages/messages.js" + ".": { + "import": { + "types": "./esm/index.d.ts", + "default": "./esm/index.js" + }, + "require": { + "types": "./cjs/index.d.ts", + "default": "./cjs/index.js" + } + }, + "./unit": { + "import": { + "types": "./esm/unit.d.ts", + "default": "./esm/unit.js" + }, + "require": { + "types": "./cjs/unit.d.ts", + "default": "./cjs/unit.js" + } + }, + "./finder": { + "import": { + "types": "./esm/finder.d.ts", + "default": "./esm/finder.js" + }, + "require": { + "types": "./cjs/finder.d.ts", + "default": "./cjs/finder.js" + } + }, + "./messages": { + "import": { + "types": "./esm/messages/messages.d.ts", + "default": "./esm/messages/messages.js" + }, + "require": { + "types": "./cjs/messages/messages.d.ts", + "default": "./cjs/messages/messages.js" + } + } + }, + "typesVersions": { + "*": { + "*": [ + "./cjs/*", + "./cjs/messages/*" + ] + } }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "tsc", - "example": "tsc && node dist/example.js", + "build": "tsc --module commonjs --moduleResolution classic --outDir cjs/ && echo {\"type\": \"commonjs\"} > cjs/package.json && tsc --outDir esm/ && echo {\"type\": \"module\"} > esm/package.json", + "example": "tsc && node esm/example.js", "lint": "eslint . && prettier . --check && markdownlint-cli2 **/*.md", "lint:fix": "eslint . --fix && prettier . --write && markdownlint-cli2 --fix **/*.md" }, @@ -42,6 +86,7 @@ "devDependencies": { "@eslint/js": "^9.17.0", "@types/debug": "^4.1.12", + "@types/uuid": "^10.0.0", "@types/ws": "^8.5.13", "eslint": "^9.17.0", "markdownlint-cli2": "^0.17.1", diff --git a/tsconfig.json b/tsconfig.json index afe60e6..88ad17e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -53,7 +53,7 @@ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "dist" /* Specify an output folder for all emitted files. */, + "outDir": "esm" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ diff --git a/unit.ts b/unit.ts index d477768..d2ef9ae 100644 --- a/unit.ts +++ b/unit.ts @@ -6,7 +6,7 @@ import { ICRequest } from "./messages/request.js"; import { ICResponse } from "./messages/response.js"; // needed for jsdoc // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { messages } from "./messages/messages.js"; +import * as messages from "./messages/messages.js"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { SubscribeToUpdates } from "./messages/notify.js";