@akospasztor/homebridge-create-ceiling-fan 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/CHANGELOG.md +5 -0
- package/LICENSE +176 -0
- package/README.md +151 -0
- package/config.schema.json +55 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mutex.d.ts +61 -0
- package/dist/mutex.js +96 -0
- package/dist/mutex.js.map +1 -0
- package/dist/platform.d.ts +48 -0
- package/dist/platform.js +108 -0
- package/dist/platform.js.map +1 -0
- package/dist/platformAccessory.d.ts +309 -0
- package/dist/platformAccessory.js +542 -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/docs/fan-speed-slider.gif +0 -0
- package/docs/homebridge-create-logo.png +0 -0
- package/package.json +60 -0
package/CHANGELOG.md
ADDED
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,151 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/homebridge-create-logo.png" alt="Homebridge Create Ceiling Fan Plugin Logo" width="450">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# Homebridge Create Ceiling Fan Plugin
|
|
6
|
+
|
|
7
|
+
This plugin allows integrating the CREATE ceiling fans into HomeKit via
|
|
8
|
+
HomeBridge.
|
|
9
|
+
|
|
10
|
+
Although there are several HomeBridge plugins that provide similar
|
|
11
|
+
functionality, this plugin aims to stand out via providing a smooth,
|
|
12
|
+
user-friendly fan speed control mechanism in the HomeKit UI and a robust device
|
|
13
|
+
communication mechanism with a mutex. It also reflects and updates the changes
|
|
14
|
+
via the physical remote automatically in HomeKit.
|
|
15
|
+
|
|
16
|
+
**Tested Devices:**
|
|
17
|
+
|
|
18
|
+
- CREATE Wind Calm (with light, WiFi + Remote controller)
|
|
19
|
+
|
|
20
|
+
## Contents
|
|
21
|
+
|
|
22
|
+
- [Features](#features)
|
|
23
|
+
- [Requirements](#requirements)
|
|
24
|
+
- [Usage](#usage)
|
|
25
|
+
- [Known issues](#known-issues)
|
|
26
|
+
- [Acknowledgements](#acknowledgements)
|
|
27
|
+
- [Developer documentation](#developer-documentation)
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- [x] Support for devices with and without light
|
|
32
|
+
- [x] User-friendly fan speed control via the HomeKit UI slider
|
|
33
|
+
- [x] Local communication, does not require connection to the Tuya IoT cloud
|
|
34
|
+
platform [^1]
|
|
35
|
+
- [x] Robust communication implementation
|
|
36
|
+
- [x] Changes via physical remote controller and other applications are
|
|
37
|
+
automatically reflected in HomeKit
|
|
38
|
+
- [ ] Add support for devices with dimmable light
|
|
39
|
+
- [ ] Add support for toggling the beep sound feedback
|
|
40
|
+
|
|
41
|
+
## Requirements
|
|
42
|
+
|
|
43
|
+
### Getting the local key of the device
|
|
44
|
+
|
|
45
|
+
The TinyTuya project has great step-by-step instructions
|
|
46
|
+
[how to obtain the local key](https://github.com/jasonacox/tinytuya/tree/master?tab=readme-ov-file#setup-wizard---getting-local-keys)
|
|
47
|
+
of a device.
|
|
48
|
+
|
|
49
|
+
In order to obtain the local key of a device, it needs to be paired with the
|
|
50
|
+
Smart Life App or Tuya Smart App. If the device has already been paired with the
|
|
51
|
+
CREATE app, you can reset the device with its remote the following way:
|
|
52
|
+
|
|
53
|
+
1. Power off the fan (i.e. cut the power by turning off its wall switch or with
|
|
54
|
+
the associated breaker depending on the installation).
|
|
55
|
+
2. Power on the device.
|
|
56
|
+
3. Press and hold the `1h` button on the remote until you hear a beep.
|
|
57
|
+
4. Now the device is ready to be paired again.
|
|
58
|
+
|
|
59
|
+
Note from the CREATE app: if you do not hear a beep after 10 seconds, press and
|
|
60
|
+
hold the buttons `1h` and `2h` simultaneously at the same time.
|
|
61
|
+
|
|
62
|
+
### Fixed IP address
|
|
63
|
+
|
|
64
|
+
It's strongly recommended to set up a DHCP IP reservation for the device. This
|
|
65
|
+
way the fan will always have a fixed IP address assigned. The TuyAPI library
|
|
66
|
+
used for device communication works reliably when the IP address of the device
|
|
67
|
+
is used alongside with the device ID.
|
|
68
|
+
|
|
69
|
+
Note: the device used for the initial plugin development is a CREATE Wind Calm
|
|
70
|
+
purchased in 2025, and it refuses most connection attempts via the TuyAPI when
|
|
71
|
+
the IP address is not supplied (connection requests with ID only).
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
### Installation
|
|
76
|
+
|
|
77
|
+
### Configuration
|
|
78
|
+
|
|
79
|
+
By default, one HomeKit tile is exposed in the Home application for a device.
|
|
80
|
+
You can group or ungroup the different accessories of the fan (e.g. the fan
|
|
81
|
+
slider and the light switch) in the group section of the accessory settings
|
|
82
|
+
within the Home app.
|
|
83
|
+
|
|
84
|
+
### Setting the rotation speed via the HomeKit slider
|
|
85
|
+
|
|
86
|
+
The following UI slider inputs represent the different speed settings of the
|
|
87
|
+
fan. The fan is turned off when the slider is set to zero.
|
|
88
|
+
|
|
89
|
+
| Device fan speed | Corresponding UI slider value | User input range on the slider |
|
|
90
|
+
| :--------------: | :---------------------------: | :----------------------------: |
|
|
91
|
+
| 1 | 10 | 1 - 19 |
|
|
92
|
+
| 2 | 30 | 20 - 39 |
|
|
93
|
+
| 3 | 50 | 40 - 59 |
|
|
94
|
+
| 4 | 70 | 60 - 79 |
|
|
95
|
+
| 5 | 90 | 80 - 94 |
|
|
96
|
+
| 6 | 100 | 95 - 100 |
|
|
97
|
+
|
|
98
|
+
Whenever the user operates the slider, a so-called debouncing timer is set. When
|
|
99
|
+
the timer expires (without the user changing the slider), the current state of
|
|
100
|
+
the slider value is converted to the nearest value that corresponds to the
|
|
101
|
+
device fan speed. The purpose of the debounce timer is to provide great user
|
|
102
|
+
experience: without the debounce timer, the slider would jump around
|
|
103
|
+
immediately, without waiting for the user to finish adjusting the speed.
|
|
104
|
+
|
|
105
|
+
**Demo:**
|
|
106
|
+
|
|
107
|
+
<p align="center">
|
|
108
|
+
<img src="docs/fan-speed-slider.gif" alt="Fan Speed Slider UI" width="300">
|
|
109
|
+
</p>
|
|
110
|
+
|
|
111
|
+
### Setting the rotation direction via the HomeKit button
|
|
112
|
+
|
|
113
|
+
The Home app shows a small icon below the fan speed slider representing the
|
|
114
|
+
rotation direction of the fan. The implementation follows the general convention
|
|
115
|
+
that the direction is represented from the perspective when the user looks at
|
|
116
|
+
the fan; i.e. standing below and looking up in the case of a ceiling fan.
|
|
117
|
+
|
|
118
|
+
The counter-clockwise icon in the Home shows that the fan rotates
|
|
119
|
+
counter-clockwise when looked at directly from below. In this mode the fan blows
|
|
120
|
+
air downwards, called the "summer" mode. Changing the direction to clockwise
|
|
121
|
+
rotation makes the fan rotate in the opposite direction, causing the air being
|
|
122
|
+
pushed upwards. This mode is called the "winter" mode.
|
|
123
|
+
|
|
124
|
+
## Known issues
|
|
125
|
+
|
|
126
|
+
### Color temperature
|
|
127
|
+
|
|
128
|
+
It appears that the color temperature of the CREATE Wind Calm ceiling fan
|
|
129
|
+
(purchased in 2025) cannot be set properly. Regardless of using the physical
|
|
130
|
+
remote, the mobile application or manually sending the commands via TinyTuya,
|
|
131
|
+
the device simply cycles through the 3 different color temperatures and it does
|
|
132
|
+
not remember it's previously set state. This issue has also been observed here:
|
|
133
|
+
[https://github.com/velzend/create_ikohs_fan](https://github.com/velzend/create_ikohs_fan)
|
|
134
|
+
|
|
135
|
+
Therefore, this plugin does not support setting the color temperature until this
|
|
136
|
+
has been fixed by CREATE.
|
|
137
|
+
|
|
138
|
+
## Acknowledgements
|
|
139
|
+
|
|
140
|
+
- [TinyTuya](https://github.com/jasonacox/tinytuya)
|
|
141
|
+
- [TuyAPI](https://github.com/codetheweb/tuyapi)
|
|
142
|
+
|
|
143
|
+
## Developer documentation
|
|
144
|
+
|
|
145
|
+
[https://akospasztor.github.io/homebridge-create-ceiling-fan/](https://akospasztor.github.io/homebridge-create-ceiling-fan/)
|
|
146
|
+
|
|
147
|
+
<!-- Footnotes -->
|
|
148
|
+
|
|
149
|
+
[^1]: Please note that the Tuya IoT cloud platform registration is still needed
|
|
150
|
+
to obtain the local keys for the device. After obtaining the keys, the device
|
|
151
|
+
can be blocked from accessing the internet.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "CreateCeilingFanPlatform",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"strictValidation": true,
|
|
6
|
+
"schema": {
|
|
7
|
+
"devices": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"title": "Devices",
|
|
10
|
+
"items": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"properties": {
|
|
13
|
+
"name": {
|
|
14
|
+
"title": "Name",
|
|
15
|
+
"description": "The accessory name that is displayed in the Home app",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "Ceiling Fan",
|
|
18
|
+
"required": true
|
|
19
|
+
},
|
|
20
|
+
"id": {
|
|
21
|
+
"title": "Device ID",
|
|
22
|
+
"description": "Device ID retrieved from the Tuya IoT Cloud Platform",
|
|
23
|
+
"type": "string",
|
|
24
|
+
"required": true
|
|
25
|
+
},
|
|
26
|
+
"key": {
|
|
27
|
+
"title": "Device key",
|
|
28
|
+
"description": "Local key of the device retrieved with tinytuya",
|
|
29
|
+
"type": "string",
|
|
30
|
+
"required": true
|
|
31
|
+
},
|
|
32
|
+
"ip": {
|
|
33
|
+
"title": "IP address",
|
|
34
|
+
"description": "IP address of the device (optional, but recommended to reserve a static address for this device on your LAN for better performance)",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"required": true
|
|
37
|
+
},
|
|
38
|
+
"protocolVersion": {
|
|
39
|
+
"title": "Protocol version",
|
|
40
|
+
"description": "Tuya device protocol version",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"default": "3.5",
|
|
43
|
+
"required": false
|
|
44
|
+
},
|
|
45
|
+
"hasLight": {
|
|
46
|
+
"title": "Fan with light",
|
|
47
|
+
"description": "Check this if the fan is equipped with light",
|
|
48
|
+
"type": "boolean",
|
|
49
|
+
"required": false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateCeilingFanPlatform } 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, CreateCeilingFanPlatform);
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;GAEG;AACH,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,wBAAwB,CAAC,CAAC;AAChE,CAAC,CAAC"}
|
package/dist/mutex.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple mutex with a waiting queue.
|
|
3
|
+
*
|
|
4
|
+
* The mutex can be acquired by calling the `lock()` method which returns a
|
|
5
|
+
* promise with a function pointing to the `unlock()` method. Afterwards the
|
|
6
|
+
* caller can carry out the operations that are protected by the mutex. Then
|
|
7
|
+
* the caller who holds the mutex must call the previously returned function
|
|
8
|
+
* to unlock the mutex. If the caller fails to do so, the mutex will remain
|
|
9
|
+
* locked.
|
|
10
|
+
*
|
|
11
|
+
* If the mutex is free to be locked, the locking happens immediately and the
|
|
12
|
+
* caller can carry out its prorected operations. When the mutex is locked,
|
|
13
|
+
* any subsequent caller that is trying to lock the mutex is forced to wait.
|
|
14
|
+
* In this case , the actual acquire functionality is not executed but pushed
|
|
15
|
+
* to the waiting queue. When the mutex is unlocked by the first caller, the
|
|
16
|
+
* queue is processed and the mutex is locked immediately for the next in
|
|
17
|
+
* waiting, i.e. resolving the promise by returning a function pointer (to the
|
|
18
|
+
* mutex unlock method) for the caller.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Create the mutex object
|
|
22
|
+
* this.mutex = new Mutex();
|
|
23
|
+
* ...
|
|
24
|
+
* // Attempt to lock the mutex
|
|
25
|
+
* // Note: the returned function pointer needs to be called to unlock the mutex
|
|
26
|
+
* const releaseMutex = await this.mutex.lock();
|
|
27
|
+
* // Do stuff protected by the mutex; this example just starts a timer with 3 seconds timeout
|
|
28
|
+
* await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
29
|
+
* // Release the mutex
|
|
30
|
+
* releaseMutex();
|
|
31
|
+
*/
|
|
32
|
+
export declare class Mutex {
|
|
33
|
+
/** Track if the mutex is currently locked. */
|
|
34
|
+
private isLocked;
|
|
35
|
+
/** Queue for handling the lock requests when the mutex is already locked. */
|
|
36
|
+
private waitingQueue;
|
|
37
|
+
/**
|
|
38
|
+
* Lock the mutex.
|
|
39
|
+
*
|
|
40
|
+
* If the mutex is free to be locked, the locking happens immediately and the
|
|
41
|
+
* caller can carry out its prorected operations. When the mutex is locked,
|
|
42
|
+
* any subsequent caller that is trying to lock the mutex is forced to wait.
|
|
43
|
+
*
|
|
44
|
+
* @return A promise that is resolved when the mutex is given to the caller.
|
|
45
|
+
* The returned promise (that is itself a function pointer) must be
|
|
46
|
+
* called to free (unlock) the mutex.
|
|
47
|
+
*/
|
|
48
|
+
lock(): Promise<() => void>;
|
|
49
|
+
/** Unlock the mutex.
|
|
50
|
+
*
|
|
51
|
+
* This method is returned to the caller indicating that the mutex is locked.
|
|
52
|
+
* After completing the operations protected by the mutex, the caller must
|
|
53
|
+
* call this method to unlock (release) the mutex. If the caller fails to do
|
|
54
|
+
* so, the mutex will remain locked.
|
|
55
|
+
*
|
|
56
|
+
* When the mutex is unlocked by the first caller and there are several
|
|
57
|
+
* callers waiting to lock the mutex, the waiting queue is processed and the
|
|
58
|
+
* mutex is locked immediately for the next caller in waiting.
|
|
59
|
+
*/
|
|
60
|
+
private unlock;
|
|
61
|
+
}
|
package/dist/mutex.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple mutex with a waiting queue.
|
|
3
|
+
*
|
|
4
|
+
* The mutex can be acquired by calling the `lock()` method which returns a
|
|
5
|
+
* promise with a function pointing to the `unlock()` method. Afterwards the
|
|
6
|
+
* caller can carry out the operations that are protected by the mutex. Then
|
|
7
|
+
* the caller who holds the mutex must call the previously returned function
|
|
8
|
+
* to unlock the mutex. If the caller fails to do so, the mutex will remain
|
|
9
|
+
* locked.
|
|
10
|
+
*
|
|
11
|
+
* If the mutex is free to be locked, the locking happens immediately and the
|
|
12
|
+
* caller can carry out its prorected operations. When the mutex is locked,
|
|
13
|
+
* any subsequent caller that is trying to lock the mutex is forced to wait.
|
|
14
|
+
* In this case , the actual acquire functionality is not executed but pushed
|
|
15
|
+
* to the waiting queue. When the mutex is unlocked by the first caller, the
|
|
16
|
+
* queue is processed and the mutex is locked immediately for the next in
|
|
17
|
+
* waiting, i.e. resolving the promise by returning a function pointer (to the
|
|
18
|
+
* mutex unlock method) for the caller.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Create the mutex object
|
|
22
|
+
* this.mutex = new Mutex();
|
|
23
|
+
* ...
|
|
24
|
+
* // Attempt to lock the mutex
|
|
25
|
+
* // Note: the returned function pointer needs to be called to unlock the mutex
|
|
26
|
+
* const releaseMutex = await this.mutex.lock();
|
|
27
|
+
* // Do stuff protected by the mutex; this example just starts a timer with 3 seconds timeout
|
|
28
|
+
* await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
29
|
+
* // Release the mutex
|
|
30
|
+
* releaseMutex();
|
|
31
|
+
*/
|
|
32
|
+
export class Mutex {
|
|
33
|
+
/** Track if the mutex is currently locked. */
|
|
34
|
+
isLocked = false;
|
|
35
|
+
/** Queue for handling the lock requests when the mutex is already locked. */
|
|
36
|
+
waitingQueue = [];
|
|
37
|
+
/**
|
|
38
|
+
* Lock the mutex.
|
|
39
|
+
*
|
|
40
|
+
* If the mutex is free to be locked, the locking happens immediately and the
|
|
41
|
+
* caller can carry out its prorected operations. When the mutex is locked,
|
|
42
|
+
* any subsequent caller that is trying to lock the mutex is forced to wait.
|
|
43
|
+
*
|
|
44
|
+
* @return A promise that is resolved when the mutex is given to the caller.
|
|
45
|
+
* The returned promise (that is itself a function pointer) must be
|
|
46
|
+
* called to free (unlock) the mutex.
|
|
47
|
+
*/
|
|
48
|
+
async lock() {
|
|
49
|
+
return new Promise(resolve => {
|
|
50
|
+
// The actual locking function will be called either:
|
|
51
|
+
// - immediately if the lock is free, or
|
|
52
|
+
// - later from the queue when the lock becomes free
|
|
53
|
+
const acquireLock = () => {
|
|
54
|
+
this.isLocked = true;
|
|
55
|
+
resolve(() => this.unlock());
|
|
56
|
+
};
|
|
57
|
+
// If the mutex is not yet locked, then lock it here and resolve the
|
|
58
|
+
// promise by returning the unlock function to the caller. If it's
|
|
59
|
+
// already locked, then do not resolve the promise and push the
|
|
60
|
+
// actual locking function to the waiting queue. As soon as the current
|
|
61
|
+
// lock is unlocked, the next in line waiting will be resolved.
|
|
62
|
+
if (!this.isLocked) {
|
|
63
|
+
acquireLock();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.waitingQueue.push(acquireLock);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** Unlock the mutex.
|
|
71
|
+
*
|
|
72
|
+
* This method is returned to the caller indicating that the mutex is locked.
|
|
73
|
+
* After completing the operations protected by the mutex, the caller must
|
|
74
|
+
* call this method to unlock (release) the mutex. If the caller fails to do
|
|
75
|
+
* so, the mutex will remain locked.
|
|
76
|
+
*
|
|
77
|
+
* When the mutex is unlocked by the first caller and there are several
|
|
78
|
+
* callers waiting to lock the mutex, the waiting queue is processed and the
|
|
79
|
+
* mutex is locked immediately for the next caller in waiting.
|
|
80
|
+
*/
|
|
81
|
+
unlock() {
|
|
82
|
+
// Check if there is a caller waiting in line for the mutex
|
|
83
|
+
if (this.waitingQueue.length > 0) {
|
|
84
|
+
// Pass the mutex to the next in line
|
|
85
|
+
const nextPending = this.waitingQueue.shift();
|
|
86
|
+
if (nextPending) {
|
|
87
|
+
nextPending();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Release the lock if noone is waiting for the mutex
|
|
92
|
+
this.isLocked = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=mutex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutex.js","sourceRoot":"","sources":["../src/mutex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,KAAK;IAChB,8CAA8C;IACtC,QAAQ,GAAY,KAAK,CAAC;IAElC,6EAA6E;IACrE,YAAY,GAAmB,EAAE,CAAC;IAE1C;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,qDAAqD;YACrD,wCAAwC;YACxC,oDAAoD;YACpD,MAAM,WAAW,GAAG,GAAG,EAAE;gBACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACrB,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC/B,CAAC,CAAC;YAEF,oEAAoE;YACpE,kEAAkE;YAClE,+DAA+D;YAC/D,uEAAuE;YACvE,+DAA+D;YAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnB,WAAW,EAAE,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACK,MAAM;QACZ,2DAA2D;QAC3D,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,qCAAqC;YACrC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAC9C,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,qDAAqD;YACrD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { API, Characteristic, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service } from 'homebridge';
|
|
2
|
+
/**
|
|
3
|
+
* CreateCeilingFanPlatform: the platform implementation for CREATE ceiling fans.
|
|
4
|
+
*
|
|
5
|
+
* This class contains the platform implementation and follows the Homebridge
|
|
6
|
+
* plugin development recommendations.
|
|
7
|
+
*
|
|
8
|
+
* @see https://developers.homebridge.io/#/
|
|
9
|
+
* @see https://github.com/homebridge/homebridge-plugin-template/blob/latest/README.md
|
|
10
|
+
*/
|
|
11
|
+
export declare class CreateCeilingFanPlatform implements DynamicPlatformPlugin {
|
|
12
|
+
readonly log: Logging;
|
|
13
|
+
readonly config: PlatformConfig;
|
|
14
|
+
readonly api: API;
|
|
15
|
+
/** The HomeKit Accessory Protocol (HAP) service. */
|
|
16
|
+
readonly Service: typeof Service;
|
|
17
|
+
/** The HomeKit Accessory Protocol (HAP) characteristic. */
|
|
18
|
+
readonly Characteristic: typeof Characteristic;
|
|
19
|
+
/** Used for tracking the restored cached accessories. */
|
|
20
|
+
readonly accessories: Map<string, PlatformAccessory>;
|
|
21
|
+
/** Used for tracking the cached UUIDs. */
|
|
22
|
+
readonly discoveredCacheUUIDs: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The CreateCeilingFanPlatform constructor.
|
|
25
|
+
*
|
|
26
|
+
* Note: This constructor is called by Homebridge.
|
|
27
|
+
*
|
|
28
|
+
* @param log The logging object.
|
|
29
|
+
* @param config The platform configuration object.
|
|
30
|
+
* @param api The API object.
|
|
31
|
+
*/
|
|
32
|
+
constructor(log: Logging, config: PlatformConfig, api: API);
|
|
33
|
+
/**
|
|
34
|
+
* This function is invoked when Homebridge restores cached accessories from
|
|
35
|
+
* the disk at startup. It should be used to set up event handlers for
|
|
36
|
+
* characteristics and update respective values.
|
|
37
|
+
*
|
|
38
|
+
* @param accessory The accessory restored from the disk at startup.
|
|
39
|
+
*/
|
|
40
|
+
configureAccessory(accessory: PlatformAccessory): void;
|
|
41
|
+
/**
|
|
42
|
+
* Register discovered accessories.
|
|
43
|
+
*
|
|
44
|
+
* Accessories must only be registered once, previously created accessories
|
|
45
|
+
* must not be registered again to prevent "duplicate UUID" errors.
|
|
46
|
+
*/
|
|
47
|
+
private discoverDevices;
|
|
48
|
+
}
|