Skip to content

Commit 533b630

Browse files
committed
Update dependencies and bump version
1 parent a081a1f commit 533b630

10 files changed

Lines changed: 398 additions & 504 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ The package contains three different tools:
99
2. vedo - a CLI to interact with Comelit Vedo Alarm
1010
3. comelit-sb - a CLI to interact with comelit Serial Bridge (https://pro.comelitgroup.com/product/20003101)
1111

12+
## Installation
13+
14+
To install this tool use the command:
15+
16+
`npm install -g comelit-client@latest`
17+
1218
## Comelit CLI
1319

1420
## Vedo Alarm CLI

package.json

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "comelit-client",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"author": "Pierpaolo Follia",
55
"repository": {
66
"type": "git",
@@ -33,39 +33,38 @@
3333
"clean": "rimraf dist/"
3434
},
3535
"dependencies": {
36-
"@sentry/node": "5.12.2",
37-
"async-mqtt": "^2.4.2",
38-
"axios": "^0.19.2",
39-
"chalk": "^3.0.0",
40-
"lodash": "^4.17.15",
41-
"mqtt": "^3.0.0",
42-
"mqtt-packet": "^6.3.0",
43-
"querystring": "^0.2.0",
44-
"typescript": "^3.7.4",
45-
"yargs": "^15.1.0"
36+
"async-mqtt": "2.6.1",
37+
"axios": "0.19.2",
38+
"chalk": "3.0.0",
39+
"lodash": "4.17.19",
40+
"mqtt": "4.1.0",
41+
"mqtt-packet": "6.3.2",
42+
"querystring": "0.2.0",
43+
"typescript": "3.9.7",
44+
"yargs": "15.4.1"
4645
},
4746
"bin": {
4847
"comelit": "./dist/bin/comelit-cli.js",
4948
"comelit-sb": "./dist/bin/comelit-sb-cli.js",
5049
"vedo": "./dist/bin/vedo-cli.js"
5150
},
5251
"devDependencies": {
53-
"@types/chalk": "^2.2.0",
54-
"@types/lodash": "^4.14.149",
55-
"@types/mqtt": "^2.5.0",
56-
"@types/node": "^11.15.3",
57-
"@types/yargs": "^15.0.0",
58-
"@types/jest": "^25.1.4",
59-
"@types/nock": "^11.1.0",
60-
"@typescript-eslint/eslint-plugin": "^2.14.0",
61-
"@typescript-eslint/parser": "^2.14.0",
62-
"@types/axios": "^0.14.0",
63-
"eslint": "^6.4.0",
64-
"eslint-config-prettier": "^6.10.0",
65-
"prettier": "^1.19.1",
66-
"rimraf": "^3.0.2",
67-
"jest": "^25.1.0",
68-
"ts-jest": "^25.2.1",
69-
"nock": "^12.0.2"
52+
"@types/chalk": "2.2.0",
53+
"@types/lodash": "4.14.157",
54+
"@types/mqtt": "2.5.0",
55+
"@types/node": "12.12.6",
56+
"@types/yargs": "15.0.5",
57+
"@types/jest": "25.1.4",
58+
"@types/nock": "11.1.0",
59+
"@typescript-eslint/eslint-plugin": "2.14.0",
60+
"@typescript-eslint/parser": "2.14.0",
61+
"@types/axios": "0.14.0",
62+
"eslint": "7.5.0",
63+
"eslint-config-prettier": "6.11.0",
64+
"prettier": "2.0.5",
65+
"rimraf": "3.0.2",
66+
"jest": "25.1.0",
67+
"ts-jest": "25.2.1",
68+
"nock": "12.0.2"
7069
}
7170
}

src/bin/vedo-cli.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ let client: VedoClient = null;
4747

4848
async function run() {
4949
const command = options._[0];
50-
console.log(
51-
chalk.green(`Executing command ${command} - ${JSON.stringify(options)}`)
52-
);
50+
console.log(chalk.green(`Executing command ${command} - ${JSON.stringify(options)}`));
5351
client = new VedoClient(options.host, options.port || 80);
5452
let uid = null;
5553
try {

src/comelit-client.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DeferredMessage, PromiseBasedQueue } from './promise-queue';
33
import { generateUUID } from './utils';
44
import dgram, { RemoteInfo } from 'dgram';
55
import { AddressInfo } from 'net';
6-
import {ConsoleLike, DeviceData, HomeIndex} from './types';
6+
import { ConsoleLike, DeviceData, HomeIndex } from './types';
77
import Timeout = NodeJS.Timeout;
88

99
export const ROOT_ID = 'GEN#17#13#1';
@@ -145,16 +145,16 @@ function bytesToHex(byteArray: Buffer): String {
145145
const DEFAULT_TIMEOUT = 5000;
146146

147147
export interface ClientConfig {
148-
host: string,
149-
port?: number,
150-
username?: string,
151-
password?: string,
148+
host: string;
149+
port?: number;
150+
username?: string;
151+
password?: string;
152152
}
153153

154154
export interface HUBClientConfig extends ClientConfig {
155-
hub_username?: string,
156-
hub_password?: string,
157-
clientId?: string
155+
hub_username?: string;
156+
hub_password?: string;
157+
clientId?: string;
158158
}
159159

160160
export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMessage> {
@@ -165,13 +165,14 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
165165
private txTopic: string;
166166
private rxTopic: string;
167167
private clientId: string;
168-
private readonly onUpdate: (objId: string, data: Readonly<DeviceData>, oldData?: Readonly<DeviceData>) => void;
168+
private readonly onUpdate: (
169+
objId: string,
170+
data: Readonly<DeviceData>,
171+
oldData?: Readonly<DeviceData>
172+
) => void;
169173
private readonly logger: ConsoleLike;
170174

171-
constructor(
172-
onUpdate?: (objId: string, device: DeviceData) => void,
173-
log?: ConsoleLike
174-
) {
175+
constructor(onUpdate?: (objId: string, device: DeviceData) => void, log?: ConsoleLike) {
175176
super();
176177
this.props = {
177178
client: null,
@@ -187,7 +188,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
187188
): boolean {
188189
const deferredMqttMessage = response.seq_id
189190
? messages.find(
190-
message =>
191+
(message) =>
191192
message.message.seq_id == response.seq_id &&
192193
message.message.req_type == response.req_type
193194
)
@@ -219,7 +220,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
219220
}
220221

221222
scan(): Promise<void> {
222-
return new Promise(resolve => {
223+
return new Promise((resolve) => {
223224
const server = dgram.createSocket('udp4');
224225
let timeout: Timeout;
225226
function sendScan() {
@@ -246,7 +247,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
246247
this.logger.info(`server listening ${address.address}:${address.port}`);
247248
});
248249

249-
server.on('error', err => {
250+
server.on('error', (err) => {
250251
this.logger.info(`server error:\n${err.stack}`);
251252
clearInterval(timeout);
252253
server.close();
@@ -416,7 +417,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
416417
obj_id: id,
417418
};
418419
const response = await this.publish(packet);
419-
return ComelitClient.evalResponse(response).then(value => value);
420+
return ComelitClient.evalResponse(response).then((value) => value);
420421
}
421422

422423
async ping(): Promise<boolean> {
@@ -427,7 +428,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
427428
sessiontoken: this.props.sessiontoken,
428429
};
429430
const response = await this.publish(packet);
430-
return ComelitClient.evalResponse(response).then(value => value);
431+
return ComelitClient.evalResponse(response).then((value) => value);
431432
}
432433

433434
async device(objId: string = ROOT_ID, detailLevel?: number): Promise<DeviceData> {
@@ -505,7 +506,7 @@ export class ComelitClient extends PromiseBasedQueue<MqttMessage, MqttIncomingMe
505506
act_params: [value],
506507
};
507508
const response = await this.publish(packet);
508-
return ComelitClient.evalResponse(response).then(value => value);
509+
return ComelitClient.evalResponse(response).then((value) => value);
509510
}
510511

511512
private static evalResponse(response: MqttIncomingMessage): Promise<boolean> {

src/comelit-sb-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
STATUS_ON,
1212
ThermostatDeviceData,
1313
} from './types';
14-
import {ClimaMode, ClimaOnOff, ROOT_ID, ThermoSeason} from './comelit-client';
14+
import { ClimaMode, ClimaOnOff, ROOT_ID, ThermoSeason } from './comelit-client';
1515

1616
export interface BridgeLoginInfo {
1717
domus: string;
@@ -254,7 +254,7 @@ export class ComelitSbClient {
254254
type: OBJECT_TYPE.ZONE,
255255
sub_type: OBJECT_SUBTYPE.GENERIC_ZONE,
256256
descrizione: 'root',
257-
elements: [...rooms.values()].map(dd => ({ id: dd.id, data: dd })),
257+
elements: [...rooms.values()].map((dd) => ({ id: dd.id, data: dd })),
258258
});
259259
}
260260

src/promise-queue.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ export abstract class PromiseBasedQueue<M, R> implements Queue<M, R> {
2828
this.queuedMessages = [];
2929
}
3030

31-
abstract processResponse(
32-
messages: DeferredMessage<M, R>[],
33-
response: R
34-
): boolean;
31+
abstract processResponse(messages: DeferredMessage<M, R>[], response: R): boolean;
3532

3633
setTimeout(timeout: number) {
3734
if (timeout && timeout > 0) {
@@ -43,44 +40,33 @@ export abstract class PromiseBasedQueue<M, R> implements Queue<M, R> {
4340

4441
cleanPending(timeout: number) {
4542
const timestamp = new Date().getTime();
46-
const toKeep = this.queuedMessages.reduce(
47-
(keep: DeferredMessage<M, R>[], value) => {
48-
const delta = timestamp - value.timestamp;
49-
if (delta > timeout) {
50-
console.error(
51-
`Rejecting unresolved promise after ${delta}ms (${JSON.stringify(
52-
value.message
53-
)})`
54-
);
55-
value.promise.reject(
56-
new Error(`Timeout for message: ${JSON.stringify(value.message)}`)
57-
);
58-
return keep;
59-
}
60-
keep.push(value);
43+
const toKeep = this.queuedMessages.reduce((keep: DeferredMessage<M, R>[], value) => {
44+
const delta = timestamp - value.timestamp;
45+
if (delta > timeout) {
46+
console.error(
47+
`Rejecting unresolved promise after ${delta}ms (${JSON.stringify(value.message)})`
48+
);
49+
value.promise.reject(new Error(`Timeout for message: ${JSON.stringify(value.message)}`));
6150
return keep;
62-
},
63-
[]
64-
);
51+
}
52+
keep.push(value);
53+
return keep;
54+
}, []);
6555
this.flush();
6656
this.queuedMessages.push(...toKeep);
6757
this.timeout.refresh();
6858
}
6959

7060
flush(shutdown?: boolean): void {
7161
if (shutdown) {
72-
this.queuedMessages.forEach(value =>
73-
value.promise.reject(new Error('Shutting down'))
74-
);
62+
this.queuedMessages.forEach((value) => value.promise.reject(new Error('Shutting down')));
7563
}
7664
this.queuedMessages.length = 0;
7765
}
7866

7967
processQueue(response: R) {
8068
if (this.processResponse(this.queuedMessages, response)) {
81-
console.log(
82-
`Message processed. Message queue size is now ${this.queuedMessages.length}`
83-
);
69+
console.log(`Message processed. Message queue size is now ${this.queuedMessages.length}`);
8470
}
8571
}
8672

src/types.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ClimaMode, ThermoSeason} from './comelit-client';
1+
import { ClimaMode, ThermoSeason } from './comelit-client';
22

33
export interface DomoticData {
44
id: string;
@@ -139,7 +139,7 @@ export enum OBJECT_TYPE {
139139
THERMOSTAT = 9,
140140
OUTLET = 10,
141141
POWER_SUPPLIER = 11,
142-
ZONE = 1001
142+
ZONE = 1001,
143143
}
144144

145145
export enum OBJECT_SUBTYPE {
@@ -153,27 +153,28 @@ export enum OBJECT_SUBTYPE {
153153
GENERIC_ZONE = 13,
154154
CONSUMPTION = 15,
155155
CLIMA_THERMOSTAT_DEHUMIDIFIER = 16,
156-
CLIMA_DEHUMIDIFIER = 17
156+
CLIMA_DEHUMIDIFIER = 17,
157157
}
158158

159159
export const ON = 1;
160160
export const OFF = 0;
161161
export const IDLE = 2;
162-
export const STATUS_ON = "1";
163-
export const STATUS_OFF = "0";
162+
export const STATUS_ON = '1';
163+
export const STATUS_OFF = '0';
164164

165165
export class HomeIndex {
166-
public readonly lightsIndex: DeviceIndex<LightDeviceData> = new Map<string,
167-
LightDeviceData>();
166+
public readonly lightsIndex: DeviceIndex<LightDeviceData> = new Map<string, LightDeviceData>();
168167
public readonly roomsIndex: DeviceIndex = new Map() as DeviceIndex;
169-
public readonly thermostatsIndex: DeviceIndex<ThermostatDeviceData> = new Map<string,
170-
ThermostatDeviceData>();
171-
public readonly blindsIndex: DeviceIndex<BlindDeviceData> = new Map<string,
172-
BlindDeviceData>();
173-
public readonly outletsIndex: DeviceIndex<OutletDeviceData> = new Map<string,
174-
OutletDeviceData>();
175-
public readonly supplierIndex: DeviceIndex<SupplierDeviceData> = new Map<string,
176-
SupplierDeviceData>();
168+
public readonly thermostatsIndex: DeviceIndex<ThermostatDeviceData> = new Map<
169+
string,
170+
ThermostatDeviceData
171+
>();
172+
public readonly blindsIndex: DeviceIndex<BlindDeviceData> = new Map<string, BlindDeviceData>();
173+
public readonly outletsIndex: DeviceIndex<OutletDeviceData> = new Map<string, OutletDeviceData>();
174+
public readonly supplierIndex: DeviceIndex<SupplierDeviceData> = new Map<
175+
string,
176+
SupplierDeviceData
177+
>();
177178

178179
public readonly mainIndex: DeviceIndex = new Map<string, Readonly<DeviceData>>();
179180

@@ -190,7 +191,7 @@ export class HomeIndex {
190191
updateObject(id: string, data: Readonly<DeviceData>): DeviceData {
191192
if (this.mainIndex.has(id)) {
192193
const deviceData = this.mainIndex.get(id);
193-
const value = {...deviceData, ...data};
194+
const value = { ...deviceData, ...data };
194195
this.mainIndex.set(id, Object.freeze(value));
195196
return value;
196197
}
@@ -206,10 +207,7 @@ export class HomeIndex {
206207
this.roomsIndex.set(element.id, element.data);
207208
break;
208209
case OBJECT_TYPE.THERMOSTAT:
209-
this.thermostatsIndex.set(
210-
element.id,
211-
element.data as ThermostatDeviceData
212-
);
210+
this.thermostatsIndex.set(element.id, element.data as ThermostatDeviceData);
213211
break;
214212
case OBJECT_TYPE.BLIND:
215213
this.blindsIndex.set(element.id, element.data as BlindDeviceData);
@@ -228,7 +226,7 @@ export class HomeIndex {
228226
this.mainIndex.set(element.id, element.data);
229227

230228
if (element.data.elements) {
231-
element.data.elements.forEach(value => this.visitElement(value));
229+
element.data.elements.forEach((value) => this.visitElement(value));
232230
}
233231
}
234232
}

0 commit comments

Comments
 (0)