homebridge-electra-smart-v2 1.0.0
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/LICENSE +176 -0
- package/README.md +215 -0
- package/config.schema.json +61 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +16 -0
- package/dist/platform.js +103 -0
- package/dist/platform.js.map +1 -0
- package/dist/platformAccessory.d.ts +25 -0
- package/dist/platformAccessory.js +341 -0
- package/dist/platformAccessory.js.map +1 -0
- package/dist/settings.d.ts +8 -0
- package/dist/settings.js +9 -0
- package/dist/settings.js.map +1 -0
- package/homebridge-ui/public/index.html +106 -0
- package/homebridge-ui/server.js +83 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://github.com/homebridge/branding/raw/latest/logos/homebridge-wordmark-logo-vertical.png" width="150">
|
|
4
|
+
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<span align="center">
|
|
8
|
+
|
|
9
|
+
# Homebridge Platform Plugin Template
|
|
10
|
+
|
|
11
|
+
</span>
|
|
12
|
+
|
|
13
|
+
> [!IMPORTANT]
|
|
14
|
+
> **Homebridge v2.0 Information**
|
|
15
|
+
>
|
|
16
|
+
> This template currently has a
|
|
17
|
+
> - `package.json -> engines.homebridge` value of `"^1.8.0 || ^2.0.0-beta.0"`
|
|
18
|
+
> - `package.json -> devDependencies.homebridge` value of `"^2.0.0-beta.0"`
|
|
19
|
+
>
|
|
20
|
+
> This is to ensure that your plugin will build and run on both Homebridge v1 and v2.
|
|
21
|
+
>
|
|
22
|
+
> Once Homebridge v2.0 has been released, you can remove the `-beta.0` in both places.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
This is a template Homebridge dynamic platform plugin and can be used as a base to help you get started developing your own plugin.
|
|
27
|
+
|
|
28
|
+
This template should be used in conjunction with the [developer documentation](https://developers.homebridge.io/). A full list of all supported service types, and their characteristics is available on this site.
|
|
29
|
+
|
|
30
|
+
### Clone As Template
|
|
31
|
+
|
|
32
|
+
Click the link below to create a new GitHub Repository using this template, or click the *Use This Template* button above.
|
|
33
|
+
|
|
34
|
+
<span align="center">
|
|
35
|
+
|
|
36
|
+
### [Create New Repository From Template](https://github.com/homebridge/homebridge-plugin-template/generate)
|
|
37
|
+
|
|
38
|
+
</span>
|
|
39
|
+
|
|
40
|
+
### Setup Development Environment
|
|
41
|
+
|
|
42
|
+
To develop Homebridge plugins you must have Node.js 20 or later installed, and a modern code editor such as [VS Code](https://code.visualstudio.com/). This plugin template uses [TypeScript](https://www.typescriptlang.org/) to make development easier and comes with pre-configured settings for [VS Code](https://code.visualstudio.com/) and ESLint. If you are using VS Code install these extensions:
|
|
43
|
+
|
|
44
|
+
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
45
|
+
|
|
46
|
+
### Install Development Dependencies
|
|
47
|
+
|
|
48
|
+
Using a terminal, navigate to the project folder and run this command to install the development dependencies:
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
npm install
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Update package.json
|
|
55
|
+
|
|
56
|
+
Open the [`package.json`](./package.json) and change the following attributes:
|
|
57
|
+
|
|
58
|
+
- `name` - this should be prefixed with `homebridge-` or `@username/homebridge-`, is case-sensitive, and contains no spaces nor special characters apart from a dash `-`
|
|
59
|
+
- `displayName` - this is the "nice" name displayed in the Homebridge UI
|
|
60
|
+
- `homepage` - link to your GitHub repo's `README.md`
|
|
61
|
+
- `repository.url` - link to your GitHub repo
|
|
62
|
+
- `bugs.url` - link to your GitHub repo issues page
|
|
63
|
+
|
|
64
|
+
When you are ready to publish the plugin you should set `private` to false, or remove the attribute entirely.
|
|
65
|
+
|
|
66
|
+
### Update Plugin Defaults
|
|
67
|
+
|
|
68
|
+
Open the [`src/settings.ts`](./src/settings.ts) file and change the default values:
|
|
69
|
+
|
|
70
|
+
- `PLATFORM_NAME` - Set this to be the name of your platform. This is the name of the platform that users will use to register the plugin in the Homebridge `config.json`.
|
|
71
|
+
- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file.
|
|
72
|
+
|
|
73
|
+
Open the [`config.schema.json`](./config.schema.json) file and change the following attribute:
|
|
74
|
+
|
|
75
|
+
- `pluginAlias` - set this to match the `PLATFORM_NAME` you defined in the previous step.
|
|
76
|
+
|
|
77
|
+
See the [Homebridge API docs](https://developers.homebridge.io/#/config-schema#default-values) for more details on the other attributes you can set in the `config.schema.json` file.
|
|
78
|
+
|
|
79
|
+
### Build Plugin
|
|
80
|
+
|
|
81
|
+
TypeScript needs to be compiled into JavaScript before it can run. The following command will compile the contents of your [`src`](./src) directory and put the resulting code into the `dist` folder.
|
|
82
|
+
|
|
83
|
+
```shell
|
|
84
|
+
npm run build
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Link To Homebridge
|
|
88
|
+
|
|
89
|
+
Run this command so your global installation of Homebridge can discover the plugin in your development environment:
|
|
90
|
+
|
|
91
|
+
```shell
|
|
92
|
+
npm link
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
You can now start Homebridge, use the `-D` flag, so you can see debug log messages in your plugin:
|
|
96
|
+
|
|
97
|
+
```shell
|
|
98
|
+
homebridge -D
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Watch For Changes and Build Automatically
|
|
102
|
+
|
|
103
|
+
If you want to have your code compile automatically as you make changes, and restart Homebridge automatically between changes, you first need to add your plugin as a platform in `./test/hbConfig/config.json`:
|
|
104
|
+
```
|
|
105
|
+
{
|
|
106
|
+
...
|
|
107
|
+
"platforms": [
|
|
108
|
+
{
|
|
109
|
+
"name": "Config",
|
|
110
|
+
"port": 8581,
|
|
111
|
+
"platform": "config"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "<PLUGIN_NAME>",
|
|
115
|
+
//... any other options, as listed in config.schema.json ...
|
|
116
|
+
"platform": "<PLATFORM_NAME>"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
and then you can run:
|
|
123
|
+
|
|
124
|
+
```shell
|
|
125
|
+
npm run watch
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This will launch an instance of Homebridge in debug mode which will restart every time you make a change to the source code. It will load the config stored in the default location under `~/.homebridge`. You may need to stop other running instances of Homebridge while using this command to prevent conflicts. You can adjust the Homebridge startup command in the [`nodemon.json`](./nodemon.json) file.
|
|
129
|
+
|
|
130
|
+
### Customise Plugin
|
|
131
|
+
|
|
132
|
+
You can now start customising the plugin template to suit your requirements.
|
|
133
|
+
|
|
134
|
+
- [`src/platform.ts`](./src/platform.ts) - this is where your device setup and discovery should go.
|
|
135
|
+
- [`src/platformAccessory.ts`](./src/platformAccessory.ts) - this is where your accessory control logic should go, you can rename or create multiple instances of this file for each accessory type you need to implement as part of your platform plugin. You can refer to the [developer documentation](https://developers.homebridge.io/) to see what characteristics you need to implement for each service type.
|
|
136
|
+
- [`config.schema.json`](./config.schema.json) - update the config schema to match the config you expect from the user. See the [Plugin Config Schema Documentation](https://developers.homebridge.io/#/config-schema).
|
|
137
|
+
|
|
138
|
+
### Versioning Your Plugin
|
|
139
|
+
|
|
140
|
+
Given a version number `MAJOR`.`MINOR`.`PATCH`, such as `1.4.3`, increment the:
|
|
141
|
+
|
|
142
|
+
1. **MAJOR** version when you make breaking changes to your plugin,
|
|
143
|
+
2. **MINOR** version when you add functionality in a backwards compatible manner, and
|
|
144
|
+
3. **PATCH** version when you make backwards compatible bug fixes.
|
|
145
|
+
|
|
146
|
+
You can use the `npm version` command to help you with this:
|
|
147
|
+
|
|
148
|
+
```shell
|
|
149
|
+
# major update / breaking changes
|
|
150
|
+
npm version major
|
|
151
|
+
|
|
152
|
+
# minor update / new features
|
|
153
|
+
npm version update
|
|
154
|
+
|
|
155
|
+
# patch / bugfixes
|
|
156
|
+
npm version patch
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Publish Package
|
|
160
|
+
|
|
161
|
+
When you are ready to publish your plugin to [npm](https://www.npmjs.com/), make sure you have removed the `private` attribute from the [`package.json`](./package.json) file then run:
|
|
162
|
+
|
|
163
|
+
```shell
|
|
164
|
+
npm publish
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
If you are publishing a scoped plugin, i.e. `@username/homebridge-xxx` you will need to add `--access=public` to command the first time you publish.
|
|
168
|
+
|
|
169
|
+
#### Publishing Beta Versions
|
|
170
|
+
|
|
171
|
+
You can publish *beta* versions of your plugin for other users to test before you release it to everyone.
|
|
172
|
+
|
|
173
|
+
```shell
|
|
174
|
+
# create a new pre-release version (eg. 2.1.0-beta.1)
|
|
175
|
+
npm version prepatch --preid beta
|
|
176
|
+
|
|
177
|
+
# publish to @beta
|
|
178
|
+
npm publish --tag beta
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Users can then install the *beta* version by appending `@beta` to the install command, for example:
|
|
182
|
+
|
|
183
|
+
```shell
|
|
184
|
+
sudo npm install -g homebridge-example-plugin@beta
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Best Practices
|
|
188
|
+
|
|
189
|
+
Consider creating your plugin with the [Homebridge Verified](https://github.com/homebridge/verified) criteria in mind. This will help you to create a plugin that is easy to use and works well with Homebridge.
|
|
190
|
+
You can then submit your plugin to the Homebridge Verified list for review.
|
|
191
|
+
The most up-to-date criteria can be found [here](https://github.com/homebridge/verified#requirements).
|
|
192
|
+
For reference, the current criteria are:
|
|
193
|
+
|
|
194
|
+
- **General**
|
|
195
|
+
- The plugin must be of type [dynamic platform](https://developers.homebridge.io/#/#dynamic-platform-template).
|
|
196
|
+
- The plugin must not offer the same nor less functionality than that of any existing **verified** plugin.
|
|
197
|
+
- **Repo**
|
|
198
|
+
- The plugin must be published to NPM and the source code available on a GitHub repository, with issues enabled.
|
|
199
|
+
- A GitHub release should be created for every new version of your plugin, with release notes.
|
|
200
|
+
- **Environment**
|
|
201
|
+
- The plugin must run on all [supported LTS versions of Node.js](https://github.com/homebridge/homebridge/wiki/How-To-Update-Node.js), at the time of writing this is Node v18, v20 and v22.
|
|
202
|
+
- The plugin must successfully install and not start unless it is configured.
|
|
203
|
+
- The plugin must not execute post-install scripts that modify the users' system in any way.
|
|
204
|
+
- The plugin must not require the user to run Homebridge in a TTY or with non-standard startup parameters, even for initial configuration.
|
|
205
|
+
- **Codebase**
|
|
206
|
+
- The plugin must implement the [Homebridge Plugin Settings GUI](https://developers.homebridge.io/#/config-schema).
|
|
207
|
+
- The plugin must not contain any analytics or calls that enable you to track the user.
|
|
208
|
+
- If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory.
|
|
209
|
+
- The plugin must not throw unhandled exceptions, the plugin must catch and log its own errors.
|
|
210
|
+
|
|
211
|
+
### Useful Links
|
|
212
|
+
|
|
213
|
+
Note these links are here for help but are not supported/verified by the Homebridge team
|
|
214
|
+
|
|
215
|
+
- [Custom Characteristics](https://github.com/homebridge/homebridge-plugin-template/issues/20)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "ElectraSmartPlatform",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"customUi": true,
|
|
5
|
+
"singular": true,
|
|
6
|
+
"headerDisplay": "Manage your Electra Smart AC units in HomeKit.",
|
|
7
|
+
"strictValidation": false,
|
|
8
|
+
"schema": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"properties": {
|
|
11
|
+
"imei": {
|
|
12
|
+
"title": "IMEI",
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"token": {
|
|
16
|
+
"title": "Access Token",
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"phoneNumber": {
|
|
20
|
+
"title": "Registration Phone Number",
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Use this to fetch your IMEI and Token if you don't have them."
|
|
23
|
+
},
|
|
24
|
+
"options": {
|
|
25
|
+
"title": "Additional Options",
|
|
26
|
+
"type": "object",
|
|
27
|
+
"properties": {
|
|
28
|
+
"hideDryMode": {
|
|
29
|
+
"title": "Hide Dry Mode Switch",
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"default": true,
|
|
32
|
+
"description": "Removes the separate Dry Mode switch from the Home app."
|
|
33
|
+
},
|
|
34
|
+
"hideFanMode": {
|
|
35
|
+
"title": "Hide Fan Mode Switch",
|
|
36
|
+
"type": "boolean",
|
|
37
|
+
"default": true,
|
|
38
|
+
"description": "Removes the separate Fan Mode switch from the Home app."
|
|
39
|
+
},
|
|
40
|
+
"pollInterval": {
|
|
41
|
+
"title": "Polling Interval (Seconds)",
|
|
42
|
+
"type": "integer",
|
|
43
|
+
"default": 60,
|
|
44
|
+
"minimum": 30,
|
|
45
|
+
"description": "How often to check for status changes (recommended 30-60s)."
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"layout": [
|
|
52
|
+
"phoneNumber",
|
|
53
|
+
{
|
|
54
|
+
"type": "help",
|
|
55
|
+
"helpvalue": "<button id='otp-btn' class='btn btn-primary'>Request SMS Code</button>"
|
|
56
|
+
},
|
|
57
|
+
"imei",
|
|
58
|
+
"token",
|
|
59
|
+
"options"
|
|
60
|
+
]
|
|
61
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElectraSmartPlatform } from './platform.js';
|
|
2
|
+
import { PLATFORM_NAME } from './settings.js';
|
|
3
|
+
/**
|
|
4
|
+
* This method registers the platform with Homebridge
|
|
5
|
+
*/
|
|
6
|
+
export default (api) => {
|
|
7
|
+
api.registerPlatform(PLATFORM_NAME, ElectraSmartPlatform);
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;GAEG;AACH,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;AAC5D,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { API, Characteristic, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service } from 'homebridge';
|
|
2
|
+
import { Client } from 'electra-smart-js-client';
|
|
3
|
+
export declare class ElectraSmartPlatform implements DynamicPlatformPlugin {
|
|
4
|
+
readonly log: Logging;
|
|
5
|
+
readonly config: PlatformConfig;
|
|
6
|
+
readonly api: API;
|
|
7
|
+
readonly Service: typeof Service;
|
|
8
|
+
readonly Characteristic: typeof Characteristic;
|
|
9
|
+
readonly accessories: Map<string, PlatformAccessory>;
|
|
10
|
+
readonly discoveredCacheUUIDs: string[];
|
|
11
|
+
client: Client | null;
|
|
12
|
+
constructor(log: Logging, config: PlatformConfig, api: API);
|
|
13
|
+
configureAccessory(accessory: PlatformAccessory): void;
|
|
14
|
+
private initializeElectraSmartClient;
|
|
15
|
+
discoverDevices(): Promise<void>;
|
|
16
|
+
}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ElectraPlatformAccessory } from './platformAccessory.js';
|
|
2
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
3
|
+
import { Client } from 'electra-smart-js-client';
|
|
4
|
+
export class ElectraSmartPlatform {
|
|
5
|
+
log;
|
|
6
|
+
config;
|
|
7
|
+
api;
|
|
8
|
+
Service;
|
|
9
|
+
Characteristic;
|
|
10
|
+
accessories = new Map();
|
|
11
|
+
discoveredCacheUUIDs = [];
|
|
12
|
+
client = null;
|
|
13
|
+
constructor(log, config, api) {
|
|
14
|
+
this.log = log;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.api = api;
|
|
17
|
+
this.Service = api.hap.Service;
|
|
18
|
+
this.Characteristic = api.hap.Characteristic;
|
|
19
|
+
this.log.debug('Finished initializing platform:', this.config.name);
|
|
20
|
+
// Initialize client and discover devices
|
|
21
|
+
this.api.on('didFinishLaunching', async () => {
|
|
22
|
+
this.log.debug('Executed didFinishLaunching callback');
|
|
23
|
+
const success = await this.initializeElectraSmartClient();
|
|
24
|
+
if (success) {
|
|
25
|
+
await this.discoverDevices();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.log.error('Discovery aborted due to client initialization failure.');
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Required by Homebridge to restore cached accessories
|
|
33
|
+
configureAccessory(accessory) {
|
|
34
|
+
this.log.info('Loading accessory from cache:', accessory.displayName);
|
|
35
|
+
this.accessories.set(accessory.UUID, accessory);
|
|
36
|
+
}
|
|
37
|
+
// Initializes the Electra Smart Client with provided credentials
|
|
38
|
+
async initializeElectraSmartClient() {
|
|
39
|
+
try {
|
|
40
|
+
const { imei, token } = this.config;
|
|
41
|
+
if (!imei || !token) {
|
|
42
|
+
this.log.error('Missing IMEI or Token in config. Please update your settings in the Homebridge UI.');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
this.client = new Client({ imei, token });
|
|
46
|
+
this.log.info('Electra Smart Client initialized successfully');
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.log.error('Failed to initialize Electra Smart Client:', error);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Main discovery logic
|
|
55
|
+
async discoverDevices() {
|
|
56
|
+
if (!this.client) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
this.log.info('Fetching devices from Electra Smart cloud...');
|
|
61
|
+
const devices = await this.client.getDevices();
|
|
62
|
+
if (!devices || devices.length === 0) {
|
|
63
|
+
this.log.warn('No devices found on your Electra account.');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.log.info(`Discovered ${devices.length} device(s)`);
|
|
67
|
+
for (const device of devices) {
|
|
68
|
+
const uuid = this.api.hap.uuid.generate(device.id.toString());
|
|
69
|
+
const existingAccessory = this.accessories.get(uuid);
|
|
70
|
+
if (existingAccessory) {
|
|
71
|
+
this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);
|
|
72
|
+
existingAccessory.context.device = device;
|
|
73
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
74
|
+
new ElectraPlatformAccessory(this, existingAccessory);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.log.info('Adding new accessory:', device.name);
|
|
78
|
+
const accessory = new this.api.platformAccessory(device.name, uuid);
|
|
79
|
+
accessory.context.device = device;
|
|
80
|
+
new ElectraPlatformAccessory(this, accessory);
|
|
81
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
82
|
+
accessory,
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
this.discoveredCacheUUIDs.push(uuid);
|
|
86
|
+
}
|
|
87
|
+
// Cleanup Orphaned Accessories
|
|
88
|
+
this.accessories.forEach((accessory, uuid) => {
|
|
89
|
+
if (!this.discoveredCacheUUIDs.includes(uuid)) {
|
|
90
|
+
this.log.info('Removing accessory no longer present in Electra account:', accessory.displayName);
|
|
91
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
92
|
+
accessory,
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.log.error('An error occurred during device discovery. Check your internet connection and API token.');
|
|
99
|
+
this.log.debug('Discovery Error Detail:', error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,MAAM,OAAO,oBAAoB;IAUb;IACA;IACA;IAXF,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AG,CAAC,6BAA6B,CAAC,WAAW,EAAE,aAAa,EAAE;wBACjE,SAAS;qBACV,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,0FAA0F,CAC3F,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory } from 'homebridge';
|
|
2
|
+
import { ElectraSmartPlatform } from './platform.js';
|
|
3
|
+
export declare class ElectraPlatformAccessory {
|
|
4
|
+
private readonly platform;
|
|
5
|
+
private readonly accessory;
|
|
6
|
+
private service;
|
|
7
|
+
private dryService?;
|
|
8
|
+
private fanModeService?;
|
|
9
|
+
private filterService;
|
|
10
|
+
constructor(platform: ElectraSmartPlatform, accessory: PlatformAccessory);
|
|
11
|
+
private getDeviceStatus;
|
|
12
|
+
setActive(value: CharacteristicValue): Promise<void>;
|
|
13
|
+
getActive(): Promise<CharacteristicValue>;
|
|
14
|
+
getCurrentState(): Promise<CharacteristicValue>;
|
|
15
|
+
getCurrentTemperature(): Promise<CharacteristicValue>;
|
|
16
|
+
setTargetTemperature(value: CharacteristicValue): Promise<void>;
|
|
17
|
+
getTargetTemperature(): Promise<CharacteristicValue>;
|
|
18
|
+
setTargetState(value: CharacteristicValue): Promise<void>;
|
|
19
|
+
getTargetState(): Promise<CharacteristicValue>;
|
|
20
|
+
setRotationSpeed(value: CharacteristicValue): Promise<void>;
|
|
21
|
+
getRotationSpeed(): Promise<CharacteristicValue>;
|
|
22
|
+
setCustomMode(mode: 'DRY' | 'FAN'): Promise<void>;
|
|
23
|
+
getFilterStatus(): Promise<CharacteristicValue>;
|
|
24
|
+
pollDeviceStatus(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
export class ElectraPlatformAccessory {
|
|
2
|
+
platform;
|
|
3
|
+
accessory;
|
|
4
|
+
service;
|
|
5
|
+
dryService;
|
|
6
|
+
fanModeService;
|
|
7
|
+
filterService;
|
|
8
|
+
constructor(platform, accessory) {
|
|
9
|
+
this.platform = platform;
|
|
10
|
+
this.accessory = accessory;
|
|
11
|
+
// Accessory Information
|
|
12
|
+
this.accessory
|
|
13
|
+
.getService(this.platform.Service.AccessoryInformation)
|
|
14
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.context.device.providerName || 'Electra')
|
|
15
|
+
.setCharacteristic(this.platform.Characteristic.Model, accessory.context.device.manufactor || 'Smart AC')
|
|
16
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.sn)
|
|
17
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.accessory.context.device.fmVersion || '1.0.0');
|
|
18
|
+
// 1. Main AC Service
|
|
19
|
+
this.service =
|
|
20
|
+
this.accessory.getService(this.platform.Service.HeaterCooler) ||
|
|
21
|
+
this.accessory.addService(this.platform.Service.HeaterCooler);
|
|
22
|
+
// 2. DRY MODE Switch
|
|
23
|
+
if (!this.platform.config.hideDryMode) {
|
|
24
|
+
this.dryService =
|
|
25
|
+
this.accessory.getService('Dry Mode') ||
|
|
26
|
+
this.accessory.addService(this.platform.Service.Switch, 'Dry Mode', 'dry-mode-switch');
|
|
27
|
+
this.dryService
|
|
28
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
29
|
+
.onSet(async (value) => value ? await this.setCustomMode('DRY') : await this.setActive(0));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// If user wants it hidden, remove the service if it exists
|
|
33
|
+
const existingDry = this.accessory.getService('Dry Mode');
|
|
34
|
+
if (existingDry) {
|
|
35
|
+
this.accessory.removeService(existingDry);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// 3. FAN MODE Switch
|
|
39
|
+
if (!this.platform.config.hideFanMode) {
|
|
40
|
+
this.fanModeService =
|
|
41
|
+
this.accessory.getService('Fan Mode') ||
|
|
42
|
+
this.accessory.addService(this.platform.Service.Switch, 'Fan Mode', 'fan-mode-switch');
|
|
43
|
+
this.fanModeService
|
|
44
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
45
|
+
.onSet(async (value) => value ? await this.setCustomMode('FAN') : await this.setActive(0));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const existingFan = this.accessory.getService('Fan Mode');
|
|
49
|
+
if (existingFan) {
|
|
50
|
+
this.accessory.removeService(existingFan);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// 4. FILTER Changne Indicator
|
|
54
|
+
this.filterService =
|
|
55
|
+
this.accessory.getService('Filter Change Indicator') ||
|
|
56
|
+
this.accessory.addService(this.platform.Service.FilterMaintenance, 'Filter Change Indicator', 'filter-change-indicator');
|
|
57
|
+
// GROUPING: Linking services tells the Home App they belong together
|
|
58
|
+
if (this.dryService) {
|
|
59
|
+
this.service.addLinkedService(this.dryService);
|
|
60
|
+
}
|
|
61
|
+
if (this.fanModeService) {
|
|
62
|
+
this.service.addLinkedService(this.fanModeService);
|
|
63
|
+
}
|
|
64
|
+
this.service.addLinkedService(this.filterService);
|
|
65
|
+
// --- Characteristic Bindings ---
|
|
66
|
+
this.service
|
|
67
|
+
.getCharacteristic(this.platform.Characteristic.Active)
|
|
68
|
+
.onSet(this.setActive.bind(this))
|
|
69
|
+
.onGet(this.getActive.bind(this));
|
|
70
|
+
this.service
|
|
71
|
+
.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
|
|
72
|
+
.onGet(this.getCurrentState.bind(this));
|
|
73
|
+
this.service
|
|
74
|
+
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
75
|
+
.onGet(this.getCurrentTemperature.bind(this));
|
|
76
|
+
this.service
|
|
77
|
+
.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
|
|
78
|
+
.onSet(this.setTargetState.bind(this))
|
|
79
|
+
.onGet(this.getTargetState.bind(this));
|
|
80
|
+
this.service
|
|
81
|
+
.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
|
|
82
|
+
.setProps({ minStep: 1, minValue: 16, maxValue: 30 })
|
|
83
|
+
.onSet(this.setTargetTemperature.bind(this))
|
|
84
|
+
.onGet(this.getTargetTemperature.bind(this));
|
|
85
|
+
this.service
|
|
86
|
+
.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
|
|
87
|
+
.setProps({ minStep: 1, minValue: 16, maxValue: 30 })
|
|
88
|
+
.onSet(this.setTargetTemperature.bind(this))
|
|
89
|
+
.onGet(this.getTargetTemperature.bind(this));
|
|
90
|
+
this.service
|
|
91
|
+
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
92
|
+
.setProps({ minStep: 25, minValue: 0, maxValue: 100 })
|
|
93
|
+
.onSet(this.setRotationSpeed.bind(this))
|
|
94
|
+
.onGet(this.getRotationSpeed.bind(this));
|
|
95
|
+
// this.service
|
|
96
|
+
// .getCharacteristic(this.platform.Characteristic.SwingMode)
|
|
97
|
+
// .onSet(this.setSwingMode.bind(this))
|
|
98
|
+
// .onGet(this.getSwingMode.bind(this));
|
|
99
|
+
this.dryService
|
|
100
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
101
|
+
.onSet(async (value) => value ? await this.setCustomMode('DRY') : await this.setActive(0));
|
|
102
|
+
this.fanModeService
|
|
103
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
104
|
+
.onSet(async (value) => value ? await this.setCustomMode('FAN') : await this.setActive(0));
|
|
105
|
+
this.filterService
|
|
106
|
+
.getCharacteristic(this.platform.Characteristic.FilterChangeIndication)
|
|
107
|
+
.onGet(this.getFilterStatus.bind(this));
|
|
108
|
+
/*
|
|
109
|
+
POLLING:
|
|
110
|
+
Poll every 30 seconds (30000ms). // ToDo: Make interval configurable.
|
|
111
|
+
Electra's servers might temporarily block IP if they see too many requests.
|
|
112
|
+
30–60 seconds is usually the "sweet spot" for responsiveness versus stability.
|
|
113
|
+
*/
|
|
114
|
+
const pollInterval = (this.platform.config.pollInterval || 30) * 1000;
|
|
115
|
+
setInterval(() => this.pollDeviceStatus(), pollInterval);
|
|
116
|
+
}
|
|
117
|
+
// HELPER: The library lacks getDeviceStatus, so we filter getDevices
|
|
118
|
+
async getDeviceStatus() {
|
|
119
|
+
try {
|
|
120
|
+
const deviceId = this.accessory.context.device.id;
|
|
121
|
+
const telemetry = await this.platform.client?.getTelemetry(deviceId);
|
|
122
|
+
this.platform.log.debug(`[${this.accessory.context.device.name}] Live Telemetry:`, telemetry);
|
|
123
|
+
return {
|
|
124
|
+
oper: telemetry?.OPER,
|
|
125
|
+
diag: telemetry?.DIAG_L2,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.platform.log.error('Failed to fetch telemetry:', error);
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// --- Handlers ---
|
|
134
|
+
async setActive(value) {
|
|
135
|
+
try {
|
|
136
|
+
if (value === this.platform.Characteristic.Active.ACTIVE) {
|
|
137
|
+
await this.platform.client?.setMode(this.accessory.context.device.id, 'COOL');
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
await this.platform.client?.setMode(this.accessory.context.device.id, 'STBY');
|
|
141
|
+
}
|
|
142
|
+
this.platform.log.info(`Set Active to: ${value}`);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.platform.log.error('Failed to set Active state:', error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async getActive() {
|
|
149
|
+
const status = await this.getDeviceStatus();
|
|
150
|
+
this.platform.log.debug('Active State:', status?.oper?.AC_MODE);
|
|
151
|
+
return status?.oper?.AC_MODE === 'STBY' ? 0 : 1;
|
|
152
|
+
}
|
|
153
|
+
async getCurrentState() {
|
|
154
|
+
const status = await this.getDeviceStatus();
|
|
155
|
+
this.platform.log.debug('Current State:', status?.oper?.AC_MODE);
|
|
156
|
+
switch (status?.oper?.AC_MODE) {
|
|
157
|
+
case 'COOL':
|
|
158
|
+
return this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
159
|
+
case 'HEAT':
|
|
160
|
+
return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
161
|
+
case 'AUTO':
|
|
162
|
+
case 'FAN':
|
|
163
|
+
case 'DRY':
|
|
164
|
+
return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
165
|
+
default:
|
|
166
|
+
return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async getCurrentTemperature() {
|
|
170
|
+
const status = await this.getDeviceStatus();
|
|
171
|
+
this.platform.log.debug('Current Temperature:', status?.diag?.I_RAT);
|
|
172
|
+
return status?.diag?.I_RAT || 22;
|
|
173
|
+
}
|
|
174
|
+
async setTargetTemperature(value) {
|
|
175
|
+
await this.platform.client?.setTemperature(this.accessory.context.device.id, value);
|
|
176
|
+
this.platform.log.info(`Set Target Temperature to: ${value}`);
|
|
177
|
+
}
|
|
178
|
+
async getTargetTemperature() {
|
|
179
|
+
const status = await this.getDeviceStatus();
|
|
180
|
+
this.platform.log.debug('Target Temperature:', status?.oper?.SPT);
|
|
181
|
+
return status?.oper?.SPT || 24;
|
|
182
|
+
}
|
|
183
|
+
async setTargetState(value) {
|
|
184
|
+
let mode = 'AUTO';
|
|
185
|
+
switch (value) {
|
|
186
|
+
case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
|
|
187
|
+
mode = 'COOL';
|
|
188
|
+
break;
|
|
189
|
+
case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
|
|
190
|
+
mode = 'HEAT';
|
|
191
|
+
break;
|
|
192
|
+
case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
|
|
193
|
+
mode = 'AUTO';
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
await this.platform.client?.setMode(this.accessory.context.device.id, mode);
|
|
197
|
+
// If we switch to Heat/Cool/Auto, turn off Dry/Fan switches
|
|
198
|
+
this.dryService?.updateCharacteristic(this.platform.Characteristic.On, false);
|
|
199
|
+
this.fanModeService?.updateCharacteristic(this.platform.Characteristic.On, false);
|
|
200
|
+
this.platform.log.info(`Changing mode to: ${mode}`);
|
|
201
|
+
}
|
|
202
|
+
async getTargetState() {
|
|
203
|
+
const status = await this.getDeviceStatus();
|
|
204
|
+
this.platform.log.debug('Target State:', status?.oper?.AC_MODE);
|
|
205
|
+
switch (status?.oper?.AC_MODE) {
|
|
206
|
+
case 'COOL':
|
|
207
|
+
return this.platform.Characteristic.TargetHeaterCoolerState.COOL;
|
|
208
|
+
case 'HEAT':
|
|
209
|
+
return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
210
|
+
case 'AUTO':
|
|
211
|
+
return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
212
|
+
default:
|
|
213
|
+
return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async setRotationSpeed(value) {
|
|
217
|
+
const speed = value;
|
|
218
|
+
let electraSpeed = 'AUTO';
|
|
219
|
+
if (speed > 75) {
|
|
220
|
+
electraSpeed = 'HIGH';
|
|
221
|
+
}
|
|
222
|
+
else if (speed > 45) {
|
|
223
|
+
electraSpeed = 'MED';
|
|
224
|
+
}
|
|
225
|
+
else if (speed > 10) {
|
|
226
|
+
electraSpeed = 'LOW';
|
|
227
|
+
}
|
|
228
|
+
await this.platform.client?.setFanSpeed(this.accessory.context.device.id, electraSpeed);
|
|
229
|
+
this.platform.log.info(`Set Rotation Speed to: ${electraSpeed}`);
|
|
230
|
+
}
|
|
231
|
+
async getRotationSpeed() {
|
|
232
|
+
const status = await this.getDeviceStatus();
|
|
233
|
+
this.platform.log.debug('Rotation Speed:', status?.oper?.FANSPD);
|
|
234
|
+
switch (status?.oper?.FANSPD) {
|
|
235
|
+
case 'HIGH':
|
|
236
|
+
return 100;
|
|
237
|
+
case 'MED':
|
|
238
|
+
return 50;
|
|
239
|
+
case 'LOW':
|
|
240
|
+
return 25;
|
|
241
|
+
default:
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// async setSwingMode(value: CharacteristicValue) {
|
|
246
|
+
// const isSwingOn =
|
|
247
|
+
// value === this.platform.Characteristic.SwingMode.SWING_ENABLED;
|
|
248
|
+
// this.platform.log.info(
|
|
249
|
+
// `Setting Swing Mode to: ${isSwingOn ? 'ON' : 'OFF'}`,
|
|
250
|
+
// );
|
|
251
|
+
// await this.platform.client?.sendCommand(this.accessory.context.device.id, {
|
|
252
|
+
// SWING: isSwingOn ? 'ON' : 'OFF',
|
|
253
|
+
// } as any);
|
|
254
|
+
// }
|
|
255
|
+
// async getSwingMode(): Promise<CharacteristicValue> {
|
|
256
|
+
// const status = await this.getDeviceStatus();
|
|
257
|
+
// const swingState = status?.oper?.V_SWING;
|
|
258
|
+
// this.platform.log.debug('Current Swing State:', swingState);
|
|
259
|
+
// return swingState === 'ON'
|
|
260
|
+
// ? this.platform.Characteristic.SwingMode.SWING_ENABLED
|
|
261
|
+
// : this.platform.Characteristic.SwingMode.SWING_DISABLED;
|
|
262
|
+
// }
|
|
263
|
+
async setCustomMode(mode) {
|
|
264
|
+
try {
|
|
265
|
+
await this.platform.client?.setMode(this.accessory.context.device.id, mode);
|
|
266
|
+
this.dryService?.updateCharacteristic(this.platform.Characteristic.On, mode === 'DRY');
|
|
267
|
+
this.fanModeService?.updateCharacteristic(this.platform.Characteristic.On, mode === 'FAN');
|
|
268
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Active, 1);
|
|
269
|
+
this.platform.log.info(`Set mode to: ${mode}`);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
this.platform.log.error(`Failed to set ${mode} mode:`, error);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async getFilterStatus() {
|
|
276
|
+
const status = await this.getDeviceStatus();
|
|
277
|
+
this.platform.log.debug('Filter Status:', status?.oper?.CLEAR_FILT);
|
|
278
|
+
const needsCleaning = status?.oper?.CLEAR_FILT === 'ON';
|
|
279
|
+
if (needsCleaning) {
|
|
280
|
+
this.platform.log.info('Filter cleaning detected! Sending auto-reset command...');
|
|
281
|
+
this.platform.client
|
|
282
|
+
?.sendCommand(this.accessory.context.device.id, {
|
|
283
|
+
CLEAR_FILT: 'OFF',
|
|
284
|
+
})
|
|
285
|
+
.catch(error => this.platform.log.error('Auto-reset failed:', error));
|
|
286
|
+
return this.platform.Characteristic.FilterChangeIndication.CHANGE_FILTER;
|
|
287
|
+
}
|
|
288
|
+
return this.platform.Characteristic.FilterChangeIndication.FILTER_OK;
|
|
289
|
+
}
|
|
290
|
+
async pollDeviceStatus() {
|
|
291
|
+
try {
|
|
292
|
+
const status = await this.getDeviceStatus();
|
|
293
|
+
if (!status) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Active, status.oper?.AC_MODE === 'STBY' ? 0 : 1);
|
|
297
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, status.oper?.AC_MODE === 'COOL'
|
|
298
|
+
? this.platform.Characteristic.CurrentHeaterCoolerState.COOLING
|
|
299
|
+
: status.oper?.AC_MODE === 'HEAT'
|
|
300
|
+
? this.platform.Characteristic.CurrentHeaterCoolerState.HEATING
|
|
301
|
+
: status.oper?.AC_MODE === 'AUTO'
|
|
302
|
+
? this.platform.Characteristic.CurrentHeaterCoolerState.IDLE
|
|
303
|
+
: this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE);
|
|
304
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, status.diag?.I_RAT);
|
|
305
|
+
let targetState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
306
|
+
if (status.oper?.AC_MODE === 'COOL') {
|
|
307
|
+
targetState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
|
|
308
|
+
}
|
|
309
|
+
if (status.oper?.AC_MODE === 'HEAT') {
|
|
310
|
+
targetState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
311
|
+
}
|
|
312
|
+
this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, targetState);
|
|
313
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, status.oper?.SPT);
|
|
314
|
+
this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, status.oper?.SPT);
|
|
315
|
+
let rotationSpeed = 0;
|
|
316
|
+
switch (status.oper?.FANSPD) {
|
|
317
|
+
case 'HIGH':
|
|
318
|
+
rotationSpeed = 100;
|
|
319
|
+
break;
|
|
320
|
+
case 'MED':
|
|
321
|
+
rotationSpeed = 50;
|
|
322
|
+
break;
|
|
323
|
+
case 'LOW':
|
|
324
|
+
rotationSpeed = 25;
|
|
325
|
+
break;
|
|
326
|
+
default:
|
|
327
|
+
rotationSpeed = 0;
|
|
328
|
+
}
|
|
329
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, rotationSpeed);
|
|
330
|
+
this.dryService?.updateCharacteristic(this.platform.Characteristic.On, status.oper?.AC_MODE === 'DRY');
|
|
331
|
+
this.fanModeService?.updateCharacteristic(this.platform.Characteristic.On, status.oper?.AC_MODE === 'FAN');
|
|
332
|
+
this.filterService.updateCharacteristic(this.platform.Characteristic.FilterChangeIndication, status.oper?.CLEAR_FILT === 'ON'
|
|
333
|
+
? this.platform.Characteristic.FilterChangeIndication.CHANGE_FILTER
|
|
334
|
+
: this.platform.Characteristic.FilterChangeIndication.FILTER_OK);
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
this.platform.log.error('Polling error:', error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=platformAccessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,wBAAwB;IAOhB;IACA;IAPX,OAAO,CAAU;IACjB,UAAU,CAAW;IACrB,cAAc,CAAW;IACzB,aAAa,CAAU;IAE/B,YACmB,QAA8B,EAC9B,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,cAAS,GAAT,SAAS,CAAmB;QAE7C,wBAAwB;QACxB,IAAI,CAAC,SAAS;aACX,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACvD,iBAAiB,CAChB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EACzC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,SAAS,CACnD;aACA,iBAAiB,CAChB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,EAClC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,UAAU,CAClD;aACA,iBAAiB,CAChB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EACzC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAY,CACtC;aACA,iBAAiB,CAChB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,gBAAgB,EAC7C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,OAAO,CACnD,CAAC;QAEJ,qBAAqB;QACrB,IAAI,CAAC,OAAO;YACV,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC7D,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,C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the name of the platform that users will use to register the plugin in the Homebridge config.json
|
|
3
|
+
*/
|
|
4
|
+
export declare const PLATFORM_NAME = "ElectraSmartPlatform";
|
|
5
|
+
/**
|
|
6
|
+
* This must match the name of your plugin as defined the package.json `name` property
|
|
7
|
+
*/
|
|
8
|
+
export declare const PLUGIN_NAME = "homebridge-electra-smart-v2";
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the name of the platform that users will use to register the plugin in the Homebridge config.json
|
|
3
|
+
*/
|
|
4
|
+
export const PLATFORM_NAME = 'ElectraSmartPlatform';
|
|
5
|
+
/**
|
|
6
|
+
* This must match the name of your plugin as defined the package.json `name` property
|
|
7
|
+
*/
|
|
8
|
+
export const PLUGIN_NAME = 'homebridge-electra-smart-v2';
|
|
9
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<div class="card card-body">
|
|
2
|
+
<div id="step-1">
|
|
3
|
+
<h4 class="mb-3">Connect Electra Smart</h4>
|
|
4
|
+
<p class="text-muted small">
|
|
5
|
+
Enter your phone number to receive a one-time login code.
|
|
6
|
+
</p>
|
|
7
|
+
<div class="form-group">
|
|
8
|
+
<label for="phone-input">Phone Number</label>
|
|
9
|
+
<input
|
|
10
|
+
type="text"
|
|
11
|
+
id="phone-input"
|
|
12
|
+
placeholder="0501234567"
|
|
13
|
+
class="form-control"
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
<button id="send-otp-btn" class="btn btn-primary btn-block mt-3">
|
|
17
|
+
Send SMS Code
|
|
18
|
+
</button>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div id="step-2" style="display: none">
|
|
22
|
+
<h4 class="mb-3">Verify SMS Code</h4>
|
|
23
|
+
<p class="text-muted small">Enter the 4-digit code sent to your phone.</p>
|
|
24
|
+
<div class="form-group">
|
|
25
|
+
<label for="otp-input">Verification Code</label>
|
|
26
|
+
<input
|
|
27
|
+
type="text"
|
|
28
|
+
id="otp-input"
|
|
29
|
+
placeholder="1234"
|
|
30
|
+
class="form-control text-center"
|
|
31
|
+
style="letter-spacing: 10px; font-size: 1.5rem"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
<button id="verify-btn" class="btn btn-success btn-block mt-3">
|
|
35
|
+
Verify & Connect
|
|
36
|
+
</button>
|
|
37
|
+
<button id="back-btn" class="btn btn-link btn-sm btn-block mt-2">
|
|
38
|
+
Change Phone Number
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div id="setup-complete" style="display: none" class="text-center py-4">
|
|
43
|
+
<i class="fa fa-check-circle fa-3x text-success mb-3"></i>
|
|
44
|
+
<h5>Account Linked!</h5>
|
|
45
|
+
<p class="text-muted">Restart Homebridge to apply changes.</p>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
(async () => {
|
|
51
|
+
const hb = window.homebridge;
|
|
52
|
+
|
|
53
|
+
// Initial State Check
|
|
54
|
+
const config = await hb.getPluginConfig();
|
|
55
|
+
if (config[0]?.token && config[0]?.imei) {
|
|
56
|
+
document.getElementById('step-1').style.display = 'none';
|
|
57
|
+
document.getElementById('setup-complete').style.display = 'block';
|
|
58
|
+
hb.showSchemaForm();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.getElementById('send-otp-btn').onclick = async () => {
|
|
62
|
+
const phone = document.getElementById('phone-input').value;
|
|
63
|
+
if (!phone) return hb.toast.error('Phone number required');
|
|
64
|
+
hb.showSpinner();
|
|
65
|
+
try {
|
|
66
|
+
await hb.request('/request-otp', { phone });
|
|
67
|
+
document.getElementById('step-1').style.display = 'none';
|
|
68
|
+
document.getElementById('step-2').style.display = 'block';
|
|
69
|
+
hb.toast.success('SMS Sent');
|
|
70
|
+
} catch (err) {
|
|
71
|
+
hb.toast.error(err.message);
|
|
72
|
+
} finally {
|
|
73
|
+
hb.hideSpinner();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
document.getElementById('verify-btn').onclick = async () => {
|
|
78
|
+
const otp = document.getElementById('otp-input').value;
|
|
79
|
+
const phone = document.getElementById('phone-input').value;
|
|
80
|
+
hb.showSpinner();
|
|
81
|
+
try {
|
|
82
|
+
const res = await hb.request('/verify-otp', { phone, otp });
|
|
83
|
+
const config = await hb.getPluginConfig();
|
|
84
|
+
const current = config[0] || { platform: 'ElectraSmartPlatform' };
|
|
85
|
+
current.imei = res.imei;
|
|
86
|
+
current.token = res.token;
|
|
87
|
+
await hb.updatePluginConfig([current]);
|
|
88
|
+
await hb.savePluginConfig();
|
|
89
|
+
|
|
90
|
+
document.getElementById('step-2').style.display = 'none';
|
|
91
|
+
document.getElementById('setup-complete').style.display = 'block';
|
|
92
|
+
hb.showSchemaForm();
|
|
93
|
+
hb.toast.success('Success!');
|
|
94
|
+
} catch (err) {
|
|
95
|
+
hb.toast.error(err.message);
|
|
96
|
+
} finally {
|
|
97
|
+
hb.hideSpinner();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
document.getElementById('back-btn').onclick = () => {
|
|
102
|
+
document.getElementById('step-2').style.display = 'none';
|
|
103
|
+
document.getElementById('step-1').style.display = 'block';
|
|
104
|
+
};
|
|
105
|
+
})();
|
|
106
|
+
</script>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HomebridgePluginUiServer,
|
|
3
|
+
RequestError,
|
|
4
|
+
} from '@homebridge/plugin-ui-utils';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
// 1. Get the actual directory of THIS file (homebridge-ui folder)
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
// 2. Create a require function that looks at your plugin's root
|
|
13
|
+
// We go up one level from 'homebridge-ui' to find 'node_modules'
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
|
|
16
|
+
class UiServer extends HomebridgePluginUiServer {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
this.client = null;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// Try to resolve the client class
|
|
24
|
+
const electra = require('electra-smart-js-client');
|
|
25
|
+
const ElectraClass = electra.ElectraSmartClient || electra;
|
|
26
|
+
this.client = new ElectraClass();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// If that fails, try an absolute path from the plugin root
|
|
29
|
+
try {
|
|
30
|
+
const rootPath = join(
|
|
31
|
+
__dirname,
|
|
32
|
+
'..',
|
|
33
|
+
'node_modules',
|
|
34
|
+
'electra-smart-js-client',
|
|
35
|
+
);
|
|
36
|
+
const electra = require(rootPath);
|
|
37
|
+
const ElectraClass = electra.ElectraSmartClient || electra;
|
|
38
|
+
this.client = new ElectraClass();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
this.client = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.imei = this.generateIMEI();
|
|
45
|
+
this.onRequest('/request-otp', this.handleRequestOtp.bind(this));
|
|
46
|
+
this.onRequest('/verify-otp', this.handleVerifyOtp.bind(this));
|
|
47
|
+
this.ready();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async handleRequestOtp({ phone }) {
|
|
51
|
+
if (!this.client) {
|
|
52
|
+
throw new RequestError(
|
|
53
|
+
'Library resolution failed. Please ensure "electra-smart-js-client" is in your package.json dependencies.',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await this.client.requestOtp(phone, this.imei);
|
|
58
|
+
return { success: true };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new RequestError(`Electra API Error: ${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async handleVerifyOtp({ phone, otp }) {
|
|
65
|
+
try {
|
|
66
|
+
const res = await this.client.verifyOtp(phone, otp, this.imei);
|
|
67
|
+
return { imei: this.imei, token: res.token };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
throw new RequestError(error.message || 'Invalid code');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
generateIMEI() {
|
|
74
|
+
return (
|
|
75
|
+
'2b95' +
|
|
76
|
+
Math.floor(10000000000 + Math.random() * 90000000000)
|
|
77
|
+
.toString()
|
|
78
|
+
.substring(0, 11)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
new UiServer();
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "homebridge-electra-smart-v2",
|
|
3
|
+
"displayName": "Electra Smart A/C",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"private": false,
|
|
7
|
+
"description": "Homebridge plugin for Electra Smart A/C units",
|
|
8
|
+
"author": "Yossi Hillali",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"homepage": "https://github.com/hillaliy/Homebridge-Electra-Smart",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/hillaliy/Homebridge-Electra-Smart.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/hillaliy/Homebridge-Electra-Smart/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"homebridge-plugin"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"homebridge-ui",
|
|
25
|
+
"config.schema.json"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^20.18.0 || ^22.10.0 || ^24.0.0",
|
|
29
|
+
"homebridge": "^1.8.0 || ^2.0.0-beta.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "rimraf ./dist && tsc",
|
|
33
|
+
"lint": "eslint . --max-warnings=0",
|
|
34
|
+
"prepublishOnly": "npm run lint && npm run build",
|
|
35
|
+
"watch": "npm run build && npm link && nodemon"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@homebridge/plugin-ui-utils": "^2.1.2",
|
|
39
|
+
"electra-smart-js-client": "^1.0.1",
|
|
40
|
+
"homebridge-lib": "^7.1.12"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.39.1",
|
|
44
|
+
"@types/node": "^24.10.1",
|
|
45
|
+
"eslint": "^9.39.1",
|
|
46
|
+
"homebridge": "^2.0.0-beta.55",
|
|
47
|
+
"nodemon": "^3.1.11",
|
|
48
|
+
"rimraf": "^6.1.0",
|
|
49
|
+
"ts-node": "^10.9.2",
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"typescript-eslint": "^8.46.4"
|
|
52
|
+
}
|
|
53
|
+
}
|