@xyo-network/pentair-plugin 2.55.5 → 2.56.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,377 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { FindUnits, RemoteLogin, UnitConnection } from 'node-screenlogic'
3
-
4
- /* From https://github.com/schemers/homebridge-screenlogic */
5
-
6
- interface ControllerOptions {
7
- ip_address?: string
8
- log?: typeof console
9
- password?: string
10
- port?: number
11
- username?: string
12
- }
13
-
14
- export class Controller {
15
- static readonly HEAT_MODE_HEAT_PUMP = 3
16
- static readonly HEAT_MODE_OFF = 0
17
- static readonly HEAT_MODE_SOLAR = 1
18
- static readonly HEAT_MODE_SOLAR_PREFERRED = 2
19
- static readonly HEAT_MODE_UNCHANGED = 4
20
-
21
- static readonly POOL_CIRCUIT_ID = 505
22
- static readonly SPA_CIRCUIT_ID = 500
23
-
24
- private readonly ip_address?: string
25
- private readonly log: typeof console
26
-
27
- private readonly password?: string
28
- private readonly port?: number
29
- private readonly username?: string
30
-
31
- constructor(settings?: ControllerOptions) {
32
- this.log = settings?.log ?? console
33
- this.ip_address = settings?.ip_address
34
- this.port = settings?.port
35
- this.username = settings?.username
36
- this.password = settings?.password
37
- }
38
-
39
- _getConnection(): Promise<UnitConnection> {
40
- if (this.ip_address) {
41
- return this._getConnectionByIPAddress()
42
- } else if (this.username && this.password) {
43
- return this._getConnectionByRemoteLogin()
44
- } else {
45
- return this._getConnectionByBroadcast()
46
- }
47
- }
48
-
49
- /** get a connection by udp broadcast */
50
- _getConnectionByBroadcast(): Promise<UnitConnection> {
51
- return new Promise((resolve, reject) => {
52
- const finder = new FindUnits()
53
- finder
54
- .on('serverFound', (server: { gatewayName: any }) => {
55
- finder.close()
56
- const connection = new UnitConnection(server)
57
- connection.gatewayName = server.gatewayName
58
- resolve(connection)
59
- })
60
- .on('error', (err: any) => {
61
- reject(err)
62
- })
63
- finder.search()
64
- })
65
- }
66
-
67
- /** get a connection by IP address */
68
- _getConnectionByIPAddress(): Promise<UnitConnection> {
69
- return new Promise((resolve, _reject) => {
70
- const connection = new UnitConnection(this.port || 80, this.ip_address, this.password)
71
- connection.gatewayName = this.username ?? 'Pentair: XX-XX-XX'
72
- resolve(connection)
73
- })
74
- }
75
-
76
- /** find a unit by remote login */
77
- _getConnectionByRemoteLogin(): Promise<UnitConnection> {
78
- return new Promise((resolve, reject) => {
79
- const remote = new RemoteLogin(this.username)
80
- remote
81
- .on('gatewayFound', (unit: { gatewayFound: any; ipAddr: any; port: any }) => {
82
- remote.close()
83
- if (unit && unit.gatewayFound) {
84
- const connection = new UnitConnection(unit.port, unit.ipAddr, this.password)
85
- connection.gatewayName = this.username
86
- resolve(connection)
87
- } else {
88
- reject(new ControllerError('no remote unit found'))
89
- }
90
- })
91
- .on('error', (err: Error) => {
92
- reject(err)
93
- })
94
- remote.connect()
95
- })
96
- }
97
-
98
- _getPoolConfig(connection: UnitConnection): Promise<PoolConfig> {
99
- let softwareVersion = ''
100
- return new Promise((resolve, reject) => {
101
- connection
102
- .once('version', (version: any) => {
103
- softwareVersion = version.version
104
- connection.getControllerConfig()
105
- })
106
- .once('controllerConfig', (poolConfig: any) => {
107
- //this.log.debug('controllerConfig', poolConfig)
108
- resolve(new PoolConfig(connection.gatewayName, softwareVersion, poolConfig))
109
- })
110
- .on('error', (err: any) => {
111
- reject(err)
112
- })
113
- connection.getVersion()
114
- })
115
- }
116
-
117
- _getPoolStatus(connection: UnitConnection): Promise<PoolStatus> {
118
- return new Promise((resolve, reject) => {
119
- connection
120
- .once('poolStatus', (status) => {
121
- //this.log.debug('poolStatus', status)
122
- resolve(new PoolStatus(status))
123
- })
124
- .on('error', (err: any) => {
125
- reject(err)
126
- })
127
- connection.getPoolStatus()
128
- })
129
- }
130
-
131
- _login(connection: UnitConnection): Promise<void> {
132
- return new Promise((resolve, reject) => {
133
- connection
134
- .once('loggedIn', () => {
135
- resolve()
136
- })
137
- .once('loginFailed', () => {
138
- reject(new ControllerError('unable to login'))
139
- })
140
- .on('error', (err: any) => {
141
- reject(err)
142
- })
143
- connection.connect()
144
- })
145
- }
146
-
147
- _sendLightCommand(connection: UnitConnection, cmd: number): Promise<void> {
148
- return new Promise((resolve, reject) => {
149
- connection
150
- .once('sentLightCommand', () => {
151
- resolve()
152
- })
153
- .once('badParameter', () => {
154
- reject(new ControllerError('bad parameter passed to send light command'))
155
- })
156
- .on('error', (err: any) => {
157
- reject(err)
158
- })
159
- connection.sendLightCommand(0, cmd)
160
- })
161
- }
162
-
163
- _setCircuitState(connection: UnitConnection, circuitId: number, circuitState: boolean): Promise<void> {
164
- return new Promise((resolve, reject) => {
165
- connection
166
- .once('circuitStateChanged', () => {
167
- resolve()
168
- })
169
- .once('badParameter', () => {
170
- reject(new ControllerError('bad parameter passed to set command'))
171
- })
172
- .on('error', (err: any) => {
173
- reject(err)
174
- })
175
- connection.setCircuitState(0, circuitId, circuitState ? 1 : 0)
176
- })
177
- }
178
-
179
- _setHeatMode(connection: UnitConnection, bodyType: number, heatMode: number): Promise<void> {
180
- return new Promise((resolve, reject) => {
181
- connection
182
- .once('heatModeChanged', () => {
183
- resolve()
184
- })
185
- .once('badParameter', () => {
186
- reject(new ControllerError('bad parameter passed to set command'))
187
- })
188
- .on('error', (err: any) => {
189
- reject(err)
190
- })
191
- connection.setHeatMode(0, bodyType, heatMode)
192
- })
193
- }
194
-
195
- _setHeatPoint(connection: UnitConnection, bodyType: number, heatPoint: number): Promise<void> {
196
- return new Promise((resolve, reject) => {
197
- connection
198
- .once('setPointChanged', () => {
199
- resolve()
200
- })
201
- .once('badParameter', () => {
202
- reject(new ControllerError('bad parameter passed to set command'))
203
- })
204
- .on('error', (err: any) => {
205
- reject(err)
206
- })
207
- connection.setSetPoint(0, bodyType, heatPoint)
208
- })
209
- }
210
-
211
- async getPoolConfig(): Promise<PoolConfig> {
212
- const connection = await this._getConnection()
213
- try {
214
- await this._login(connection)
215
- return await this._getPoolConfig(connection)
216
- } finally {
217
- connection.close()
218
- }
219
- }
220
-
221
- async getPoolStatus(): Promise<PoolStatus> {
222
- const connection = await this._getConnection()
223
- try {
224
- await this._login(connection)
225
- return await this._getPoolStatus(connection)
226
- } finally {
227
- connection.close()
228
- }
229
- }
230
-
231
- async sendLightCommand(cmd: number): Promise<void> {
232
- const connection = await this._getConnection()
233
- try {
234
- await this._login(connection)
235
- return await this._sendLightCommand(connection, cmd)
236
- } finally {
237
- connection.close()
238
- }
239
- }
240
-
241
- async setCircuitState(circuitId: number, circuitState: boolean): Promise<void> {
242
- const connection = await this._getConnection()
243
- try {
244
- await this._login(connection)
245
- return await this._setCircuitState(connection, circuitId, circuitState)
246
- } finally {
247
- connection.close()
248
- }
249
- }
250
-
251
- async setHeatMode(bodyType: number, heatMode: number): Promise<void> {
252
- const connection = await this._getConnection()
253
- try {
254
- await this._login(connection)
255
- return await this._setHeatMode(connection, bodyType, heatMode)
256
- } finally {
257
- connection.close()
258
- }
259
- }
260
-
261
- async setHeatPoint(bodyType: number, heatPoint: number): Promise<void> {
262
- const connection = await this._getConnection()
263
- try {
264
- await this._login(connection)
265
- return await this._setHeatPoint(connection, bodyType, heatPoint)
266
- } finally {
267
- connection.close()
268
- }
269
- }
270
- }
271
-
272
- export class ControllerError extends Error {}
273
-
274
- export interface PoolCircuitJson {
275
- id: number
276
- name: string
277
- }
278
-
279
- export class PoolCircuit implements PoolCircuitJson {
280
- constructor(readonly id: number, readonly name: string) {}
281
- }
282
-
283
- export interface PoolConfigJson {
284
- circuits: PoolCircuitJson[]
285
- deviceId: string
286
- gatewayName: string
287
- hasPool: boolean
288
- hasSpa: boolean
289
- isCelsius: boolean
290
- poolMaxSetPoint: number
291
- poolMinSetPoint: number
292
- softwareVersion: string
293
- spaMaxSetPoint: number
294
- spaMinSetPoint: number
295
- }
296
-
297
- export class PoolConfig implements PoolConfigJson {
298
- circuits: PoolCircuit[] = []
299
- readonly deviceId: string
300
- readonly gatewayName: string
301
- readonly hasPool: boolean
302
- readonly hasSpa: boolean
303
- readonly isCelsius: boolean
304
- readonly poolMaxSetPoint: number
305
- readonly poolMinSetPoint: number
306
- readonly softwareVersion: string
307
- readonly spaMaxSetPoint: number
308
- readonly spaMinSetPoint: number
309
-
310
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
311
- constructor(gatewayName: string, softwareVersion: string, config: any) {
312
- this.gatewayName = gatewayName
313
- this.deviceId = gatewayName.replace('Pentair: ', '')
314
-
315
- this.softwareVersion = softwareVersion
316
- this.isCelsius = config.degC
317
- this.poolMinSetPoint = config.minSetPoint[0] ?? 0
318
- this.poolMaxSetPoint = config.maxSetPoint[0] ?? 0
319
- this.spaMinSetPoint = config.minSetPoint[1] ?? 0
320
- this.spaMaxSetPoint = config.maxSetPoint[1] ?? 0
321
- this.hasSpa = false
322
- this.hasPool = false
323
- this.circuits = []
324
- for (const circuit of config.bodyArray) {
325
- const poolCircuit = new PoolCircuit(circuit.circuitId, circuit.name)
326
- this.circuits.push(poolCircuit)
327
- if (poolCircuit.id === Controller.POOL_CIRCUIT_ID) {
328
- this.hasPool = true
329
- } else if (poolCircuit.id === Controller.SPA_CIRCUIT_ID) {
330
- this.hasSpa = true
331
- }
332
- }
333
- }
334
- }
335
-
336
- export class PoolStatus {
337
- readonly airTemperature: number
338
- readonly circuitState = new Map<number, number>()
339
- readonly hasPool: boolean
340
- readonly hasSpa: boolean
341
- readonly isPoolActive: boolean
342
- readonly isPoolHeating: boolean
343
- readonly isSpaActive: boolean
344
- readonly isSpaHeating: boolean
345
- readonly poolHeatMode: number
346
- readonly poolSetPoint: number
347
- readonly poolTemperature: number
348
- readonly spaHeatMode: number
349
- readonly spaSetPoint: number
350
- readonly spaTemperature: number
351
-
352
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
353
- constructor(status: any) {
354
- // save circuit state
355
- this.circuitState = new Map()
356
- for (const circuit of status.circuitArray) {
357
- this.circuitState.set(circuit.id, circuit.state)
358
- }
359
-
360
- this.hasPool = this.circuitState.get(Controller.POOL_CIRCUIT_ID) !== undefined
361
- this.hasSpa = this.circuitState.get(Controller.SPA_CIRCUIT_ID) !== undefined
362
-
363
- this.poolTemperature = status.currentTemp[0]
364
- this.poolSetPoint = status.setPoint[0]
365
- this.isPoolActive = this.hasPool && status.isPoolActive()
366
- this.isPoolHeating = this.hasPool && status.heatStatus[0] !== 0
367
- this.poolHeatMode = status.heatMode[0]
368
-
369
- this.spaTemperature = status.currentTemp[1]
370
- this.spaSetPoint = status.setPoint[1]
371
- this.isSpaActive = this.hasSpa && status.isSpaActive()
372
- this.isSpaHeating = this.hasSpa && status.heatStatus[1] !== 0
373
- this.spaHeatMode = status.heatMode[1]
374
-
375
- this.airTemperature = status.airTemp
376
- }
377
- }
@@ -1 +0,0 @@
1
- export * from './controller'
@@ -1,135 +0,0 @@
1
- declare module 'node-screenlogic' {
2
- declare class EventEmitter {
3
- eventNames(): string[]
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- on<T>(event: string, func: (data: T) => void)
7
-
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- once<T>(event: string, func: (data: T) => void)
10
- }
11
-
12
- declare class FindUnits extends EventEmitter {
13
- constructor()
14
-
15
- close()
16
-
17
- foundServer(msg, remote)
18
-
19
- search()
20
-
21
- sendServerBroadcast()
22
- }
23
-
24
- declare class RemoteLogin extends EventEmitter {
25
- constructor(systemName)
26
- close()
27
-
28
- connect()
29
-
30
- onClientMessage(msg)
31
-
32
- onConnected()
33
- }
34
-
35
- declare class UnitConnection extends EventEmitter {
36
- //this is an arbitrary field added in code
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- gatewayName: any
39
-
40
- constructor(server, address?, password?)
41
-
42
- addClient(clientId, senderId?)
43
-
44
- addNewScheduleEvent(scheduleType, senderId?)
45
-
46
- cancelDelay(senderId?)
47
-
48
- close()
49
-
50
- connect()
51
-
52
- deleteScheduleEventById(scheduleId, senderId?)
53
-
54
- getChemHistoryData(fromTime, toTime, senderId?)
55
-
56
- getChemicalData(senderId?)
57
-
58
- getControllerConfig(senderId?)
59
-
60
- getEquipmentConfiguration(senderId?)
61
-
62
- getHistoryData(fromTime, toTime, senderId?)
63
-
64
- getPoolStatus()
65
-
66
- getPumpStatus(pumpId, senderId?)
67
-
68
- getSaltCellConfig(senderId?)
69
-
70
- getScheduleData(scheduleType, senderId?)
71
-
72
- getSystemTime(senderId?)
73
-
74
- getVersion(senderId?)
75
-
76
- getWeatherForecast(senderId?)
77
-
78
- login()
79
-
80
- onClientMessage(msg)
81
-
82
- onConnected()
83
-
84
- pingServer(senderId?)
85
-
86
- processData(msg)
87
-
88
- removeClient(clientId, senderId?)
89
-
90
- sendLightCommand(controllerId, command, senderId?)
91
-
92
- setCircuitRuntimebyId(circuitId, runTime, senderId?)
93
-
94
- setCircuitState(controllerId, circuitId, circuitState, senderId?)
95
-
96
- setHeatMode(controllerId, bodyType, heatMode, senderId?)
97
-
98
- setPumpFlow(pumpId, circuitId, setPoint, isRPMs, senderId?)
99
-
100
- setSaltCellOutput(controllerId, poolOutput, spaOutput, senderId?)
101
-
102
- setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint, senderId?)
103
-
104
- setSetPoint(controllerId, bodyType, temperature, senderId?)
105
-
106
- setSystemTime(date, shouldAdjustForDST, senderId?)
107
- }
108
-
109
- declare const HEAT_MODE_DONTCHANGE
110
- declare const HEAT_MODE_HEATPUMP
111
- declare const HEAT_MODE_OFF
112
- declare const HEAT_MODE_SOLAR
113
- declare const HEAT_MODE_SOLARPREFERRED
114
- declare const LIGHT_CMD_COLOR_BLUE
115
- declare const LIGHT_CMD_COLOR_GREEN
116
- declare const LIGHT_CMD_COLOR_MODE_AMERICAN
117
- declare const LIGHT_CMD_COLOR_MODE_CARIBBEAN
118
- declare const LIGHT_CMD_COLOR_MODE_PARTY
119
- declare const LIGHT_CMD_COLOR_MODE_ROMANCE
120
- declare const LIGHT_CMD_COLOR_MODE_ROYAL
121
- declare const LIGHT_CMD_COLOR_MODE_SUNSET
122
- declare const LIGHT_CMD_COLOR_PURPLE
123
- declare const LIGHT_CMD_COLOR_RED
124
- declare const LIGHT_CMD_COLOR_SET
125
- declare const LIGHT_CMD_COLOR_SET_RECALL
126
- declare const LIGHT_CMD_COLOR_SET_SAVE
127
- declare const LIGHT_CMD_COLOR_SWIM
128
- declare const LIGHT_CMD_COLOR_SYNC
129
- declare const LIGHT_CMD_COLOR_WHITE
130
- declare const LIGHT_CMD_LIGHTS_OFF
131
- declare const LIGHT_CMD_LIGHTS_ON
132
- declare const PUMP_TYPE_INTELLIFLOVF
133
- declare const PUMP_TYPE_INTELLIFLOVS
134
- declare const PUMP_TYPE_INTELLIFLOVSF
135
- }