@petro-kushchak/homebridge-tuya-eve 1.0.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.
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 80
6
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Alexandru Dragoescu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ <span align="center">
2
+
3
+ <a href="https://github.com/Alperen-Ozturk/homebridge-tuya-switch/blob/master/assets/homebridge-tuya-switch.artwork.png?raw=true"><img alt="homebridge-verified" src="https://github.com/Alperen-Ozturk/homebridge-tuya-switch/blob/master/assets/homebridge-tuya-switch.artwork.png?raw=true" width="600px"></a>
4
+
5
+ # Homebridge-Tuya-Switch
6
+
7
+ <a href="https://www.npmjs.com/package/homebridge-tuya-switch"><img title="npm version" src="https://badgen.net/npm/v/homebridge-tuya-switch" ></a>
8
+
9
+ </span>
10
+
11
+
12
+ homebridge-tuya-switch is a homebridge plugin that lets you control your Tuya based switch devices with HomeKit.
13
+
14
+
15
+ ## Installation
16
+ To use this plugin, follow the steps below:
17
+
18
+ 1) Install [Homebridge](https://github.com/homebridge/homebridge), if you haven't already.
19
+
20
+ 2) Install this plugin. You may need to prefix this command with ```sudo``` if you run into any issues.
21
+
22
+ ```npm i -g homebridge-tuya-eve```
23
+
24
+ 3) Add your device's parameters to your ```config.json``` file, then reload Homebridge.
25
+
26
+ You can check out the [configuration example](https://github.com/Alperen-Ozturk/homebridge-tuya-switch/blob/master/config-example.MD) for parameters you should set.
27
+
28
+ **To get ID and Key** Watch [this](https://www.youtube.com/watch?v=oq0JL_wicKg) video.
29
+
30
+
31
+ ## Issues
32
+
33
+ If you spot any errors with the plugin, or have a question, feel free to open an issue.
34
+
35
+
36
+ ## Contribution guide
37
+
38
+ Any help is welcome!
39
+
40
+ If you would like to make refinments to this plugin, add new device support, or anything else feel free to make a fork, and submit a PR detailing the changes you made, and why.
41
+
42
+ ## Note
43
+
44
+ This repository is created because there is no support for switch type accessories on iRayanKhan's homebridge-tuya repository. Once he merges my commits or adds support for switch type accessories himself, you should go and use his plugin. This plugin supports ONLY switch type accessories.
@@ -0,0 +1,46 @@
1
+ {
2
+ "pluginAlias": "TuyaSwitchEve",
3
+ "pluginType": "accessory",
4
+ "singular": true,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "required": true,
12
+ "default": "Main Switch"
13
+ },
14
+ "model": {
15
+ "title": "Model",
16
+ "type": "string",
17
+ "required": false,
18
+ "default": "123456"
19
+ },
20
+ "serial": {
21
+ "title": "Serial",
22
+ "type": "string",
23
+ "required": false,
24
+ "default": "aa-00-00-01"
25
+ },
26
+ "updateInterval": {
27
+ "title": "Update Interval",
28
+ "type": "number",
29
+ "required": false,
30
+ "default": "5000"
31
+ },
32
+ "id": {
33
+ "title": "Tuya Device Id",
34
+ "type": "string",
35
+ "required": true,
36
+ "default": "00000000000000000000"
37
+ },
38
+ "key": {
39
+ "title": "Tuya Device Id",
40
+ "type": "string",
41
+ "required": true,
42
+ "default": "00000000000000000000"
43
+ }
44
+ }
45
+ }
46
+ }
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ const eveHistoryService_1 = require("./lib/eveHistoryService");
3
+ let hap;
4
+ /**
5
+ * Platform Accessory
6
+ * An instance of this class is created for each accessory your platform registers
7
+ * Each accessory may expose multiple services of different service types.
8
+ */
9
+ class TuyaSwitchAccessoryAccessory {
10
+ constructor(logger, config, api) {
11
+ this.logger = logger;
12
+ this.config = config;
13
+ this.api = api;
14
+ hap = api.hap;
15
+ this.log = logger;
16
+ this.name = config.name;
17
+ this.displayName = this.name;
18
+ this.serial = config.serial;
19
+ this.id = config.id;
20
+ this.key = config.key;
21
+ this.model = config.model || 'TuyaSwitch';
22
+ this.updateInterval = config.updateInterval || 5000;
23
+ // Set AccessoryInformation
24
+ this.informationService = new hap.Service.AccessoryInformation()
25
+ .setCharacteristic(hap.Characteristic.Name, this.name)
26
+ .setCharacteristic(hap.Characteristic.Manufacturer, 'Tuya')
27
+ .setCharacteristic(hap.Characteristic.Model, this.model)
28
+ .setCharacteristic(hap.Characteristic.SerialNumber, this.serial);
29
+ // create a new Thermostat service
30
+ this.service = new hap.Service.Switch(this.name);
31
+ this.service
32
+ .getCharacteristic(hap.Characteristic.On)
33
+ .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
34
+ this.log.info(`[${this.name} Switch] GET ON`);
35
+ callback(undefined, false);
36
+ })
37
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
38
+ this.log.info(`[${this.name} Switch] SET ON: ${value}`);
39
+ if (value) {
40
+ // this.streamer.startPlaying();
41
+ }
42
+ else {
43
+ // this.streamer.stopPlaying();
44
+ }
45
+ callback();
46
+ });
47
+ // create handlers for required characteristics
48
+ this.historyService = new eveHistoryService_1.EveHistoryService(this, this.api, this.logger);
49
+ }
50
+ getServices() {
51
+ return [
52
+ this.informationService,
53
+ this.service,
54
+ this.historyService.getService(),
55
+ ];
56
+ }
57
+ }
58
+ module.exports = (api) => {
59
+ hap = api.hap;
60
+ api.registerAccessory('homebridge-tuya-eve', 'TuyaSwitchEve', TuyaSwitchAccessoryAccessory);
61
+ };
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,+DAEiC;AAEjC,IAAI,GAAQ,CAAC;AAcb;;;;GAIG;AACH,MAAM,4BAA4B;IAchC,YACU,MAAe,EACf,MAAuB,EACvB,GAAQ;QAFR,WAAM,GAAN,MAAM,CAAS;QACf,WAAM,GAAN,MAAM,CAAiB;QACvB,QAAG,GAAH,GAAG,CAAK;QAEhB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;QAEd,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QAElB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,YAAY,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAEpD,2BAA2B;QAE3B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,oBAAoB,EAAE;aAC7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AAU,EAAE;SACjC,CAAC;IACJ,CAAC;CACF;AA1FD,iBAAS,CAAC,GAAQ,EAAE,EAAE;IACpB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IACd,GAAG,CAAC,iBAAiB,CACnB,qBAAqB,EACrB,eAAe,EACf,4BAA4B,CAC7B,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EveHistoryService = void 0;
7
+ const fakegato_history_1 = __importDefault(require("fakegato-history"));
8
+ class EveHistoryService {
9
+ constructor(accessory, api, logger) {
10
+ this.accessory = accessory;
11
+ this.api = api;
12
+ this.logger = logger;
13
+ const FakeGatoHistoryService = (0, fakegato_history_1.default)(api);
14
+ this.historyService = new FakeGatoHistoryService('thermo', this.accessory, { storage: 'fs', log: this.logger });
15
+ }
16
+ getService() {
17
+ return this.historyService;
18
+ }
19
+ addEntry(entry) {
20
+ this.historyService.addEntry(entry);
21
+ }
22
+ readHistory(lastEntryHandler) {
23
+ const storage = this.api.globalFakeGatoStorage;
24
+ if (!storage) {
25
+ this.logger.debug('Failed to access globalFakeGatoStorage');
26
+ return;
27
+ }
28
+ this.logger.debug('Reading data from globalFakeGatoStorage ...');
29
+ const thisAccessory = this.accessory;
30
+ storage.read({
31
+ service: this.historyService,
32
+ callback: function (err, data) {
33
+ if (!err) {
34
+ if (data) {
35
+ try {
36
+ const accessoryName = 'name' in thisAccessory ? thisAccessory['name'] : thisAccessory;
37
+ this.logger.debug('read data from', accessoryName);
38
+ const jsonFile = typeof (data) === 'object' ? data : JSON.parse(data);
39
+ lastEntryHandler(jsonFile.lastEntry, jsonFile.history);
40
+ }
41
+ catch (e) {
42
+ this.logger.debug('**ERROR fetching persisting data restart from zero - invalid JSON**', e);
43
+ }
44
+ }
45
+ }
46
+ else {
47
+ // file don't exists
48
+ this.logger.debug('**ERROR fetching persisting data: file dont exists', err);
49
+ }
50
+ }.bind(this),
51
+ });
52
+ }
53
+ }
54
+ exports.EveHistoryService = EveHistoryService;
55
+ //# sourceMappingURL=eveHistoryService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eveHistoryService.js","sourceRoot":"","sources":["../../src/lib/eveHistoryService.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAwC;AAsBxC,MAAa,iBAAiB;IAI1B,YAAoB,SAA0B,EAAU,GAAQ,EAAU,MAAe;QAArE,cAAS,GAAT,SAAS,CAAiB;QAAU,QAAG,GAAH,GAAG,CAAK;QAAU,WAAM,GAAN,MAAM,CAAS;QACvF,MAAM,sBAAsB,GAAG,IAAA,0BAAQ,EAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc,GAAG,IAAI,sBAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAClH,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,cAAyB,CAAC;IACxC,CAAC;IAED,QAAQ,CAAC,KAA0B;QAChC,IAAI,CAAC,cAAiC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,WAAW,CAAC,gBAA6E;QACvF,MAAM,OAAO,GAAK,IAAI,CAAC,GAAyC,CAAC,qBAAqB,CAAC;QAEvF,IAAI,CAAC,OAAO,EAAE;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,OAAO;SACR;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,cAAc;YAC5B,QAAQ,EAAE,UAAU,GAAG,EAAE,IAAI;gBAC3B,IAAI,CAAC,GAAG,EAAE;oBACR,IAAI,IAAI,EAAE;wBACR,IAAI;4BACF,MAAM,aAAa,GAAG,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;4BACtF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;4BACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;4BACtE,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,OAAgC,CAAC,CAAC;yBACjF;wBAAC,OAAO,CAAC,EAAE;4BACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qEAAqE,EAAE,CAAC,CAAC,CAAC;yBAC7F;qBACF;iBACF;qBAAM;oBACL,oBAAoB;oBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD,EAAE,GAAG,CAAC,CAAC;iBAC9E;YACH,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;SACb,CAAC,CAAC;IACL,CAAC;CACJ;AAhDD,8CAgDC"}
@@ -0,0 +1,19 @@
1
+ {
2
+ "bridge": {
3
+ "name": "Homebridge",
4
+ "username": "CC:22:3D:E3:CE:30",
5
+ "port": 51826,
6
+ "pin": "123-45-568"
7
+ },
8
+ "accessories": [
9
+ {
10
+ "accessory": "TuyaSwitchEve",
11
+ "name": "Main Switch",
12
+ "manufacturer": "Manufacturer",
13
+ "model": "Model=",
14
+ "id": "00000000000000000000",
15
+ "key": "0000000000000000",
16
+ "updateInterval": 10000
17
+ }
18
+ ]
19
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "displayName": "Homebridge Cooper&Hunter AC",
3
+ "name": "@petro-kushchak/homebridge-tuya-eve",
4
+ "version": "1.0.1",
5
+ "description": "Homebridge plugin for TuyAPI (with Eve app energy consumption monitoring)",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/petro-kushchak/homebridge-tuya-eve.git"
10
+ },
11
+ "engines": {
12
+ "node": ">=12.13.0",
13
+ "homebridge": ">=1.3.0"
14
+ },
15
+ "main": "dist/index.js",
16
+ "scripts": {
17
+ "lint": "eslint src/**.ts --max-warnings=0",
18
+ "watch": "npm run build && npm link && nodemon",
19
+ "build": "rimraf ./dist && tsc",
20
+ "prepublishOnly": "npm run lint && npm run build"
21
+ },
22
+ "keywords": [
23
+ "homebridge-plugin",
24
+ "air conditioning",
25
+ "cooper&hunter ac",
26
+ "homebridge heatercooler",
27
+ "eve",
28
+ "fakegato"
29
+ ],
30
+ "devDependencies": {
31
+ "@types/node": "^14.14.31",
32
+ "@typescript-eslint/eslint-plugin": "^4.16.1",
33
+ "@typescript-eslint/parser": "^4.16.1",
34
+ "eslint": "^7.21.0",
35
+ "homebridge": "^1.3.1",
36
+ "nodemon": "^2.0.7",
37
+ "rimraf": "^3.0.2",
38
+ "ts-node": "^9.1.1",
39
+ "typescript": "^4.2.2"
40
+ },
41
+ "dependencies": {
42
+ "fakegato-history": "^0.6.2"
43
+ }
44
+ }