kettle-x2p-cli 1.4.1__tar.gz → 1.4.2__tar.gz
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.
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/CHANGELOG.md +6 -0
- {kettle_x2p_cli-1.4.1/src/kettle_x2p_cli.egg-info → kettle_x2p_cli-1.4.2}/PKG-INFO +13 -30
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/README.md +12 -29
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/__init__.py +1 -1
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/cli.py +51 -9
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/miio.py +1 -1
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2/src/kettle_x2p_cli.egg-info}/PKG-INFO +13 -30
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/test_cli.py +70 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/LICENSE +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/MANIFEST.in +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/SPEC.md +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/pyproject.toml +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/setup.cfg +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/__main__.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/aes.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/config.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/style.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle/wizard.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle_x2p_cli.egg-info/SOURCES.txt +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle_x2p_cli.egg-info/dependency_links.txt +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle_x2p_cli.egg-info/entry_points.txt +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle_x2p_cli.egg-info/top_level.txt +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/helpers.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/test_aes.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/test_miio.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/test_style.py +0 -0
- {kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/tests/test_wizard.py +0 -0
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.4.2] - 2026-12-02
|
|
11
|
+
### Added
|
|
12
|
+
- When a command (`boil`, `warm`, `cancel`, `status`, `info`, `hello`) gets no reply from the kettle at its saved IP,
|
|
13
|
+
it asks `Run kettle find? [y/N]`. On `y` it searches the network for the kettle, saves the new IP and runs the
|
|
14
|
+
command again. Without a terminal it only prints the hint. Not asked when `--ip` is given.
|
|
15
|
+
|
|
10
16
|
## [1.4.1] - 2026-11-08
|
|
11
17
|
### Changed
|
|
12
18
|
- The Homebrew formula is renamed to `kettle-x2p-cli` (as on PyPI), because `kettle` is taken in homebrew-core:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kettle-x2p-cli
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.2
|
|
4
4
|
Summary: Local control of the Xiaomi Smart Kettle 2 Pro over your Wi-Fi, no cloud at runtime.
|
|
5
5
|
Author-email: Ilia Petrov-Komotskii <ilia@inkedkettle.art>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -25,17 +25,23 @@ Terminal: boil, heat to a temperature, keep warm for up to 24 hours, check the s
|
|
|
25
25
|
your own Wi-Fi, directly to the kettle - no Xiaomi Home app and no cloud connection when you use it.
|
|
26
26
|
|
|
27
27
|
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
brew install manefunction/tap/kettle-x2p-cli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
pip install kettle-x2p-cli
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
Written for the EU model (BHR9107EU, `xiaomi.kettle.v20`, 1.7 L, 1800 W), tested on firmware `2.2.7_0016`.
|
|
35
36
|
It has no dependencies except Python itself. This is the standalone tool and a documented protocol reference ([SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md))
|
|
36
37
|
made just for fun... or not. Setting a kettle right from the Terminal while working is pretty neat, actually :)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
```
|
|
40
|
+
$ kettle warm 80 --keep 2
|
|
41
|
+
warm to 80 C and keep warm at 80 C for 2 h: water at 41 C, idle, no fault (0).
|
|
42
|
+
Start heating? [y/N] y
|
|
43
|
+
status: water at 41 C, heating to 80 C, no fault (0).
|
|
44
|
+
```
|
|
39
45
|
|
|
40
46
|
## Features
|
|
41
47
|
|
|
@@ -79,8 +85,6 @@ reporting no fault, and a status read that fails or is unclear never starts anyt
|
|
|
79
85
|
to see exactly what they will send) (without a terminal, `--yes` is required). This model has no water-level reading, so a
|
|
80
86
|
low-water condition only shows up as a fault code. Heat water remotely only when you know the kettle has water in it.
|
|
81
87
|
|
|
82
|
-
---
|
|
83
|
-
|
|
84
88
|
## Installation
|
|
85
89
|
|
|
86
90
|
**kettle** is available from a variety of sources.
|
|
@@ -98,7 +102,7 @@ low-water condition only shows up as a fault code. Heat water remotely only when
|
|
|
98
102
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
99
103
|
2) **brew (Recommended for Mac and Linux users)**
|
|
100
104
|
- Type `brew tap manefunction/tap` in your Terminal to add my custom tap (app source) to your brew sources,
|
|
101
|
-
if you haven't already
|
|
105
|
+
if you haven't already, and trust it with `brew trust manefunction/tap`.
|
|
102
106
|
- Type `brew install kettle-x2p-cli` to install the application itself.
|
|
103
107
|
- Verify the installation with `kettle --version`.
|
|
104
108
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
@@ -120,8 +124,6 @@ Updates arrive with `pip install --upgrade kettle-x2p-cli` or `brew upgrade`. Yo
|
|
|
120
124
|
(`~/.config/kettle/`), so upgrading or reinstalling never loses them. (`pip` may ask you to use a virtual environment or `pipx` on newer
|
|
121
125
|
systems; `pipx install kettle-x2p-cli` is a good fit for a command line tool.)
|
|
122
126
|
|
|
123
|
-
---
|
|
124
|
-
|
|
125
127
|
## First-time setup
|
|
126
128
|
|
|
127
129
|
Run `kettle setup` and follow the instructions on the screen. It takes about five minutes the first time and is
|
|
@@ -150,8 +152,6 @@ setup mode stops working afterwards. I tried the alternatives (including the app
|
|
|
150
152
|
`kettle provision --app-params`); none gave a usable token without the cloud. After the one-time extraction,
|
|
151
153
|
all control is local. If you re-pair or reset the kettle, the token changes and you run `kettle setup` again.
|
|
152
154
|
|
|
153
|
-
---
|
|
154
|
-
|
|
155
155
|
## Usage
|
|
156
156
|
|
|
157
157
|
```bash
|
|
@@ -186,8 +186,6 @@ or `FORCE_COLOR=1` to keep them in a pipe.
|
|
|
186
186
|
- **"kettle fault: something wrong (N)"**: check the water level and that the kettle sits on its base. Fault codes are
|
|
187
187
|
not documented by Xiaomi; `no fault (0)` means none.
|
|
188
188
|
|
|
189
|
-
---
|
|
190
|
-
|
|
191
189
|
## How it works
|
|
192
190
|
|
|
193
191
|
The kettle speaks Xiaomi's *miio* protocol over UDP port 54321: a hello handshake that returns the device id and
|
|
@@ -195,21 +193,6 @@ a timestamp, then JSON-RPC calls encrypted with AES-128-CBC keyed from the token
|
|
|
195
193
|
a MIoT spec (service/property numbers); the ones used here are listed in [SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md). The client is a few hundred
|
|
196
194
|
lines of standard-library Python, including its own AES, and handles re-handshakes and timestamp drift by itself.
|
|
197
195
|
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Development
|
|
201
|
-
|
|
202
|
-
```bash
|
|
203
|
-
python3 -m venv .venv && .venv/bin/pip install -e .
|
|
204
|
-
.venv/bin/python -m unittest discover -s tests -v
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
The tests run against a fake kettle on the loopback interface that speaks the real wire format; nothing touches a
|
|
208
|
-
real device. The release workflow checks that the tag matches `src/kettle/__init__.py`, builds the package and
|
|
209
|
-
publishes it to PyPI and creates the GitHub release; the Homebrew formula is bumped automatically.
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
196
|
## Credits
|
|
214
197
|
|
|
215
198
|
- [python-miio](https://github.com/rytilahti/python-miio) for documenting the miio protocol.
|
|
@@ -5,17 +5,23 @@ Terminal: boil, heat to a temperature, keep warm for up to 24 hours, check the s
|
|
|
5
5
|
your own Wi-Fi, directly to the kettle - no Xiaomi Home app and no cloud connection when you use it.
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
brew install manefunction/tap/kettle-x2p-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pip install kettle-x2p-cli
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
Written for the EU model (BHR9107EU, `xiaomi.kettle.v20`, 1.7 L, 1800 W), tested on firmware `2.2.7_0016`.
|
|
15
16
|
It has no dependencies except Python itself. This is the standalone tool and a documented protocol reference ([SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md))
|
|
16
17
|
made just for fun... or not. Setting a kettle right from the Terminal while working is pretty neat, actually :)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
```
|
|
20
|
+
$ kettle warm 80 --keep 2
|
|
21
|
+
warm to 80 C and keep warm at 80 C for 2 h: water at 41 C, idle, no fault (0).
|
|
22
|
+
Start heating? [y/N] y
|
|
23
|
+
status: water at 41 C, heating to 80 C, no fault (0).
|
|
24
|
+
```
|
|
19
25
|
|
|
20
26
|
## Features
|
|
21
27
|
|
|
@@ -59,8 +65,6 @@ reporting no fault, and a status read that fails or is unclear never starts anyt
|
|
|
59
65
|
to see exactly what they will send) (without a terminal, `--yes` is required). This model has no water-level reading, so a
|
|
60
66
|
low-water condition only shows up as a fault code. Heat water remotely only when you know the kettle has water in it.
|
|
61
67
|
|
|
62
|
-
---
|
|
63
|
-
|
|
64
68
|
## Installation
|
|
65
69
|
|
|
66
70
|
**kettle** is available from a variety of sources.
|
|
@@ -78,7 +82,7 @@ low-water condition only shows up as a fault code. Heat water remotely only when
|
|
|
78
82
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
79
83
|
2) **brew (Recommended for Mac and Linux users)**
|
|
80
84
|
- Type `brew tap manefunction/tap` in your Terminal to add my custom tap (app source) to your brew sources,
|
|
81
|
-
if you haven't already
|
|
85
|
+
if you haven't already, and trust it with `brew trust manefunction/tap`.
|
|
82
86
|
- Type `brew install kettle-x2p-cli` to install the application itself.
|
|
83
87
|
- Verify the installation with `kettle --version`.
|
|
84
88
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
@@ -100,8 +104,6 @@ Updates arrive with `pip install --upgrade kettle-x2p-cli` or `brew upgrade`. Yo
|
|
|
100
104
|
(`~/.config/kettle/`), so upgrading or reinstalling never loses them. (`pip` may ask you to use a virtual environment or `pipx` on newer
|
|
101
105
|
systems; `pipx install kettle-x2p-cli` is a good fit for a command line tool.)
|
|
102
106
|
|
|
103
|
-
---
|
|
104
|
-
|
|
105
107
|
## First-time setup
|
|
106
108
|
|
|
107
109
|
Run `kettle setup` and follow the instructions on the screen. It takes about five minutes the first time and is
|
|
@@ -130,8 +132,6 @@ setup mode stops working afterwards. I tried the alternatives (including the app
|
|
|
130
132
|
`kettle provision --app-params`); none gave a usable token without the cloud. After the one-time extraction,
|
|
131
133
|
all control is local. If you re-pair or reset the kettle, the token changes and you run `kettle setup` again.
|
|
132
134
|
|
|
133
|
-
---
|
|
134
|
-
|
|
135
135
|
## Usage
|
|
136
136
|
|
|
137
137
|
```bash
|
|
@@ -166,8 +166,6 @@ or `FORCE_COLOR=1` to keep them in a pipe.
|
|
|
166
166
|
- **"kettle fault: something wrong (N)"**: check the water level and that the kettle sits on its base. Fault codes are
|
|
167
167
|
not documented by Xiaomi; `no fault (0)` means none.
|
|
168
168
|
|
|
169
|
-
---
|
|
170
|
-
|
|
171
169
|
## How it works
|
|
172
170
|
|
|
173
171
|
The kettle speaks Xiaomi's *miio* protocol over UDP port 54321: a hello handshake that returns the device id and
|
|
@@ -175,21 +173,6 @@ a timestamp, then JSON-RPC calls encrypted with AES-128-CBC keyed from the token
|
|
|
175
173
|
a MIoT spec (service/property numbers); the ones used here are listed in [SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md). The client is a few hundred
|
|
176
174
|
lines of standard-library Python, including its own AES, and handles re-handshakes and timestamp drift by itself.
|
|
177
175
|
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## Development
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
python3 -m venv .venv && .venv/bin/pip install -e .
|
|
184
|
-
.venv/bin/python -m unittest discover -s tests -v
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
The tests run against a fake kettle on the loopback interface that speaks the real wire format; nothing touches a
|
|
188
|
-
real device. The release workflow checks that the tag matches `src/kettle/__init__.py`, builds the package and
|
|
189
|
-
publishes it to PyPI and creates the GitHub release; the Homebrew formula is bumped automatically.
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
176
|
## Credits
|
|
194
177
|
|
|
195
178
|
- [python-miio](https://github.com/rytilahti/python-miio) for documenting the miio protocol.
|
|
@@ -10,7 +10,7 @@ import textwrap
|
|
|
10
10
|
import time
|
|
11
11
|
|
|
12
12
|
from . import config, style, version
|
|
13
|
-
from .miio import MiioClient, MiioError, MiioRpcError, discover, local_subnet
|
|
13
|
+
from .miio import MiioClient, MiioError, MiioRpcError, MiioTimeout, discover, local_subnet
|
|
14
14
|
from .style import code, coded, field, paint
|
|
15
15
|
|
|
16
16
|
EXPECTED_MODEL = "xiaomi.kettle.v20"
|
|
@@ -450,6 +450,39 @@ def run_command(args) -> None:
|
|
|
450
450
|
COMMANDS[args.cmd](args)
|
|
451
451
|
|
|
452
452
|
|
|
453
|
+
# commands that talk to the kettle at its saved IP; when it does not answer they offer `kettle find`
|
|
454
|
+
DEVICE_COMMANDS = ("hello", "info", "status", "boil", "warm", "cancel", "stop")
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def unreachable(e: BaseException) -> bool:
|
|
458
|
+
"""No reply at all (timeout, no route), as opposed to a reply we did not like."""
|
|
459
|
+
while e is not None:
|
|
460
|
+
if isinstance(e, MiioTimeout) or (isinstance(e, OSError) and not isinstance(e, MiioError)):
|
|
461
|
+
return True
|
|
462
|
+
e = e.__cause__
|
|
463
|
+
return False
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def offer_find(args, e: Exception) -> bool:
|
|
467
|
+
"""The kettle did not answer at its saved IP: offer to run `kettle find`. True if it was found again."""
|
|
468
|
+
cfg = config.load_config()
|
|
469
|
+
if args.cmd not in DEVICE_COMMANDS or args.ip or not cfg.get("ip") or not cfg.get("did") or not unreachable(e):
|
|
470
|
+
return False
|
|
471
|
+
if not sys.stdin.isatty():
|
|
472
|
+
print(code("If the kettle's IP changed, run `kettle find`."), file=sys.stderr)
|
|
473
|
+
return False
|
|
474
|
+
question = f"No kettle at {cfg['ip']}. Run `kettle find`?"
|
|
475
|
+
try:
|
|
476
|
+
answer = input(style.prompt(question, "bold", "yellow") + style.prompt(" [y/N] ", "dim"))
|
|
477
|
+
except (EOFError, KeyboardInterrupt):
|
|
478
|
+
print()
|
|
479
|
+
return False
|
|
480
|
+
if answer.strip().lower() != "y":
|
|
481
|
+
return False
|
|
482
|
+
cmd_find(argparse.Namespace(subnet=None))
|
|
483
|
+
return True
|
|
484
|
+
|
|
485
|
+
|
|
453
486
|
KEEP_HELP = (f"then keep warm at TEMP C ({TEMP_MIN}-{TEMP_MAX}) for TIME hours ({KEEP_MIN_LO // 60}-{KEEP_MIN_HI // 60}, "
|
|
454
487
|
f"e.g. 1.5 or 1:30); TEMP defaults to the heating target, TIME to {KEEP_MIN_LO // 60}. "
|
|
455
488
|
f"Without it the kettle stops after heating")
|
|
@@ -667,14 +700,23 @@ def main(argv=None):
|
|
|
667
700
|
if not config.load_config().get("token"):
|
|
668
701
|
print(f"\n{paint('First time here?', 'bold', 'yellow')} " + code("Run `kettle setup`."))
|
|
669
702
|
return
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
703
|
+
for retry in (False, True): # once more after `kettle find` found the kettle at a new IP
|
|
704
|
+
try:
|
|
705
|
+
run_command(args)
|
|
706
|
+
return
|
|
707
|
+
except KettleError as e:
|
|
708
|
+
print(style.error(e), file=sys.stderr)
|
|
709
|
+
sys.exit(e.code)
|
|
710
|
+
except (MiioError, OSError) as e:
|
|
711
|
+
print(style.error(e), file=sys.stderr)
|
|
712
|
+
if retry:
|
|
713
|
+
sys.exit(1)
|
|
714
|
+
try:
|
|
715
|
+
if not offer_find(args, e):
|
|
716
|
+
sys.exit(1)
|
|
717
|
+
except KettleError as find_error:
|
|
718
|
+
print(style.error(find_error), file=sys.stderr)
|
|
719
|
+
sys.exit(find_error.code)
|
|
678
720
|
|
|
679
721
|
|
|
680
722
|
if __name__ == "__main__":
|
|
@@ -170,7 +170,7 @@ class MiioClient:
|
|
|
170
170
|
except (MiioError, ValueError, OSError) as e: # timeout, bad checksum, stale stamp, no route...
|
|
171
171
|
last = e
|
|
172
172
|
self.did = None
|
|
173
|
-
raise MiioError(f"{method} failed after {self.retries} attempts: {last}")
|
|
173
|
+
raise MiioError(f"{method} failed after {self.retries} attempts: {last}") from last
|
|
174
174
|
|
|
175
175
|
# --- MIoT helpers -------------------------------------------------
|
|
176
176
|
def get_properties(self, props: list[tuple[int, int]]) -> list[dict]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kettle-x2p-cli
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.2
|
|
4
4
|
Summary: Local control of the Xiaomi Smart Kettle 2 Pro over your Wi-Fi, no cloud at runtime.
|
|
5
5
|
Author-email: Ilia Petrov-Komotskii <ilia@inkedkettle.art>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -25,17 +25,23 @@ Terminal: boil, heat to a temperature, keep warm for up to 24 hours, check the s
|
|
|
25
25
|
your own Wi-Fi, directly to the kettle - no Xiaomi Home app and no cloud connection when you use it.
|
|
26
26
|
|
|
27
27
|
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
brew install manefunction/tap/kettle-x2p-cli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
pip install kettle-x2p-cli
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
Written for the EU model (BHR9107EU, `xiaomi.kettle.v20`, 1.7 L, 1800 W), tested on firmware `2.2.7_0016`.
|
|
35
36
|
It has no dependencies except Python itself. This is the standalone tool and a documented protocol reference ([SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md))
|
|
36
37
|
made just for fun... or not. Setting a kettle right from the Terminal while working is pretty neat, actually :)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
```
|
|
40
|
+
$ kettle warm 80 --keep 2
|
|
41
|
+
warm to 80 C and keep warm at 80 C for 2 h: water at 41 C, idle, no fault (0).
|
|
42
|
+
Start heating? [y/N] y
|
|
43
|
+
status: water at 41 C, heating to 80 C, no fault (0).
|
|
44
|
+
```
|
|
39
45
|
|
|
40
46
|
## Features
|
|
41
47
|
|
|
@@ -79,8 +85,6 @@ reporting no fault, and a status read that fails or is unclear never starts anyt
|
|
|
79
85
|
to see exactly what they will send) (without a terminal, `--yes` is required). This model has no water-level reading, so a
|
|
80
86
|
low-water condition only shows up as a fault code. Heat water remotely only when you know the kettle has water in it.
|
|
81
87
|
|
|
82
|
-
---
|
|
83
|
-
|
|
84
88
|
## Installation
|
|
85
89
|
|
|
86
90
|
**kettle** is available from a variety of sources.
|
|
@@ -98,7 +102,7 @@ low-water condition only shows up as a fault code. Heat water remotely only when
|
|
|
98
102
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
99
103
|
2) **brew (Recommended for Mac and Linux users)**
|
|
100
104
|
- Type `brew tap manefunction/tap` in your Terminal to add my custom tap (app source) to your brew sources,
|
|
101
|
-
if you haven't already
|
|
105
|
+
if you haven't already, and trust it with `brew trust manefunction/tap`.
|
|
102
106
|
- Type `brew install kettle-x2p-cli` to install the application itself.
|
|
103
107
|
- Verify the installation with `kettle --version`.
|
|
104
108
|
- You are perfect, you can use the app with `kettle` from any folder in your system.
|
|
@@ -120,8 +124,6 @@ Updates arrive with `pip install --upgrade kettle-x2p-cli` or `brew upgrade`. Yo
|
|
|
120
124
|
(`~/.config/kettle/`), so upgrading or reinstalling never loses them. (`pip` may ask you to use a virtual environment or `pipx` on newer
|
|
121
125
|
systems; `pipx install kettle-x2p-cli` is a good fit for a command line tool.)
|
|
122
126
|
|
|
123
|
-
---
|
|
124
|
-
|
|
125
127
|
## First-time setup
|
|
126
128
|
|
|
127
129
|
Run `kettle setup` and follow the instructions on the screen. It takes about five minutes the first time and is
|
|
@@ -150,8 +152,6 @@ setup mode stops working afterwards. I tried the alternatives (including the app
|
|
|
150
152
|
`kettle provision --app-params`); none gave a usable token without the cloud. After the one-time extraction,
|
|
151
153
|
all control is local. If you re-pair or reset the kettle, the token changes and you run `kettle setup` again.
|
|
152
154
|
|
|
153
|
-
---
|
|
154
|
-
|
|
155
155
|
## Usage
|
|
156
156
|
|
|
157
157
|
```bash
|
|
@@ -186,8 +186,6 @@ or `FORCE_COLOR=1` to keep them in a pipe.
|
|
|
186
186
|
- **"kettle fault: something wrong (N)"**: check the water level and that the kettle sits on its base. Fault codes are
|
|
187
187
|
not documented by Xiaomi; `no fault (0)` means none.
|
|
188
188
|
|
|
189
|
-
---
|
|
190
|
-
|
|
191
189
|
## How it works
|
|
192
190
|
|
|
193
191
|
The kettle speaks Xiaomi's *miio* protocol over UDP port 54321: a hello handshake that returns the device id and
|
|
@@ -195,21 +193,6 @@ a timestamp, then JSON-RPC calls encrypted with AES-128-CBC keyed from the token
|
|
|
195
193
|
a MIoT spec (service/property numbers); the ones used here are listed in [SPEC.md](https://github.com/ManeFunction/kettle-x2p-cli/blob/main/SPEC.md). The client is a few hundred
|
|
196
194
|
lines of standard-library Python, including its own AES, and handles re-handshakes and timestamp drift by itself.
|
|
197
195
|
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Development
|
|
201
|
-
|
|
202
|
-
```bash
|
|
203
|
-
python3 -m venv .venv && .venv/bin/pip install -e .
|
|
204
|
-
.venv/bin/python -m unittest discover -s tests -v
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
The tests run against a fake kettle on the loopback interface that speaks the real wire format; nothing touches a
|
|
208
|
-
real device. The release workflow checks that the tag matches `src/kettle/__init__.py`, builds the package and
|
|
209
|
-
publishes it to PyPI and creates the GitHub release; the Homebrew formula is bumped automatically.
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
196
|
## Credits
|
|
214
197
|
|
|
215
198
|
- [python-miio](https://github.com/rytilahti/python-miio) for documenting the miio protocol.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import io
|
|
1
3
|
import json
|
|
4
|
+
import socket
|
|
2
5
|
import unittest
|
|
3
6
|
from unittest import mock
|
|
4
7
|
|
|
@@ -333,5 +336,72 @@ class FindTests(DeviceCase):
|
|
|
333
336
|
self.assertEqual(config.load_config()["ip"], "127.0.0.1")
|
|
334
337
|
|
|
335
338
|
|
|
339
|
+
class FindPromptTests(DeviceCase):
|
|
340
|
+
"""A command that gets no reply at the saved IP offers `kettle find`, then tries again at the new IP."""
|
|
341
|
+
|
|
342
|
+
def setUp(self):
|
|
343
|
+
super().setUp()
|
|
344
|
+
config.save_config({"ip": "10.0.0.9", "token": TOKEN.hex(), "did": DID, "model": "xiaomi.kettle.v20"})
|
|
345
|
+
real_init = cli.MiioClient.__init__
|
|
346
|
+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as probe:
|
|
347
|
+
probe.bind(("127.0.0.1", 0))
|
|
348
|
+
closed_port = probe.getsockname()[1]
|
|
349
|
+
|
|
350
|
+
def init(client, ip, token=None, timeout=3.0, retries=3, port=None, debug=False):
|
|
351
|
+
real_init(client, ip, token, 0.2, 1, debug=debug)
|
|
352
|
+
if ip != "127.0.0.1": # the old IP: nobody answers there (kept off the real network)
|
|
353
|
+
client.ip, client.port = "127.0.0.1", closed_port
|
|
354
|
+
|
|
355
|
+
real_discover = cli.discover
|
|
356
|
+
for patcher in (mock.patch.object(cli.MiioClient, "__init__", init),
|
|
357
|
+
mock.patch.object(cli, "discover",
|
|
358
|
+
lambda base: real_discover("127.0.0", wait=0.5, port=self.dev.port)),
|
|
359
|
+
mock.patch.object(cli.sys.stdin, "isatty", return_value=True)):
|
|
360
|
+
patcher.start()
|
|
361
|
+
self.addCleanup(patcher.stop)
|
|
362
|
+
|
|
363
|
+
def run_saved(self, *argv, answer="y"):
|
|
364
|
+
out, err = io.StringIO(), io.StringIO()
|
|
365
|
+
prompts = []
|
|
366
|
+
|
|
367
|
+
def fake_input(prompt=""):
|
|
368
|
+
prompts.append(prompt)
|
|
369
|
+
return answer
|
|
370
|
+
|
|
371
|
+
code = 0
|
|
372
|
+
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err), \
|
|
373
|
+
mock.patch("builtins.input", fake_input):
|
|
374
|
+
try:
|
|
375
|
+
cli.main(list(argv))
|
|
376
|
+
except SystemExit as e:
|
|
377
|
+
code = e.code if isinstance(e.code, int) else 1
|
|
378
|
+
return code, out.getvalue(), err.getvalue(), prompts
|
|
379
|
+
|
|
380
|
+
def test_yes_finds_the_kettle_and_runs_the_command(self):
|
|
381
|
+
code, out, err, prompts = self.run_saved("boil", "--yes")
|
|
382
|
+
self.assertEqual(code, 0, err)
|
|
383
|
+
self.assertEqual(len(prompts), 1)
|
|
384
|
+
self.assertIn("Run `kettle find`?", prompts[0])
|
|
385
|
+
self.assertIn("[y/N]", prompts[0])
|
|
386
|
+
self.assertEqual(config.load_config()["ip"], "127.0.0.1")
|
|
387
|
+
self.assertEqual(len(self.dev.writes), 1)
|
|
388
|
+
|
|
389
|
+
def test_no_leaves_the_config_alone(self):
|
|
390
|
+
code, _, _, prompts = self.run_saved("status", answer="")
|
|
391
|
+
self.assertEqual(code, 1)
|
|
392
|
+
self.assertEqual(len(prompts), 1)
|
|
393
|
+
self.assertEqual(config.load_config()["ip"], "10.0.0.9")
|
|
394
|
+
|
|
395
|
+
def test_without_a_terminal_it_only_hints(self):
|
|
396
|
+
with mock.patch.object(cli.sys.stdin, "isatty", return_value=False):
|
|
397
|
+
code, _, err, prompts = self.run_saved("warm", "70", "--yes")
|
|
398
|
+
self.assertEqual((code, prompts), (1, []))
|
|
399
|
+
self.assertIn("kettle find", err)
|
|
400
|
+
|
|
401
|
+
def test_not_offered_for_an_ip_given_on_the_command_line(self):
|
|
402
|
+
code, _, _, prompts = self.run_saved("--ip", "10.0.0.9", "status")
|
|
403
|
+
self.assertEqual((code, prompts), (1, []))
|
|
404
|
+
|
|
405
|
+
|
|
336
406
|
if __name__ == "__main__":
|
|
337
407
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kettle_x2p_cli-1.4.1 → kettle_x2p_cli-1.4.2}/src/kettle_x2p_cli.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|