homebridge-petlibro-feeder 0.0.0-stage → 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.txt +202 -0
- package/README.md +135 -2
- package/config.schema.json +47 -0
- package/dist/accessory.js +59 -0
- package/dist/accessory.js.map +1 -0
- package/dist/feeder.js +23 -0
- package/dist/feeder.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.js +46 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.js +3 -0
- package/dist/settings.js.map +1 -0
- package/dist/telnet.js +105 -0
- package/dist/telnet.js.map +1 -0
- package/package.json +59 -4
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# homebridge-petlibro-feeder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Homebridge plugin that dispenses food on **Petlibro PLAF203** smart feeders over the local network and exposes each feeder as a switch in Apple Home. It works fully locally: no Petlibro or Tuya cloud, no account, no API keys.
|
|
4
|
+
|
|
5
|
+
> **Tested only on the Petlibro PLAF203.** It may work on similar Tuya-based feeders, see [Compatibility](#compatibility).
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
The feeder's main board (running the Tuya firmware) talks to the motor controller (MCU) over a serial port, `/dev/ttySAK1`. Writing the right frame to that port makes the MCU run the feed motor. The plugin does exactly that:
|
|
10
|
+
|
|
11
|
+
1. A HomeKit switch is turned on (manually, from an automation, or by a scene).
|
|
12
|
+
2. The plugin opens a telnet connection to the feeder, logs in with the configured username and password, and runs a single shell command, for example:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
echo -en "\x55\xaa\x03\x01\x00\x01\x01\x05" > /dev/ttySAK1
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
3. The plugin closes the connection and the switch turns itself off again after about a second.
|
|
19
|
+
|
|
20
|
+
The connection is opened per dispense and is not kept alive.
|
|
21
|
+
|
|
22
|
+
### Serial frame
|
|
23
|
+
|
|
24
|
+
The frame follows the Tuya MCU serial protocol:
|
|
25
|
+
|
|
26
|
+
| Bytes | Meaning |
|
|
27
|
+
| ------- | ---------------------------------------------- |
|
|
28
|
+
| `55 aa` | Frame header |
|
|
29
|
+
| `03` | Protocol version |
|
|
30
|
+
| `01` | Command |
|
|
31
|
+
| `00 01` | Data length (1 byte) |
|
|
32
|
+
| `NN` | Data byte, set from the `portions` setting |
|
|
33
|
+
| `CC` | Checksum, sum of all previous bytes modulo 256 |
|
|
34
|
+
|
|
35
|
+
With `portions: 1` the frame is `55 aa 03 01 00 01 01 05`, which is the known-good command from the device. For other values the plugin recalculates the checksum. Treating the data byte as a portion count is an assumption; verify it on your device (see [Verify manually](#verify-manually)).
|
|
36
|
+
|
|
37
|
+
### Safety behaviour
|
|
38
|
+
|
|
39
|
+
- **Cooldown:** by default a feeder can't dispense again for 30 minutes after a successful dispense, so automations or accidental taps can't overfeed your pet. Requests during the cooldown are ignored and logged as a warning. Set `cooldownMinutes` to `0` to disable it.
|
|
40
|
+
- **No double dispense:** if a dispense is already in progress, further requests are ignored.
|
|
41
|
+
- **Failures:** if the telnet login or command fails, the error is logged, the switch resets, and the cooldown is not started.
|
|
42
|
+
|
|
43
|
+
## Requirements
|
|
44
|
+
|
|
45
|
+
- Homebridge 1.8 or later (including 2.x)
|
|
46
|
+
- Node.js 26 or later
|
|
47
|
+
- Telnet access to the feeder with a known login (this plugin doesn't enable it for you)
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Install through the Homebridge UI by searching for `homebridge-petlibro-feeder`, or from the command line:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
npm install -g homebridge-petlibro-feeder
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
Use the Homebridge UI settings form, or add the platform to `config.json`:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"platform": "PetlibroFeeder",
|
|
64
|
+
"password": "YOUR_TELNET_PASSWORD",
|
|
65
|
+
"cooldownMinutes": 30,
|
|
66
|
+
"devices": [
|
|
67
|
+
{ "name": "Kitchen Feeder", "ip": "192.168.1.217", "portions": 1 },
|
|
68
|
+
{ "name": "Bedroom Feeder", "ip": "192.168.1.218", "portions": 2 }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Option | Default | Description |
|
|
74
|
+
| -------------------- | ------- | ------------------------------------------------------------- |
|
|
75
|
+
| `username` | `root` | Telnet username, shared by all devices |
|
|
76
|
+
| `password` | - | Telnet password, shared by all devices (required) |
|
|
77
|
+
| `cooldownMinutes` | `30` | Minimum minutes between dispenses per device, `0` disables it |
|
|
78
|
+
| `devices[].name` | - | Name shown in Apple Home |
|
|
79
|
+
| `devices[].ip` | - | IP address of the feeder (use a DHCP reservation) |
|
|
80
|
+
| `devices[].portions` | `1` | Portions per dispense (1-10) |
|
|
81
|
+
|
|
82
|
+
Each device becomes one switch accessory, identified by its IP address. Changing the name keeps the accessory, while changing the IP creates a new one and removes the old one.
|
|
83
|
+
|
|
84
|
+
## Compatibility
|
|
85
|
+
|
|
86
|
+
This plugin was developed and tested **only on the Petlibro PLAF203**. Nothing else has been verified.
|
|
87
|
+
|
|
88
|
+
It may work on other feeders if both of these are true:
|
|
89
|
+
|
|
90
|
+
1. **Telnet access is available** with a login you know.
|
|
91
|
+
2. **The serial frame is the same.** The feeder's firmware must drive its motor controller via a Tuya MCU frame on `/dev/ttySAK1`, with the same bytes as the PLAF203.
|
|
92
|
+
|
|
93
|
+
Other Petlibro models or Tuya-based feeders often share parts of the design, but the port name, frame bytes, or whether telnet exists at all can differ.
|
|
94
|
+
|
|
95
|
+
### Verify manually
|
|
96
|
+
|
|
97
|
+
Before configuring the plugin for another model, telnet into the device and check:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
ls -l /dev/ttySAK1
|
|
101
|
+
echo -en "\x55\xaa\x03\x01\x00\x01\x01\x05" > /dev/ttySAK1
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If the feeder dispenses, the plugin should work. You can also try other values, for example `\x02` with checksum `\x06`, to see whether the data byte controls the portion count.
|
|
105
|
+
|
|
106
|
+
**Do not send arbitrary bytes to the serial port of a device you don't understand.** Frames that the controller does not expect could cause unexpected behaviour.
|
|
107
|
+
|
|
108
|
+
## Security notes
|
|
109
|
+
|
|
110
|
+
- Telnet is unencrypted. Use this plugin only on a trusted local network.
|
|
111
|
+
- The password is stored in plain text in Homebridge's `config.json`.
|
|
112
|
+
- The plugin is not affiliated with or endorsed by Petlibro or Tuya.
|
|
113
|
+
- Use at your own risk. Check that your pet is fed the right amount, since automation failures or wrong settings may under- or overfeed it.
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
corepack enable
|
|
119
|
+
yarn install
|
|
120
|
+
yarn build # compile TypeScript to dist/
|
|
121
|
+
yarn watch # compile on change
|
|
122
|
+
yarn lint # ESLint
|
|
123
|
+
yarn format # Prettier (write)
|
|
124
|
+
yarn check # format check + lint + build
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
To test without publishing, pack the plugin and install it into your Homebridge storage directory:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
yarn pack -o plugin.tgz
|
|
131
|
+
cd /path/to/homebridge && npm install ./plugin.tgz
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
Apache-2.0
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "PetlibroFeeder",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": { "type": "string", "default": "Petlibro Feeder" },
|
|
9
|
+
"username": {
|
|
10
|
+
"title": "Telnet username",
|
|
11
|
+
"type": "string",
|
|
12
|
+
"default": "root"
|
|
13
|
+
},
|
|
14
|
+
"password": {
|
|
15
|
+
"title": "Telnet password (same for all devices)",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"required": true,
|
|
18
|
+
"x-schema-form": { "type": "password" }
|
|
19
|
+
},
|
|
20
|
+
"cooldownMinutes": {
|
|
21
|
+
"title": "Minimum minutes between dispenses (per device, 0 = off)",
|
|
22
|
+
"type": "integer",
|
|
23
|
+
"default": 30,
|
|
24
|
+
"minimum": 0
|
|
25
|
+
},
|
|
26
|
+
"devices": {
|
|
27
|
+
"title": "Feeders",
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"name": { "title": "Name", "type": "string", "required": true },
|
|
33
|
+
"ip": { "title": "IP address", "type": "string", "required": true, "format": "ipv4" },
|
|
34
|
+
"portions": {
|
|
35
|
+
"title": "Portions per dispense",
|
|
36
|
+
"type": "integer",
|
|
37
|
+
"default": 1,
|
|
38
|
+
"minimum": 1,
|
|
39
|
+
"maximum": 10,
|
|
40
|
+
"required": true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { dispense } from './feeder.js';
|
|
2
|
+
export class FeederAccessory {
|
|
3
|
+
platform;
|
|
4
|
+
accessory;
|
|
5
|
+
device;
|
|
6
|
+
service;
|
|
7
|
+
busy = false;
|
|
8
|
+
lastDispense = 0;
|
|
9
|
+
constructor(platform, accessory, device) {
|
|
10
|
+
this.platform = platform;
|
|
11
|
+
this.accessory = accessory;
|
|
12
|
+
this.device = device;
|
|
13
|
+
const { Service, Characteristic } = platform.api.hap;
|
|
14
|
+
this.accessory
|
|
15
|
+
.getService(Service.AccessoryInformation)
|
|
16
|
+
.setCharacteristic(Characteristic.Manufacturer, 'Petlibro')
|
|
17
|
+
.setCharacteristic(Characteristic.Model, 'PLAF203')
|
|
18
|
+
.setCharacteristic(Characteristic.SerialNumber, device.ip);
|
|
19
|
+
this.service =
|
|
20
|
+
this.accessory.getService(Service.Switch) ?? this.accessory.addService(Service.Switch);
|
|
21
|
+
this.service.setCharacteristic(Characteristic.Name, device.name);
|
|
22
|
+
this.service
|
|
23
|
+
.getCharacteristic(Characteristic.On)
|
|
24
|
+
.onGet(() => false)
|
|
25
|
+
.onSet((v) => this.onSet(Boolean(v)));
|
|
26
|
+
}
|
|
27
|
+
reset() {
|
|
28
|
+
setTimeout(() => this.service.updateCharacteristic(this.platform.api.hap.Characteristic.On, false), 1000);
|
|
29
|
+
}
|
|
30
|
+
async onSet(on) {
|
|
31
|
+
if (!on)
|
|
32
|
+
return;
|
|
33
|
+
const { log, config } = this.platform;
|
|
34
|
+
const cooldownMs = (config.cooldownMinutes ?? 30) * 60_000;
|
|
35
|
+
if (this.busy) {
|
|
36
|
+
log.warn(`[${this.device.name}] dispense already in progress`);
|
|
37
|
+
return this.reset();
|
|
38
|
+
}
|
|
39
|
+
const since = Date.now() - this.lastDispense;
|
|
40
|
+
if (this.lastDispense && since < cooldownMs) {
|
|
41
|
+
log.warn(`[${this.device.name}] cooldown active, ${Math.ceil((cooldownMs - since) / 60_000)} min left`);
|
|
42
|
+
return this.reset();
|
|
43
|
+
}
|
|
44
|
+
this.busy = true;
|
|
45
|
+
try {
|
|
46
|
+
await dispense(this.device.ip, config.username ?? 'root', config.password, this.device.portions);
|
|
47
|
+
this.lastDispense = Date.now();
|
|
48
|
+
log.info(`[${this.device.name}] dispensed ${this.device.portions} portion(s)`);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
log.error(`[${this.device.name}] dispense failed: ${e.message}`);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
this.busy = false;
|
|
55
|
+
this.reset();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=accessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessory.js","sourceRoot":"","sources":["../src/accessory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,MAAM,OAAO,eAAe;IAMP;IACA;IACA;IAPF,OAAO,CAAU;IAC1B,IAAI,GAAG,KAAK,CAAC;IACb,YAAY,GAAG,CAAC,CAAC;IAEzB,YACmB,QAAwB,EACxB,SAA4B,EAC5B,MAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAc;QAErC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAErD,IAAI,CAAC,SAAS;aACX,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACzC,iBAAiB,CAAC,cAAc,CAAC,YAAY,EAAE,UAAU,CAAC;aAC1D,iBAAiB,CAAC,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC;aAClD,iBAAiB,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,OAAO;YACV,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAA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C,IAAI,sBAAsB,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAC9F,CAAC;YACF,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,QAAQ,CACZ,IAAI,CAAC,MAAM,CAAC,EAAE,EACd,MAAM,CAAC,QAAQ,IAAI,MAAM,EACzB,MAAM,CAAC,QAAQ,EACf,IAAI,CAAC,MAAM,CAAC,QAAQ,CACrB,CAAC;YACF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC/B,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,eAAe,IAAI,CAAC,MAAM,CAAC,QAAQ,aAAa,CAAC,CAAC;QACjF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,sBAAuB,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9E,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;YAClB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
package/dist/feeder.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { runTelnetCommand } from './telnet.js';
|
|
2
|
+
const SERIAL_DEV = '/dev/ttySAK1';
|
|
3
|
+
/** Tuya MCU frame: 55 AA | ver 03 | cmd 01 | len 00 01 | data=portions | checksum (sum mod 256) */
|
|
4
|
+
export function buildFrame(portions) {
|
|
5
|
+
const bytes = [0x55, 0xaa, 0x03, 0x01, 0x00, 0x01, portions & 0xff];
|
|
6
|
+
bytes.push(bytes.reduce((a, c) => a + c, 0) & 0xff);
|
|
7
|
+
return bytes;
|
|
8
|
+
}
|
|
9
|
+
export function buildShellCommand(portions) {
|
|
10
|
+
const esc = buildFrame(portions)
|
|
11
|
+
.map((b) => '\\x' + b.toString(16).padStart(2, '0'))
|
|
12
|
+
.join('');
|
|
13
|
+
return `echo -en "${esc}" > ${SERIAL_DEV}`;
|
|
14
|
+
}
|
|
15
|
+
export async function dispense(ip, username, password, portions) {
|
|
16
|
+
await runTelnetCommand({
|
|
17
|
+
host: ip,
|
|
18
|
+
username,
|
|
19
|
+
password,
|
|
20
|
+
command: buildShellCommand(portions),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=feeder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feeder.js","sourceRoot":"","sources":["../src/feeder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,UAAU,GAAG,cAAc,CAAC;AAElC,mGAAmG;AACnG,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;IACpE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC7B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SACnD,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,aAAa,GAAG,OAAO,UAAU,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,EAAU,EACV,QAAgB,EAChB,QAAgB,EAChB,QAAgB;IAEhB,MAAM,gBAAgB,CAAC;QACrB,IAAI,EAAE,EAAE;QACR,QAAQ;QACR,QAAQ;QACR,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC;KACrC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAe,CAAC,GAAQ,EAAQ,EAAE;IAChC,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AACtD,CAAC,CAAC"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FeederAccessory } from './accessory.js';
|
|
2
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
3
|
+
export class FeederPlatform {
|
|
4
|
+
log;
|
|
5
|
+
api;
|
|
6
|
+
config;
|
|
7
|
+
cached = new Map();
|
|
8
|
+
constructor(log, config, api) {
|
|
9
|
+
this.log = log;
|
|
10
|
+
this.api = api;
|
|
11
|
+
this.config = config;
|
|
12
|
+
api.on('didFinishLaunching', () => this.discover());
|
|
13
|
+
}
|
|
14
|
+
configureAccessory(accessory) {
|
|
15
|
+
this.cached.set(accessory.UUID, accessory);
|
|
16
|
+
}
|
|
17
|
+
discover() {
|
|
18
|
+
if (!this.config.password) {
|
|
19
|
+
this.log.error('No telnet password configured');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
for (const device of this.config.devices ?? []) {
|
|
24
|
+
if (!device.ip || !device.name) {
|
|
25
|
+
this.log.warn('Skipping device without name/ip');
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const uuid = this.api.hap.uuid.generate(`${PLUGIN_NAME}:${device.ip}`);
|
|
29
|
+
seen.add(uuid);
|
|
30
|
+
let accessory = this.cached.get(uuid);
|
|
31
|
+
if (accessory) {
|
|
32
|
+
accessory.displayName = device.name;
|
|
33
|
+
this.api.updatePlatformAccessories([accessory]);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
accessory = new this.api.platformAccessory(device.name, uuid);
|
|
37
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
38
|
+
}
|
|
39
|
+
new FeederAccessory(this, accessory, { ...device, portions: device.portions ?? 1 });
|
|
40
|
+
}
|
|
41
|
+
const stale = [...this.cached.values()].filter((a) => !seen.has(a.UUID));
|
|
42
|
+
if (stale.length)
|
|
43
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, stale);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,WAAW,EAA6B,MAAM,eAAe,CAAC;AAEtF,MAAM,OAAO,cAAc;IAKd;IAEA;IANF,MAAM,CAAuB;IACrB,MAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;IAE/D,YACW,GAAW,EACpB,MAAsB,EACb,GAAQ;QAFR,QAAG,GAAH,GAAG,CAAQ;QAEX,QAAG,GAAH,GAAG,CAAK;QAEjB,IAAI,CAAC,MAAM,GAAG,MAA8B,CAAC;QAC7C,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,IAA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,WAAW,EAAE,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAChF,CAAC;YACD,IAAI,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC,CAAC;QACtF,CAAC;QAED,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACzE,IAAI,KAAK,CAAC,MAAM;YAAE,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC,WAAW,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IAC9F,CAAC;CACF"}
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,4BAA4B,CAAC"}
|
package/dist/telnet.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
const IAC = 255, DONT = 254, DO = 253, WONT = 252, WILL = 251, SB = 250, SE = 240;
|
|
3
|
+
/** Logs in over telnet, runs one command, waits for the next prompt, exits. */
|
|
4
|
+
export function runTelnetCommand(opts) {
|
|
5
|
+
const { host, port = 23, username, password, command, timeoutMs = 10_000 } = opts;
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const socket = net.createConnection({ host, port });
|
|
8
|
+
let pending = Buffer.alloc(0);
|
|
9
|
+
let text = '';
|
|
10
|
+
let sentUser = false, sentPass = false, sentCmd = false, done = false;
|
|
11
|
+
const finish = (err) => {
|
|
12
|
+
if (done)
|
|
13
|
+
return;
|
|
14
|
+
done = true;
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
socket.destroy();
|
|
17
|
+
if (err)
|
|
18
|
+
reject(err);
|
|
19
|
+
else
|
|
20
|
+
resolve();
|
|
21
|
+
};
|
|
22
|
+
const timer = setTimeout(() => finish(new Error(`telnet timeout (${host})`)), timeoutMs);
|
|
23
|
+
const send = (line) => {
|
|
24
|
+
text = '';
|
|
25
|
+
socket.write(line + '\r\n');
|
|
26
|
+
};
|
|
27
|
+
const check = () => {
|
|
28
|
+
if (/login:\s*$/i.test(text)) {
|
|
29
|
+
if (sentUser)
|
|
30
|
+
return finish(new Error('telnet authentication failed'));
|
|
31
|
+
sentUser = true;
|
|
32
|
+
return send(username);
|
|
33
|
+
}
|
|
34
|
+
if (/password:\s*$/i.test(text)) {
|
|
35
|
+
if (sentPass)
|
|
36
|
+
return finish(new Error('telnet authentication failed'));
|
|
37
|
+
sentPass = true;
|
|
38
|
+
return send(password);
|
|
39
|
+
}
|
|
40
|
+
if (/[#$] ?$/.test(text)) {
|
|
41
|
+
if (!sentCmd) {
|
|
42
|
+
sentCmd = true;
|
|
43
|
+
return send(command);
|
|
44
|
+
}
|
|
45
|
+
socket.write('exit\r\n');
|
|
46
|
+
setTimeout(() => finish(), 100);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
socket.on('data', (chunk) => {
|
|
50
|
+
const data = typeof chunk === 'string' ? Buffer.from(chunk, 'latin1') : chunk;
|
|
51
|
+
const buf = Buffer.concat([pending, data]);
|
|
52
|
+
pending = Buffer.alloc(0);
|
|
53
|
+
let i = 0;
|
|
54
|
+
while (i < buf.length) {
|
|
55
|
+
const b = buf[i];
|
|
56
|
+
if (b !== IAC) {
|
|
57
|
+
text += String.fromCharCode(b);
|
|
58
|
+
i++;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (i + 1 >= buf.length) {
|
|
62
|
+
pending = buf.subarray(i);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const cmd = buf[i + 1];
|
|
66
|
+
if (cmd === DO || cmd === DONT || cmd === WILL || cmd === WONT) {
|
|
67
|
+
if (i + 2 >= buf.length) {
|
|
68
|
+
pending = buf.subarray(i);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const opt = buf[i + 2];
|
|
72
|
+
if (cmd === DO)
|
|
73
|
+
socket.write(Buffer.from([IAC, WONT, opt]));
|
|
74
|
+
else if (cmd === WILL)
|
|
75
|
+
socket.write(Buffer.from([IAC, DONT, opt]));
|
|
76
|
+
i += 3;
|
|
77
|
+
}
|
|
78
|
+
else if (cmd === SB) {
|
|
79
|
+
let j = i + 2;
|
|
80
|
+
while (j + 1 < buf.length && !(buf[j] === IAC && buf[j + 1] === SE))
|
|
81
|
+
j++;
|
|
82
|
+
if (j + 1 >= buf.length) {
|
|
83
|
+
pending = buf.subarray(i);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
i = j + 2;
|
|
87
|
+
}
|
|
88
|
+
else if (cmd === IAC) {
|
|
89
|
+
text += String.fromCharCode(IAC);
|
|
90
|
+
i += 2;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
i += 2;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
check();
|
|
97
|
+
});
|
|
98
|
+
socket.on('error', (e) => finish(e));
|
|
99
|
+
socket.on('close', () => {
|
|
100
|
+
if (!done)
|
|
101
|
+
finish(sentCmd ? undefined : new Error('telnet connection closed early'));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=telnet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telnet.js","sourceRoot":"","sources":["../src/telnet.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,MAAM,GAAG,GAAG,GAAG,EACb,IAAI,GAAG,GAAG,EACV,EAAE,GAAG,GAAG,EACR,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Name": "Petlibro Feeder (Telnet)",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"maintainers": [
|
|
6
|
+
"supaflyster"
|
|
7
|
+
],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://gitlab.com/supaflyster/homebridge-petlibro-feeder.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://gitlab.com/supaflyster/homebridge-petlibro-feeder/-/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://gitlab.com/supaflyster/homebridge-petlibro-feeder#readme",
|
|
16
|
+
"description": "Homebridge plugin that dispenses food on Petlibro PLAF203 feeders over local telnet.",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"packageManager": "yarn@4.19.0",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=26",
|
|
23
|
+
"homebridge": "^1.8.0 || ^2.0.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"homebridge-plugin",
|
|
27
|
+
"petlibro",
|
|
28
|
+
"cat-feeder"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"config.schema.json",
|
|
33
|
+
"LICENSE.txt",
|
|
34
|
+
"README.md",
|
|
35
|
+
"CHANGELOG.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc",
|
|
39
|
+
"watch": "tsc --watch",
|
|
40
|
+
"clean": "rm -rf dist",
|
|
41
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"lint:fix": "eslint . --fix",
|
|
44
|
+
"format": "prettier --write .",
|
|
45
|
+
"format:check": "prettier --check .",
|
|
46
|
+
"check": "yarn format:check && yarn lint && yarn build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^10.0.1",
|
|
50
|
+
"@types/node": "^26.6.11",
|
|
51
|
+
"eslint": "^10.16.0",
|
|
52
|
+
"eslint-config-prettier": "^10.1.9",
|
|
53
|
+
"homebridge": "^2.5.1",
|
|
54
|
+
"prettier": "^3.10.2",
|
|
55
|
+
"typescript": "^6.0.3",
|
|
56
|
+
"typescript-eslint": "^8.74.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"homebridge": "^1.8.0 || ^2.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|