homebridge-tydom 0.23.6 → 0.23.7

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/README.md CHANGED
@@ -81,6 +81,8 @@
81
81
 
82
82
  Your username is the MAC Address of your local Tydom hardware, it should be `001A25` + your 6-character home ID that you can find in the mobile app.
83
83
 
84
+ The password for newer Tydom setups can be auto-generated by the mobile application and hard to get. Only solution for now is to use some SSL Proxying application on your mobile to inspect the requests. You can follow the [following guide](https://github.com/mgcrea/homebridge-tydom/issues/72#issuecomment-1315036089) from @aure-olivier to get it.
85
+
84
86
  For your password, you can also use an environment variable `HOMEBRIDGE_TYDOM_PASSWORD` with the base64 encoded value of your password.
85
87
 
86
88
  > Example: `HOMEBRIDGE_TYDOM_PASSWORD=Zm9vYmFyYmF6` for a `foobarbaz` password (`echo -n "foobarbaz" | base64`)
@@ -211,7 +213,8 @@ You can override categories of devices (eg. some light switch used to manage a f
211
213
  }
212
214
  ```
213
215
 
214
- > `3` being the `Categories.FAN` number.
216
+ > `3` being the `Fan` number.
217
+ > `8` being the `Switch` number.
215
218
 
216
219
  ### Supported hardware
217
220
 
@@ -1,6 +1,6 @@
1
- import type { PlatformAccessory } from 'homebridge';
1
+ import { PlatformAccessory } from 'homebridge';
2
2
  import TydomController from '../controller';
3
- import { TydomAccessoryContext } from '../typings/tydom';
3
+ import { TydomAccessoryContext } from '../typings';
4
4
  type LightbulbSettings = Record<string, never>;
5
5
  type LightbulbState = {
6
6
  latestBrightness: number;
@@ -1,20 +1,23 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.updateLightbulb = exports.setupLightbulb = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
4
8
  const lodash_1 = require("lodash");
5
- const accessory_1 = require("../helpers/accessory");
6
- const chalk_1 = require("../utils/chalk");
7
- const debug_1 = require("../utils/debug");
8
- const hap_1 = require("../config/hap");
9
+ const helpers_1 = require("../helpers");
9
10
  const tydom_1 = require("../helpers/tydom");
11
+ const utils_1 = require("../utils");
10
12
  const switchableService_1 = require("./services/switchableService");
13
+ const hap_1 = require("../config/hap");
11
14
  const setupLightbulb = (accessory, controller) => {
12
15
  const { context } = accessory;
13
16
  const { client } = controller;
14
17
  const { On, Brightness } = hap_1.Characteristic;
15
18
  const { deviceId, endpointId, metadata, state } = context;
16
- (0, accessory_1.setupAccessoryInformationService)(accessory, controller);
17
- (0, accessory_1.setupAccessoryIdentifyHandler)(accessory, controller);
19
+ (0, helpers_1.setupAccessoryInformationService)(accessory, controller);
20
+ (0, helpers_1.setupAccessoryIdentifyHandler)(accessory, controller);
18
21
  Object.assign(state, {
19
22
  latestBrightness: 100,
20
23
  pendingUpdatedValues: [],
@@ -27,9 +30,9 @@ const setupLightbulb = (accessory, controller) => {
27
30
  return;
28
31
  }
29
32
  // Dimmable
30
- const service = (0, accessory_1.addAccessoryService)(accessory, hap_1.Service.Lightbulb, `${accessory.displayName}`, true);
33
+ const service = (0, helpers_1.addAccessoryService)(accessory, hap_1.Service.Lightbulb, `${accessory.displayName}`, true);
31
34
  const debouncedSetLevel = (0, lodash_1.debounce)(async (value) => {
32
- (0, debug_1.debugTydomPut)('level', accessory, value);
35
+ (0, utils_1.debugTydomPut)('level', accessory, value);
33
36
  await client.put(`/devices/${deviceId}/endpoints/${endpointId}/data`, [
34
37
  {
35
38
  name: 'level',
@@ -43,12 +46,12 @@ const setupLightbulb = (accessory, controller) => {
43
46
  service
44
47
  .getCharacteristic(hap_1.Characteristic.On)
45
48
  .on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
46
- (0, debug_1.debugGet)(On, service);
49
+ (0, utils_1.debugGet)(On, service);
47
50
  try {
48
51
  const data = (await (0, tydom_1.getTydomDeviceData)(client, { deviceId, endpointId }));
49
52
  const level = (0, tydom_1.getTydomDataPropValue)(data, 'level');
50
53
  const nextValue = level > 0;
51
- (0, debug_1.debugGetResult)(On, service, nextValue);
54
+ (0, utils_1.debugGetResult)(On, service, nextValue);
52
55
  callback(null, nextValue);
53
56
  }
54
57
  catch (err) {
@@ -56,12 +59,12 @@ const setupLightbulb = (accessory, controller) => {
56
59
  }
57
60
  })
58
61
  .on("set" /* CharacteristicEventTypes.SET */, async (value, callback) => {
59
- (0, debug_1.debugSet)(On, service, value);
62
+ (0, utils_1.debugSet)(On, service, value);
60
63
  try {
61
64
  const nextLevel = value ? state.latestBrightness || 100 : 0;
62
65
  await debouncedSetLevel(nextLevel);
63
66
  service.updateCharacteristic(Brightness, nextLevel);
64
- (0, debug_1.debugSetResult)(On, service, value);
67
+ (0, utils_1.debugSetResult)(On, service, value);
65
68
  callback();
66
69
  }
67
70
  catch (err) {
@@ -72,11 +75,11 @@ const setupLightbulb = (accessory, controller) => {
72
75
  service
73
76
  .getCharacteristic(hap_1.Characteristic.Brightness)
74
77
  .on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
75
- (0, debug_1.debugGet)(Brightness, service);
78
+ (0, utils_1.debugGet)(Brightness, service);
76
79
  try {
77
80
  const data = await (0, tydom_1.getTydomDeviceData)(client, { deviceId, endpointId });
78
81
  const level = (0, tydom_1.getTydomDataPropValue)(data, 'level');
79
- (0, debug_1.debugGetResult)(Brightness, service, level);
82
+ (0, utils_1.debugGetResult)(Brightness, service, level);
80
83
  callback(null, level);
81
84
  }
82
85
  catch (err) {
@@ -84,7 +87,7 @@ const setupLightbulb = (accessory, controller) => {
84
87
  }
85
88
  })
86
89
  .on("set" /* CharacteristicEventTypes.SET */, async (value, callback) => {
87
- (0, debug_1.debugSet)(Brightness, service, value);
90
+ (0, utils_1.debugSet)(Brightness, service, value);
88
91
  try {
89
92
  const nextValue = value;
90
93
  Object.assign(state, {
@@ -92,7 +95,7 @@ const setupLightbulb = (accessory, controller) => {
92
95
  lastUpdatedAt: Date.now()
93
96
  });
94
97
  await debouncedSetLevel(nextValue);
95
- (0, debug_1.debugSetResult)(Brightness, service, value);
98
+ (0, utils_1.debugSetResult)(Brightness, service, value);
96
99
  callback();
97
100
  }
98
101
  catch (err) {
@@ -117,24 +120,24 @@ const updateLightbulb = (accessory, controller, updates) => {
117
120
  const { name, value } = update;
118
121
  switch (name) {
119
122
  case 'level': {
120
- const service = (0, accessory_1.getAccessoryService)(accessory, hap_1.Service.Lightbulb);
123
+ const service = (0, helpers_1.getAccessoryService)(accessory, hap_1.Service.Lightbulb);
121
124
  const level = value;
122
125
  if (level === null) {
123
- (0, debug_1.debug)(`Encountered a ${(0, chalk_1.chalkString)('level')} update with a null value!`);
126
+ (0, debug_1.default)(`Encountered a ${(0, utils_1.chalkString)('level')} update with a null value!`);
124
127
  return;
125
128
  }
126
129
  // @NOTE ignore pending updates
127
130
  if (state.pendingUpdatedValues.includes(level)) {
128
- (0, debug_1.debug)(`Ignoring a delayed ${(0, chalk_1.chalkString)('level')} update with value=${(0, chalk_1.chalkNumber)(level)}`);
131
+ (0, debug_1.default)(`Ignoring a delayed ${(0, utils_1.chalkString)('level')} update with value=${(0, utils_1.chalkNumber)(level)}`);
129
132
  // Reset pending updates stack
130
133
  state.pendingUpdatedValues = [];
131
134
  return;
132
135
  }
133
- (0, debug_1.debugSetUpdate)(On, service, level > 0);
136
+ (0, utils_1.debugSetUpdate)(On, service, level > 0);
134
137
  service.updateCharacteristic(On, level > 0);
135
138
  // @NOTE Only update brightness for non-null values
136
139
  if (level > 0) {
137
- (0, debug_1.debugSetUpdate)(Brightness, service, level);
140
+ (0, utils_1.debugSetUpdate)(Brightness, service, level);
138
141
  service.updateCharacteristic(Brightness, level);
139
142
  }
140
143
  return;
@@ -1,5 +1,5 @@
1
- import type { PlatformAccessory } from 'homebridge';
1
+ import { PlatformAccessory } from 'homebridge';
2
2
  import { TydomAccessoryContext } from '../typings';
3
3
  import TydomController from '../controller';
4
4
  export declare const setupOutlet: (accessory: PlatformAccessory<TydomAccessoryContext>, controller: TydomController) => void;
5
- export declare const updateOutlet: (accessory: PlatformAccessory<TydomAccessoryContext>, controller: TydomController, updates: Record<string, unknown>[]) => void;
5
+ export declare const updateOutlet: (accessory: PlatformAccessory<TydomAccessoryContext>, _controller: TydomController, updates: Record<string, unknown>[]) => void;
@@ -1,17 +1,92 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateOutlet = exports.setupOutlet = void 0;
4
+ const definitions_1 = require("hap-nodejs/dist/lib/definitions");
5
+ const lodash_1 = require("lodash");
6
+ const tydom_1 = require("../helpers/tydom");
7
+ const utils_1 = require("../utils");
4
8
  const hap_1 = require("../config/hap");
5
9
  const accessory_1 = require("../helpers/accessory");
6
- const switchableService_1 = require("./services/switchableService");
7
10
  const setupOutlet = (accessory, controller) => {
11
+ const { context } = accessory;
12
+ const { client } = controller;
13
+ const { On } = hap_1.Characteristic;
14
+ const { deviceId, endpointId } = context;
8
15
  (0, accessory_1.setupAccessoryInformationService)(accessory, controller);
9
16
  (0, accessory_1.setupAccessoryIdentifyHandler)(accessory, controller);
10
17
  // Add the actual accessory Service
11
- (0, switchableService_1.addAccessorySwitchableService)(accessory, controller, hap_1.Service.Outlet);
18
+ const service = (0, accessory_1.addAccessoryService)(accessory, hap_1.Service.Outlet, `${accessory.displayName}`, true);
19
+ service
20
+ .getCharacteristic(On)
21
+ .on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
22
+ (0, utils_1.debugGet)(On, service);
23
+ try {
24
+ const data = await (0, tydom_1.getTydomDeviceData)(client, { deviceId, endpointId });
25
+ const plugCmd = (0, tydom_1.getTydomDataPropValue)(data, 'plugCmd');
26
+ const nextValue = plugCmd === 'ON';
27
+ (0, utils_1.debugGetResult)(On, service, nextValue);
28
+ callback(null, nextValue);
29
+ }
30
+ catch (err) {
31
+ callback(err);
32
+ }
33
+ })
34
+ .on("set" /* CharacteristicEventTypes.SET */, async (value, callback) => {
35
+ (0, utils_1.debugSet)(On, service, value);
36
+ try {
37
+ const tydomValue = value ? 'ON' : 'OFF';
38
+ await client.put(`/devices/${deviceId}/endpoints/${endpointId}/data`, [
39
+ {
40
+ name: 'plugCmd',
41
+ value: tydomValue
42
+ }
43
+ ]);
44
+ (0, utils_1.debugSetResult)(On, service, value, tydomValue);
45
+ callback();
46
+ }
47
+ catch (err) {
48
+ callback(err);
49
+ }
50
+ });
51
+ service
52
+ .getCharacteristic(definitions_1.OutletInUse)
53
+ .on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
54
+ (0, utils_1.debugGet)(definitions_1.OutletInUse, service);
55
+ try {
56
+ const data = await (0, tydom_1.getTydomDeviceData)(client, { deviceId, endpointId });
57
+ const energyInstantTotElecP = (0, tydom_1.getTydomDataPropValue)(data, 'energyInstantTotElecP');
58
+ const nextValue = energyInstantTotElecP > 0;
59
+ (0, utils_1.debugGetResult)(definitions_1.OutletInUse, service, nextValue);
60
+ callback(null, nextValue);
61
+ }
62
+ catch (err) {
63
+ callback(err);
64
+ }
65
+ });
12
66
  };
13
67
  exports.setupOutlet = setupOutlet;
14
- const updateOutlet = (accessory, controller, updates) => {
15
- (0, switchableService_1.updateAccessorySwitchableService)(accessory, controller, updates, hap_1.Service.Outlet);
68
+ const updateOutlet = (accessory, _controller, updates) => {
69
+ updates.forEach((update) => {
70
+ const { name, value } = update;
71
+ const { On } = hap_1.Characteristic;
72
+ switch (name) {
73
+ case 'level': {
74
+ const service = (0, accessory_1.getAccessoryService)(accessory, hap_1.Service.Outlet);
75
+ const nextValue = value === 'ON';
76
+ (0, utils_1.debugSetUpdate)(On, service, nextValue);
77
+ service.updateCharacteristic(On, nextValue);
78
+ return;
79
+ }
80
+ case 'energyInstantTotElecP': {
81
+ const service = (0, accessory_1.getAccessoryService)(accessory, hap_1.Service.Outlet);
82
+ const nextValue = (0, lodash_1.toNumber)(value) > 0;
83
+ (0, utils_1.debugSetUpdate)(definitions_1.OutletInUse, service, nextValue);
84
+ service.updateCharacteristic(definitions_1.OutletInUse, nextValue);
85
+ return;
86
+ }
87
+ default:
88
+ return;
89
+ }
90
+ });
16
91
  };
17
92
  exports.updateOutlet = updateOutlet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-tydom",
3
- "version": "0.23.6",
3
+ "version": "0.23.7",
4
4
  "description": "Homebridge plugin to manage Tydom devices by Delta Dore",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",