homebridge-esphome-ts 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/discovery.js CHANGED
@@ -19,7 +19,7 @@ const discoverDevices = (timeout, log) => {
19
19
  browser.stop();
20
20
  subscriber.complete();
21
21
  }, timeout);
22
- }).pipe(operators_1.map((findResult) => {
22
+ }).pipe((0, operators_1.map)((findResult) => {
23
23
  log.info('HAP Device discovered', findResult.name);
24
24
  const address = findResult.addresses.find((addr) => {
25
25
  return (ip_1.default.isV4Format(addr) && addr.substring(0, 7) !== '169.254') || ip_1.default.isV6Format(addr);
@@ -53,11 +53,11 @@ const binarySensorHelper = (component, accessory) => {
53
53
  service = accessory.addService(new ServiceConstructor(component.name, ''));
54
54
  }
55
55
  (_a = service
56
- .getCharacteristic(homekitStuff.characteristic)) === null || _a === void 0 ? void 0 : _a.on("get" /* GET */, (callback) => {
56
+ .getCharacteristic(homekitStuff.characteristic)) === null || _a === void 0 ? void 0 : _a.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
57
57
  callback(null, component.status);
58
58
  });
59
59
  component.state$
60
- .pipe(operators_1.tap(() => {
60
+ .pipe((0, operators_1.tap)(() => {
61
61
  var _a;
62
62
  (_a = service === null || service === void 0 ? void 0 : service.getCharacteristic(homekitStuff.characteristic)) === null || _a === void 0 ? void 0 : _a.setValue(component.status);
63
63
  }))
@@ -14,7 +14,7 @@ const lightHelper = (component, accessory) => {
14
14
  let lastHue;
15
15
  let lastSat;
16
16
  (_a = lightBulbService
17
- .getCharacteristic(index_1.Characteristic.Hue)) === null || _a === void 0 ? void 0 : _a.on("set" /* SET */, (hue, callback) => {
17
+ .getCharacteristic(index_1.Characteristic.Hue)) === null || _a === void 0 ? void 0 : _a.on("set" /* CharacteristicEventTypes.SET */, (hue, callback) => {
18
18
  lastHue = hue;
19
19
  const hsv = component.hsv;
20
20
  hsv.hue = lastHue !== null && lastHue !== void 0 ? lastHue : 0;
@@ -23,12 +23,12 @@ const lightHelper = (component, accessory) => {
23
23
  callback();
24
24
  });
25
25
  (_b = lightBulbService
26
- .getCharacteristic(index_1.Characteristic.Saturation)) === null || _b === void 0 ? void 0 : _b.on("set" /* SET */, (saturation, callback) => {
26
+ .getCharacteristic(index_1.Characteristic.Saturation)) === null || _b === void 0 ? void 0 : _b.on("set" /* CharacteristicEventTypes.SET */, (saturation, callback) => {
27
27
  lastSat = saturation;
28
28
  callback();
29
29
  });
30
30
  (_c = lightBulbService
31
- .getCharacteristic(index_1.Characteristic.Brightness)) === null || _c === void 0 ? void 0 : _c.on("set" /* SET */, (brightness, callback) => {
31
+ .getCharacteristic(index_1.Characteristic.Brightness)) === null || _c === void 0 ? void 0 : _c.on("set" /* CharacteristicEventTypes.SET */, (brightness, callback) => {
32
32
  const hsv = component.hsv;
33
33
  hsv.value = brightness;
34
34
  component.hsv = hsv;
@@ -37,7 +37,7 @@ const lightHelper = (component, accessory) => {
37
37
  }
38
38
  else if (component.supportsBrightness) {
39
39
  (_d = lightBulbService
40
- .getCharacteristic(index_1.Characteristic.Brightness)) === null || _d === void 0 ? void 0 : _d.on("set" /* SET */, (brightness, callback) => {
40
+ .getCharacteristic(index_1.Characteristic.Brightness)) === null || _d === void 0 ? void 0 : _d.on("set" /* CharacteristicEventTypes.SET */, (brightness, callback) => {
41
41
  if (typeof brightness === 'number') {
42
42
  component.setBrightness(brightness);
43
43
  }
@@ -45,7 +45,7 @@ const lightHelper = (component, accessory) => {
45
45
  });
46
46
  }
47
47
  (_e = lightBulbService
48
- .getCharacteristic(index_1.Characteristic.On)) === null || _e === void 0 ? void 0 : _e.on("set" /* SET */, (on, callback) => {
48
+ .getCharacteristic(index_1.Characteristic.On)) === null || _e === void 0 ? void 0 : _e.on("set" /* CharacteristicEventTypes.SET */, (on, callback) => {
49
49
  !!on ? component.turnOn() : component.turnOff();
50
50
  callback();
51
51
  });
@@ -67,7 +67,7 @@ const lightHelper = (component, accessory) => {
67
67
  if (effects.length > 0) {
68
68
  effects.forEach(({ name, service }) => {
69
69
  var _a;
70
- (_a = service === null || service === void 0 ? void 0 : service.getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.on("set" /* SET */, (on, callback) => {
70
+ (_a = service === null || service === void 0 ? void 0 : service.getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.on("set" /* CharacteristicEventTypes.SET */, (on, callback) => {
71
71
  component.effect = on ? name : esphome_ts_1.DEFAULT_NO_EFFECT;
72
72
  effects
73
73
  .filter(({ name: otherEffectName }) => otherEffectName !== name)
@@ -79,7 +79,7 @@ const lightHelper = (component, accessory) => {
79
79
  });
80
80
  }
81
81
  component.state$
82
- .pipe(operators_1.tap((state) => {
82
+ .pipe((0, operators_1.tap)((state) => {
83
83
  var _a, _b, _c, _d, _e, _f;
84
84
  (_a = lightBulbService.getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.updateValue(!!state.state);
85
85
  if (component.supportsRgb) {
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sensorHelper = void 0;
4
4
  const operators_1 = require("rxjs/operators");
5
5
  const index_1 = require("../index");
6
- const isTemperatureComponent = (unitOfMeasurement) => unitOfMeasurement === '°C' || unitOfMeasurement === '°F';
6
+ const fahrenheitUnit = 'ºF';
7
+ const isTemperatureComponent = (unitOfMeasurement) => unitOfMeasurement === '°C' || unitOfMeasurement === fahrenheitUnit;
8
+ const fahrenheitToCelsius = (fahrenheit) => ((fahrenheit - 32) * 5) / 9;
7
9
  const sensorHelper = (component, accessory) => {
8
10
  if (isTemperatureComponent(component.unitOfMeasurement)) {
9
11
  defaultSetup(component, accessory, index_1.Service.TemperatureSensor, index_1.Characteristic.CurrentTemperature);
@@ -22,7 +24,14 @@ const defaultSetup = (component, accessory, SelectedService, SelectedCharacteris
22
24
  if (!temperatureSensor) {
23
25
  temperatureSensor = accessory.addService(new SelectedService(component.name, ''));
24
26
  }
27
+ const valuesAreFahrenheit = component.unitOfMeasurement === fahrenheitUnit;
25
28
  component.state$
26
- .pipe(operators_1.tap(() => { var _a; return (_a = temperatureSensor === null || temperatureSensor === void 0 ? void 0 : temperatureSensor.getCharacteristic(SelectedCharacteristic)) === null || _a === void 0 ? void 0 : _a.setValue(component.value); }))
29
+ .pipe((0, operators_1.tap)(() => {
30
+ var _a;
31
+ const celsiusValue = valuesAreFahrenheit && component.value !== undefined
32
+ ? fahrenheitToCelsius(component.value)
33
+ : component.value;
34
+ (_a = temperatureSensor === null || temperatureSensor === void 0 ? void 0 : temperatureSensor.getCharacteristic(SelectedCharacteristic)) === null || _a === void 0 ? void 0 : _a.setValue(celsiusValue);
35
+ }))
27
36
  .subscribe();
28
37
  };
@@ -10,10 +10,10 @@ const switchHelper = (component, accessory) => {
10
10
  service = accessory.addService(new index_1.Service.Switch(component.name, ''));
11
11
  }
12
12
  component.state$
13
- .pipe(operators_1.tap(() => { var _a; return (_a = service === null || service === void 0 ? void 0 : service.getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.setValue(component.status); }))
13
+ .pipe((0, operators_1.tap)(() => { var _a; return (_a = service === null || service === void 0 ? void 0 : service.getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.setValue(component.status); }))
14
14
  .subscribe();
15
15
  (_a = service
16
- .getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.on("set" /* SET */, (value, callback) => {
16
+ .getCharacteristic(index_1.Characteristic.On)) === null || _a === void 0 ? void 0 : _a.on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
17
17
  if (component.status !== !!value) {
18
18
  !!value ? component.turnOn() : component.turnOff();
19
19
  }
package/dist/platform.js CHANGED
@@ -8,8 +8,8 @@ const index_1 = require("./index");
8
8
  const shared_1 = require("./shared");
9
9
  const esphome_ts_1 = require("esphome-ts");
10
10
  const discovery_1 = require("./discovery");
11
- const DEFAULT_RETRY_AFTER = 90 * 1000;
12
- const DEFAULT_DISCOVERY_TIMEOUT = 5 * 1000; // milliseconds
11
+ const DEFAULT_RETRY_AFTER = 90000;
12
+ const DEFAULT_DISCOVERY_TIMEOUT = 5000; // milliseconds
13
13
  class EsphomePlatform {
14
14
  constructor(log, config, api) {
15
15
  var _a;
@@ -36,10 +36,10 @@ class EsphomePlatform {
36
36
  }
37
37
  onHomebridgeDidFinishLaunching() {
38
38
  var _a, _b;
39
- let devices = rxjs_1.from((_a = this.config.devices) !== null && _a !== void 0 ? _a : []);
39
+ let devices = (0, rxjs_1.from)((_a = this.config.devices) !== null && _a !== void 0 ? _a : []);
40
40
  if (this.config.discover) {
41
41
  const excludeConfigDevices = new Set();
42
- devices = rxjs_1.concat(discovery_1.discoverDevices((_b = this.config.discoveryTimeout) !== null && _b !== void 0 ? _b : DEFAULT_DISCOVERY_TIMEOUT, this.log).pipe(operators_1.map((discoveredDevice) => {
42
+ devices = (0, rxjs_1.concat)((0, discovery_1.discoverDevices)((_b = this.config.discoveryTimeout) !== null && _b !== void 0 ? _b : DEFAULT_DISCOVERY_TIMEOUT, this.log).pipe((0, operators_1.map)((discoveredDevice) => {
43
43
  var _a, _b;
44
44
  const configDevice = (_a = this.config.devices) === null || _a === void 0 ? void 0 : _a.find(({ host }) => host === discoveredDevice.host);
45
45
  let deviceConfig = discoveredDevice;
@@ -53,22 +53,22 @@ class EsphomePlatform {
53
53
  host: (_b = discoveredDevice.address) !== null && _b !== void 0 ? _b : discoveredDevice.host });
54
54
  })),
55
55
  // Feed into output remaining devices from config that haven't been discovered
56
- devices.pipe(operators_1.filter(({ host }) => !excludeConfigDevices.has(host))));
56
+ devices.pipe((0, operators_1.filter)(({ host }) => !excludeConfigDevices.has(host))));
57
57
  }
58
58
  this.subscription.add(devices
59
- .pipe(operators_1.mergeMap((deviceConfig) => {
59
+ .pipe((0, operators_1.mergeMap)((deviceConfig) => {
60
60
  var _a, _b;
61
61
  const device = new esphome_ts_1.EspDevice(deviceConfig.host, deviceConfig.password, deviceConfig.port);
62
62
  if (this.config.debug) {
63
63
  this.log('Writing the raw data from your ESP Device to /tmp');
64
- shared_1.writeReadDataToLogFile(deviceConfig.host, device);
64
+ (0, shared_1.writeReadDataToLogFile)(deviceConfig.host, device);
65
65
  }
66
- device.provideRetryObservable(rxjs_1.interval((_b = (_a = deviceConfig.retryAfter) !== null && _a !== void 0 ? _a : this.config.retryAfter) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_AFTER).pipe(operators_1.tap(() => this.log.info(`Trying to reconnect now to device ${deviceConfig.host}`))));
67
- return device.discovery$.pipe(operators_1.filter((value) => value), operators_1.take(1), operators_1.timeout(10 * 1000), operators_1.tap(() => this.addAccessories(device)), operators_1.catchError((err) => {
66
+ device.provideRetryObservable((0, rxjs_1.interval)((_b = (_a = deviceConfig.retryAfter) !== null && _a !== void 0 ? _a : this.config.retryAfter) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_AFTER).pipe((0, operators_1.tap)(() => this.log.info(`Trying to reconnect now to device ${deviceConfig.host}`))));
67
+ return device.discovery$.pipe((0, operators_1.filter)((value) => value), (0, operators_1.take)(1), (0, operators_1.timeout)(10 * 1000), (0, operators_1.tap)(() => this.addAccessories(device)), (0, operators_1.catchError)((err) => {
68
68
  if (err.name === 'TimeoutError') {
69
69
  this.log.warn(`The device under the host ${deviceConfig.host} could not be reached.`);
70
70
  }
71
- return rxjs_1.of(err);
71
+ return (0, rxjs_1.of)(err);
72
72
  }));
73
73
  }))
74
74
  .subscribe());
@@ -9,15 +9,15 @@ const rxjs_1 = require("rxjs");
9
9
  const path_1 = require("path");
10
10
  const writeReadDataToLogFile = (host, device) => {
11
11
  const espDevice = device;
12
- if (fs_1.existsSync(path_1.join('/tmp')) && typeguards_1.isRecord(espDevice) && espDevice.socket instanceof espSocket_1.EspSocket) {
12
+ if ((0, fs_1.existsSync)((0, path_1.join)('/tmp')) && (0, typeguards_1.isRecord)(espDevice) && espDevice.socket instanceof espSocket_1.EspSocket) {
13
13
  const socket = espDevice.socket;
14
14
  const fileName = `esphome-log-${Date.now()}-${host}.json`;
15
15
  socket.espData$
16
- .pipe(operators_1.map((data) => ({
16
+ .pipe((0, operators_1.map)((data) => ({
17
17
  type: data.type,
18
18
  payload: Buffer.from(data.payload).toString('base64'),
19
19
  time: Date.now(),
20
- })), operators_1.concatMap((data) => rxjs_1.from(fs_1.promises.appendFile(path_1.join('/tmp', fileName), `${JSON.stringify(data)}\n`))))
20
+ })), (0, operators_1.concatMap)((data) => (0, rxjs_1.from)(fs_1.promises.appendFile((0, path_1.join)('/tmp', fileName), `${JSON.stringify(data)}\n`))))
21
21
  .subscribe();
22
22
  }
23
23
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-esphome-ts",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "New plugin for integrating for esphome into homebridge",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,26 +32,26 @@
32
32
  "homebridge": ">=0.4.0"
33
33
  },
34
34
  "dependencies": {
35
- "bonjour-hap": "3.6.2",
35
+ "bonjour-hap": "3.6.3",
36
36
  "color-convert": "2.0.1",
37
- "esphome-ts": "3.3.0",
38
- "rxjs": "7.1.0"
37
+ "esphome-ts": "3.3.1",
38
+ "rxjs": "7.8.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/color-convert": "2.0.0",
42
42
  "@types/ip": "1.1.0",
43
- "@types/node": "14.14.37",
44
- "@typescript-eslint/eslint-plugin": "4.22.1",
45
- "@typescript-eslint/parser": "4.22.0",
46
- "eslint": "7.25.0",
43
+ "@types/node": "18.7.13",
44
+ "@typescript-eslint/eslint-plugin": "5.34.0",
45
+ "@typescript-eslint/parser": "5.34.0",
46
+ "eslint": "8.22.0",
47
47
  "eslint-config-google": "0.14.0",
48
- "eslint-config-prettier": "8.3.0",
49
- "eslint-plugin-import": "2.22.1",
50
- "eslint-plugin-prettier": "3.4.0",
51
- "hap-nodejs": "0.9.4",
52
- "homebridge": "1.3.4",
53
- "prettier": "2.2.1",
54
- "prettier-eslint": "12.0.0",
55
- "typescript": "4.3.2"
48
+ "eslint-config-prettier": "8.5.0",
49
+ "eslint-plugin-import": "2.26.0",
50
+ "eslint-plugin-prettier": "4.2.1",
51
+ "hap-nodejs": "0.10.2",
52
+ "homebridge": "1.5.0",
53
+ "prettier": "2.7.1",
54
+ "prettier-eslint": "15.0.1",
55
+ "typescript": "4.7.4"
56
56
  }
57
57
  }