homebridge-xihome-plugin 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.
Files changed (43) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +215 -0
  3. package/config.schema.json +18 -0
  4. package/dist/@types/device.d.ts +65 -0
  5. package/dist/@types/device.js +2 -0
  6. package/dist/@types/device.js.map +1 -0
  7. package/dist/@types/index.d.ts +5 -0
  8. package/dist/@types/index.js +2 -0
  9. package/dist/@types/index.js.map +1 -0
  10. package/dist/accessory/baseAccessory.d.ts +3 -0
  11. package/dist/accessory/baseAccessory.js +2 -0
  12. package/dist/accessory/baseAccessory.js.map +1 -0
  13. package/dist/accessory/hcl.d.ts +25 -0
  14. package/dist/accessory/hcl.js +79 -0
  15. package/dist/accessory/hcl.js.map +1 -0
  16. package/dist/accessory/heater.d.ts +23 -0
  17. package/dist/accessory/heater.js +113 -0
  18. package/dist/accessory/heater.js.map +1 -0
  19. package/dist/accessory/light.d.ts +40 -0
  20. package/dist/accessory/light.js +78 -0
  21. package/dist/accessory/light.js.map +1 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.js +9 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/modules/base.d.ts +17 -0
  26. package/dist/modules/base.js +65 -0
  27. package/dist/modules/base.js.map +1 -0
  28. package/dist/modules/heater.d.ts +9 -0
  29. package/dist/modules/heater.js +32 -0
  30. package/dist/modules/heater.js.map +1 -0
  31. package/dist/modules/light.d.ts +10 -0
  32. package/dist/modules/light.js +47 -0
  33. package/dist/modules/light.js.map +1 -0
  34. package/dist/platform.d.ts +31 -0
  35. package/dist/platform.js +146 -0
  36. package/dist/platform.js.map +1 -0
  37. package/dist/settings.d.ts +8 -0
  38. package/dist/settings.js +9 -0
  39. package/dist/settings.js.map +1 -0
  40. package/dist/util/client.d.ts +46 -0
  41. package/dist/util/client.js +171 -0
  42. package/dist/util/client.js.map +1 -0
  43. package/package.json +48 -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,18 @@
1
+ {
2
+ "pluginAlias": "XiHomePlugin",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "strictValidation": false,
6
+ "schema": {
7
+ "type": "object",
8
+ "required": ["name"],
9
+ "additionalProperties": false,
10
+ "properties": {
11
+ "name": {
12
+ "title": "XiHomePlugin",
13
+ "type": "string",
14
+ "default": "Example Dynamic Platform"
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,65 @@
1
+ export type RawDevice<Status extends any = any, CustomStatus extends any = any> = {
2
+ device_uuid: string;
3
+ apt_code: string;
4
+ dong_no: string;
5
+ ho_no: string;
6
+ room_id: string;
7
+ device_id: string;
8
+ device_type: string;
9
+ device_group: string;
10
+ device_group_main: string;
11
+ device_name: string;
12
+ device_name_by_device_group_main: string;
13
+ device_name_by_room: string;
14
+ power: number;
15
+ seq: number;
16
+ status: Status;
17
+ status_custom: CustomStatus;
18
+ room_seq: number;
19
+ };
20
+ export type LightDevice = RawDevice<{
21
+ power: boolean;
22
+ type: "1";
23
+ typeMode: string;
24
+ dimming: string;
25
+ }>;
26
+ export type HclLightDevice = RawDevice<{
27
+ power: boolean;
28
+ type: "5";
29
+ typeMode: string;
30
+ /** 1-20 사이의 값 */
31
+ dimming: string;
32
+ hcl_allday: string;
33
+ hcl_morning: string;
34
+ hcl_night: string;
35
+ morning_time: string;
36
+ night_time: string;
37
+ }>;
38
+ export type HeaterDevice = RawDevice<{
39
+ power: boolean;
40
+ device_id: string;
41
+ mode: number;
42
+ curtemp: string;
43
+ settemp: string;
44
+ }>;
45
+ export type DeviceType = "light" | "hcl" | "heater";
46
+ export type Device<type extends DeviceType = any> = {
47
+ id: string;
48
+ uuid: string;
49
+ name: string;
50
+ roomId: string;
51
+ group: string;
52
+ type: type;
53
+ } & ({
54
+ group: "light";
55
+ type: "light";
56
+ raw: LightDevice;
57
+ } | {
58
+ group: "light";
59
+ type: "hcl";
60
+ raw: HclLightDevice;
61
+ } | {
62
+ group: "heater";
63
+ type: "heater";
64
+ raw: HeaterDevice;
65
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../../src/@types/device.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { PlatformAccessory } from "homebridge";
2
+ import { Device, DeviceType } from "./device.js";
3
+ export type XiHomePlatformAccessory<type extends DeviceType = any> = PlatformAccessory<{
4
+ device: Device<type>;
5
+ }>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/@types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export interface BaseAccessory {
2
+ updateState(): Promise<void>;
3
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=baseAccessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseAccessory.js","sourceRoot":"","sources":["../../src/accessory/baseAccessory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import type { CharacteristicValue } from "homebridge";
2
+ import type { ExampleHomebridgePlatform } from "../platform.js";
3
+ import { XiHomePlatformAccessory as XiHomePlatformAccessory } from "../@types/index.js";
4
+ import { BaseAccessory } from "./baseAccessory.js";
5
+ /**
6
+ * Platform Accessory
7
+ * An instance of this class is created for each accessory your platform registers
8
+ * Each accessory may expose multiple services of different service types.
9
+ */
10
+ export declare class HCLAccessory implements BaseAccessory {
11
+ private readonly platform;
12
+ private readonly accessory;
13
+ private service;
14
+ /**
15
+ * These are just used to create a working example
16
+ * You should implement your own code to track the state of your accessory
17
+ */
18
+ private device;
19
+ private timeout;
20
+ constructor(platform: ExampleHomebridgePlatform, accessory: XiHomePlatformAccessory<"hcl">);
21
+ setOn(value: CharacteristicValue): Promise<void>;
22
+ getOn(): Promise<CharacteristicValue>;
23
+ setBrightness(value: CharacteristicValue): Promise<void>;
24
+ updateState(): Promise<void>;
25
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Platform Accessory
3
+ * An instance of this class is created for each accessory your platform registers
4
+ * Each accessory may expose multiple services of different service types.
5
+ */
6
+ export class HCLAccessory {
7
+ platform;
8
+ accessory;
9
+ service;
10
+ /**
11
+ * These are just used to create a working example
12
+ * You should implement your own code to track the state of your accessory
13
+ */
14
+ device;
15
+ timeout = null;
16
+ constructor(platform, accessory) {
17
+ this.platform = platform;
18
+ this.accessory = accessory;
19
+ // set accessory information
20
+ this.accessory
21
+ .getService(this.platform.Service.AccessoryInformation)
22
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "Default-Manufacturer")
23
+ .setCharacteristic(this.platform.Characteristic.Model, "Default-Model")
24
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.uuid);
25
+ // get the LightBulb service if it exists, otherwise create a new LightBulb service
26
+ // you can create multiple services for each accessory
27
+ this.service =
28
+ this.accessory.getService(this.platform.Service.Lightbulb) ||
29
+ this.accessory.addService(this.platform.Service.Lightbulb);
30
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
31
+ this.device = accessory.context.device;
32
+ // each service must implement at-minimum the "required characteristics" for the given service type
33
+ // see https://developers.homebridge.io/#/service/Lightbulb
34
+ // register handlers for the On/Off Characteristic
35
+ this.service
36
+ .getCharacteristic(this.platform.Characteristic.On)
37
+ .onSet(this.setOn.bind(this)) // SET - bind to the `setOn` method below
38
+ .onGet(this.getOn.bind(this)); // GET - bind to the `getOn` method below
39
+ this.service
40
+ .getCharacteristic(this.platform.Characteristic.Brightness)
41
+ .onSet(this.setBrightness.bind(this))
42
+ .setProps({
43
+ minStep: 5,
44
+ }); // SET - bind to the `setBrightness` method below
45
+ // register handlers for the Brightness Characteristic
46
+ this.service
47
+ .getCharacteristic(this.platform.Characteristic.Brightness)
48
+ .onSet(this.setBrightness.bind(this)); // SET - bind to the `setBrightness` method below
49
+ }
50
+ async setOn(value) {
51
+ await this.platform.client.modules.light.setHclState(this.device.id, {
52
+ power: value,
53
+ });
54
+ }
55
+ async getOn() {
56
+ return this.device.raw.status.power;
57
+ }
58
+ async setBrightness(value) {
59
+ if (this.timeout) {
60
+ clearTimeout(this.timeout);
61
+ }
62
+ this.timeout = setTimeout(() => {
63
+ this.platform.client.modules.light
64
+ .setHclState(this.device.id, {
65
+ brightness: value / 5,
66
+ })
67
+ .then(() => {
68
+ this.updateState();
69
+ });
70
+ }, 500);
71
+ }
72
+ async updateState() {
73
+ const device = this.platform.client.getDevice(this.device.id);
74
+ this.device = device;
75
+ this.service.updateCharacteristic(this.platform.Characteristic.On, device.raw.status.power);
76
+ this.service.updateCharacteristic(this.platform.Characteristic.Brightness, parseInt(device.raw.status.dimming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;QACD,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK;iBAC/B,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;gBAC3B,UAAU,EAAG,KAAgB,GAAG,CAAC;aAClC,CAAC;iBACD,IAAI,CAAC,GAAG,EAAE;gBACT,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,CAAC,CAAC,CAAC;QACP,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAC3C,IAAI,CAAC,MAAM,CAAC,EAAE,CACE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAC/B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAC/B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CACxB,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAC/B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,EACvC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CACxC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import type { CharacteristicValue } from "homebridge";
2
+ import type { ExampleHomebridgePlatform } from "../platform.js";
3
+ import { XiHomePlatformAccessory as XiHomePlatformAccessory } from "../@types/index.js";
4
+ import { BaseAccessory } from "./baseAccessory.js";
5
+ /**
6
+ * Platform Accessory
7
+ * An instance of this class is created for each accessory your platform registers
8
+ * Each accessory may expose multiple services of different service types.
9
+ */
10
+ export declare class HeaterAccessory implements BaseAccessory {
11
+ private readonly platform;
12
+ private readonly accessory;
13
+ private service;
14
+ /**
15
+ * These are just used to create a working example
16
+ * You should implement your own code to track the state of your accessory
17
+ */
18
+ private device;
19
+ constructor(platform: ExampleHomebridgePlatform, accessory: XiHomePlatformAccessory<"heater">);
20
+ setOn(value: CharacteristicValue): Promise<void>;
21
+ setTemperature(value: CharacteristicValue): Promise<void>;
22
+ updateState(): Promise<void>;
23
+ }