pyscinan 0.1.0__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.
- pyscinan-0.1.0/.gitignore +10 -0
- pyscinan-0.1.0/CHANGELOG.md +12 -0
- pyscinan-0.1.0/LICENSE +21 -0
- pyscinan-0.1.0/PKG-INFO +118 -0
- pyscinan-0.1.0/PROTOCOL.md +134 -0
- pyscinan-0.1.0/README.md +93 -0
- pyscinan-0.1.0/pyproject.toml +56 -0
- pyscinan-0.1.0/src/pyscinan/__init__.py +32 -0
- pyscinan-0.1.0/src/pyscinan/__main__.py +5 -0
- pyscinan-0.1.0/src/pyscinan/cli.py +115 -0
- pyscinan-0.1.0/src/pyscinan/cloud.py +271 -0
- pyscinan-0.1.0/src/pyscinan/const.py +60 -0
- pyscinan-0.1.0/src/pyscinan/exceptions.py +29 -0
- pyscinan-0.1.0/src/pyscinan/local.py +417 -0
- pyscinan-0.1.0/src/pyscinan/models.py +158 -0
- pyscinan-0.1.0/src/pyscinan/protocol.py +64 -0
- pyscinan-0.1.0/src/pyscinan/py.typed +0 -0
- pyscinan-0.1.0/tests/__init__.py +0 -0
- pyscinan-0.1.0/tests/conftest.py +11 -0
- pyscinan-0.1.0/tests/fake_cloud.py +128 -0
- pyscinan-0.1.0/tests/fake_thermostat.py +113 -0
- pyscinan-0.1.0/tests/test_cloud.py +228 -0
- pyscinan-0.1.0/tests/test_local.py +138 -0
- pyscinan-0.1.0/tests/test_protocol.py +92 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-23)
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- Local client (`ScinanLocalClient`): TCP port 2000, hello/device ID detection, status push listeners,
|
|
8
|
+
heartbeat, idle timeout and automatic reconnect, commands for temperature, away, power, program and mode.
|
|
9
|
+
- Cloud client (`ScinanCloudClient`): Saswell v2.0 API login, device list, device status and control,
|
|
10
|
+
with token refresh and one retry on connection errors.
|
|
11
|
+
- Shared `ScinanDevice` / `ScinanStatus` models.
|
|
12
|
+
- `pyscinan` command line tool.
|
pyscinan-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kris Skarbo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pyscinan-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyscinan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async client for Saswell / Scinan Wi-Fi thermostats (local TCP and cloud API)
|
|
5
|
+
Project-URL: Homepage, https://github.com/skarbo/pyscinan
|
|
6
|
+
Project-URL: Issues, https://github.com/skarbo/pyscinan/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/skarbo/pyscinan/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Kris Skarbo
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: asyncio,home-assistant,saswell,scinan,thermostat
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Home Automation
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Requires-Dist: aiohttp>=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# pyscinan
|
|
27
|
+
|
|
28
|
+
Async Python library for Saswell (Scinan platform) Wi-Fi thermostats.
|
|
29
|
+
|
|
30
|
+
- **Local**: talks directly to the thermostat over your network (TCP port 2000). No cloud, instant push
|
|
31
|
+
updates, heartbeat and automatic reconnect.
|
|
32
|
+
- **Cloud**: the Saswell v2.0 API used by the Saswell "Thermostat" app.
|
|
33
|
+
|
|
34
|
+
Both clients fill the same `ScinanDevice` model. Used by the
|
|
35
|
+
[Scinan Saswell Thermostat](https://github.com/skarbo/hass-scinan-thermostat) Home Assistant integration.
|
|
36
|
+
|
|
37
|
+
Tested with the Saswell SAS920FHL-7W-WIFI (electric floor heating). Other thermostats using a Saswell
|
|
38
|
+
Thermostat app (for example SAS922WHL-7W-S-WIFI and Prosmart PST50W) are known to work with the cloud API.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install pyscinan
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Requires Python 3.12 or newer.
|
|
47
|
+
|
|
48
|
+
## Local
|
|
49
|
+
|
|
50
|
+
The thermostat must already be on your Wi-Fi (set it up with the Thermostat app). Give it a fixed IP address;
|
|
51
|
+
it can't be discovered automatically.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
from pyscinan import DeviceMode, ScinanLocalClient
|
|
56
|
+
|
|
57
|
+
async def main():
|
|
58
|
+
async with ScinanLocalClient("192.168.1.50") as client:
|
|
59
|
+
dev = client.device
|
|
60
|
+
print(dev.device_id, dev.current_temperature, dev.target_temperature, dev.mode)
|
|
61
|
+
|
|
62
|
+
client.add_listener(lambda: print("update:", dev.current_temperature, dev.target_temperature))
|
|
63
|
+
|
|
64
|
+
await client.set_temperature(21.5)
|
|
65
|
+
await client.set_mode(DeviceMode.COMFORT)
|
|
66
|
+
await client.set_away(True) # "off" on floor heating thermostats
|
|
67
|
+
await asyncio.sleep(60) # pushes arrive every 15 s and on every change
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Every command returns the status the thermostat answers with. A command the thermostat ignores (for example
|
|
73
|
+
power on the SAS920FHL) returns the unchanged status, so compare it with what you asked for.
|
|
74
|
+
|
|
75
|
+
## Cloud
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from pyscinan import ScinanCloudClient
|
|
79
|
+
|
|
80
|
+
async with ScinanCloudClient("email@example.com", "password") as cloud:
|
|
81
|
+
devices = await cloud.update_devices()
|
|
82
|
+
for dev in devices.values():
|
|
83
|
+
print(dev.device_id, dev.name, dev.online, dev.target_temperature)
|
|
84
|
+
await cloud.set_temperature(dev.device_id, 21.5)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Pass `session=` to reuse an `aiohttp.ClientSession`. Note that the Saswell cloud only supports plain HTTP.
|
|
88
|
+
|
|
89
|
+
## Command line
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pyscinan status 192.168.1.50
|
|
93
|
+
pyscinan listen 192.168.1.50 --seconds 60
|
|
94
|
+
pyscinan settemp 192.168.1.50 21.5
|
|
95
|
+
pyscinan away 192.168.1.50 on
|
|
96
|
+
pyscinan mode 192.168.1.50 1 # 0 Comfort, 1 Auto (schedule), 2 Day or night
|
|
97
|
+
pyscinan cloud-list email@example.com # password from $SCINAN_PASSWORD or a prompt
|
|
98
|
+
pyscinan --help
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Protocol
|
|
102
|
+
|
|
103
|
+
See [PROTOCOL.md](PROTOCOL.md) for everything known about the local protocol and the cloud API.
|
|
104
|
+
|
|
105
|
+
## Development
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
uv sync
|
|
109
|
+
uv run pytest
|
|
110
|
+
uv run ruff check .
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The tests use a fake thermostat (TCP) and a fake cloud server, so no hardware or account is needed.
|
|
114
|
+
`scripts/hw_settings_test.py` runs against a real thermostat and changes its settings (then restores them).
|
|
115
|
+
|
|
116
|
+
## Disclaimer
|
|
117
|
+
|
|
118
|
+
Not affiliated with Saswell or Scinan. Use at your own risk.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Scinan / Saswell thermostat protocol
|
|
2
|
+
|
|
3
|
+
What `pyscinan` knows about the protocols, from testing on SAS920FHL (device type 9) thermostats and from
|
|
4
|
+
watching how the official Saswell "Thermostat" app talks to them. Nothing here is official documentation.
|
|
5
|
+
|
|
6
|
+
✅ = confirmed on hardware, ⚠️ = behaves differently than expected, ❓ = seen in the app, not tested.
|
|
7
|
+
|
|
8
|
+
## Local protocol (TCP port 2000)
|
|
9
|
+
|
|
10
|
+
Plain ASCII lines, CRLF terminated. **No encryption, no authentication**: anyone on the network who can reach
|
|
11
|
+
port 2000 can control the thermostat.
|
|
12
|
+
|
|
13
|
+
/<DEVICE_ID>/<CODE>/<SENSOR_TYPE>/<DATA>
|
|
14
|
+
|
|
15
|
+
- `DEVICE_ID`: 16 characters, the same ID the cloud uses (thermostats start with `1038`).
|
|
16
|
+
- `CODE`: `S` + 2 hex digits (`S00`, `S02`, `S12` ...), `SPOLL`, or `type` (hello only).
|
|
17
|
+
- `SENSOR_TYPE`: always `1`.
|
|
18
|
+
|
|
19
|
+
### Connection
|
|
20
|
+
|
|
21
|
+
- On connect the device sends a hello, `/<id>/type/1/<device type>`, ending with `\n` only, followed right
|
|
22
|
+
away by an `S00` status.
|
|
23
|
+
- Heartbeat: send `/<id>/SPOLL/1/1`, the device answers `/<id>/SPOLL/1/OK`. The app sends it every ~8 s.
|
|
24
|
+
`pyscinan` sends it every 8 s and treats 30 s without any data as a dead connection.
|
|
25
|
+
- The device **pushes `S00` every 15 s** by itself, and **immediately when a value changes** (also changes made
|
|
26
|
+
on the thermostat or in the phone app).
|
|
27
|
+
- Every accepted command is answered with a full `S00` status (~0.1 s). An ignored command gets **no reply**.
|
|
28
|
+
- **Several TCP clients can be connected at once.** Replies are sent to all of them. The phone app (cloud)
|
|
29
|
+
keeps working while local clients are connected.
|
|
30
|
+
- The physical on/off button cuts power to the Wi-Fi module too. The device just goes silent (no TCP close),
|
|
31
|
+
comes back ~25 s after power-on with a new hello, and keeps its settings.
|
|
32
|
+
|
|
33
|
+
### Commands
|
|
34
|
+
|
|
35
|
+
| Code | Data | Meaning | Type 9 |
|
|
36
|
+
|---|---|---|---|
|
|
37
|
+
| `S00` | `-1` | Request full status | ✅ |
|
|
38
|
+
| `S01` | `1`/`0` | Power on/off | ⚠️ ignored (no reply, display unchanged). Use away as "off". |
|
|
39
|
+
| `S02` | `21.5` | Target temperature, 0.5 steps, formatted `%04.1f` (`05.0`). **Also cancels away.** | ✅ |
|
|
40
|
+
| `S03` | `1`/`0` | Away (frost protection). While away the status shows target `05.0`. Away off restores the previous target. | ✅ |
|
|
41
|
+
| `S07` | `1`/`0` | Program (schedule) on/off | ⚠️ ignored; use `S12 1` |
|
|
42
|
+
| `S12` | `0`/`1`/`2` | System mode, see below | ✅ |
|
|
43
|
+
| `S05`, `S06`, `S08`, `S11`, `S13` | | Model-specific settings and schedule data | ❓ |
|
|
44
|
+
| `S1A`, `S1B`, `S1C`, `S2A` | | Installer parameters (calibration, limits). Don't touch. | ❓ |
|
|
45
|
+
| `S99` | `<ssid>,<password>!` | Wi-Fi provisioning, **only in AP mode** (ignored in station mode) | ❓ |
|
|
46
|
+
|
|
47
|
+
`S12` system modes on type 9:
|
|
48
|
+
|
|
49
|
+
| Value | Name | Effect |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| 0 | Comfort (manual) | holds the target set with `S02` |
|
|
52
|
+
| 1 | Auto (schedule) | `program=1`, target follows the built-in schedule |
|
|
53
|
+
| 2 | Day or night | target unchanged; exact meaning unknown |
|
|
54
|
+
| 3+ | | ignored |
|
|
55
|
+
|
|
56
|
+
### Status (`S00`) payload
|
|
57
|
+
|
|
58
|
+
power,cur_temp,target_temp,unit,away,program,fan_mode,run_mode,system_mode[,min,max,sys_mode_type]
|
|
59
|
+
|
|
60
|
+
Example (type 9): `1,21.5,21.5,0,0,0,0,0,0,05,35`
|
|
61
|
+
|
|
62
|
+
| Idx | Field | Notes |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| 0 | power | 1/0 |
|
|
65
|
+
| 1 | current temperature | °C |
|
|
66
|
+
| 2 | target temperature | `05.0` while away |
|
|
67
|
+
| 3 | unit | 0 = °C |
|
|
68
|
+
| 4 | away | 1/0 |
|
|
69
|
+
| 5 | program | schedule active |
|
|
70
|
+
| 6 | fan_mode | |
|
|
71
|
+
| 7 | run_mode | **not** a heating flag on type 9 |
|
|
72
|
+
| 8 | system_mode | same value as `S12` |
|
|
73
|
+
| 9, 10 | min / max target | `05`, `35` |
|
|
74
|
+
| 11 | system_mode_type | not sent by type 9 |
|
|
75
|
+
|
|
76
|
+
**No field reports whether the thermostat is heating** (the display shows a heating icon, the status doesn't).
|
|
77
|
+
`ScinanDevice.is_heating` estimates it as `on and not away and current < target`.
|
|
78
|
+
|
|
79
|
+
### Discovery
|
|
80
|
+
|
|
81
|
+
Not supported. The SDK in the app has a UDP mode (port 4000, broadcast and group `224.5.0.7`), but the
|
|
82
|
+
thermostats tested didn't answer it, nor the Hi-Flying `48899` probe, even from the same subnet. Use the IP
|
|
83
|
+
address (give the thermostat a DHCP reservation).
|
|
84
|
+
|
|
85
|
+
### Wi-Fi provisioning (AP mode)
|
|
86
|
+
|
|
87
|
+
How the app sets up Wi-Fi (not implemented in `pyscinan`):
|
|
88
|
+
|
|
89
|
+
1. Put the thermostat in AP mode (button sequence on the thermostat) and join its Wi-Fi.
|
|
90
|
+
2. TCP `10.10.100.254:2000`, send `/SCINANIOT/DEVICE_REQUEST`, read the device ID from the reply.
|
|
91
|
+
3. Send `/<id>/S99/1/<ssid>,<password>!` and expect `/S99/1/OK`. SSIDs or passwords containing `,` or `!`
|
|
92
|
+
probably break this format.
|
|
93
|
+
4. The app then binds the device to the account in the cloud (`device/add`), which only works for a few
|
|
94
|
+
minutes after provisioning.
|
|
95
|
+
|
|
96
|
+
In station mode only port 2000 is open, and `S99` and `DEVICE_REQUEST` are ignored, so Wi-Fi can only be
|
|
97
|
+
changed in AP mode. The device ID doesn't change with the Wi-Fi.
|
|
98
|
+
|
|
99
|
+
## Cloud API (Saswell v2.0)
|
|
100
|
+
|
|
101
|
+
- Base URL `http://api.saswell.com.cn/v2.0/`. **Plain HTTP only** (HTTPS doesn't answer): the MD5 password hash
|
|
102
|
+
and the token are sent unencrypted.
|
|
103
|
+
- The old Scinan v1.0 API (`api.scinan.com`) no longer works.
|
|
104
|
+
- Every request is a POST with query parameters `app_key`, `company_id` (`1038` for thermostats), `imei`,
|
|
105
|
+
`timestamp`, `token` (after login) and `sign` = uppercase MD5 of `secret + k1v1k2v2... (keys sorted) + secret`.
|
|
106
|
+
The app key, IMEI and secret are the app's own (see `cloud.py`).
|
|
107
|
+
- Replies: `{"result_code": "0", "result_message": "...", "result_data": ...}`.
|
|
108
|
+
|
|
109
|
+
| Endpoint | Parameters | Notes |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `user/login` | `account`, `password` (MD5 hex) | → `access_token` |
|
|
112
|
+
| `device/list` | | groups `{type, devices: [...]}`; each device has `id`, `title`, `company_id`, `online`, `s00` |
|
|
113
|
+
| `device/status` | `device_id` | `{online, s00, ...}` |
|
|
114
|
+
| `sensor/control` | `device_id`, `sensor_id` (code without `S`, e.g. `02`), `sensor_type=1`, `control_data={"value": "21.5"}` | |
|
|
115
|
+
|
|
116
|
+
The cloud `s00` has one extra leading field, a timestamp in ms, so every index shifts by one.
|
|
117
|
+
|
|
118
|
+
Cloud commands behave exactly like local ones: `sensor/control` answers OK in ~0.3 s and the new status shows
|
|
119
|
+
in `device/list` ~2 s later. An ignored command (like `S01` on type 9) still gets OK, so compare the new
|
|
120
|
+
status with what you asked for.
|
|
121
|
+
|
|
122
|
+
Error codes: `20007` wrong password, `20014` user doesn't exist, `1` blocked after 5 wrong passwords,
|
|
123
|
+
`10002`/`10003` token missing/expired, `20001` device doesn't exist (for this account), `20002` device already
|
|
124
|
+
added, `20003` device authentication error.
|
|
125
|
+
|
|
126
|
+
### Live push (MQTT, not implemented)
|
|
127
|
+
|
|
128
|
+
The app gets live updates from an MQTT broker at `tcp://push.saswell.com.cn:1886` (plain TCP):
|
|
129
|
+
|
|
130
|
+
- MQTT 3.1 only (`MQIsdp`), username = account email, password = the **plain** password, a short alphanumeric
|
|
131
|
+
client ID. No subscribe is needed.
|
|
132
|
+
- The server publishes (QoS 1) every status of the account's devices. The status is in the **topic**, the
|
|
133
|
+
body is empty: `/<device id>/S00/1/1,24.5,25.0,0,0,0,0,0,0,05,35`.
|
|
134
|
+
- The broker seems to block clients that connect too often or with wrong credentials. Reconnect slowly.
|
pyscinan-0.1.0/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# pyscinan
|
|
2
|
+
|
|
3
|
+
Async Python library for Saswell (Scinan platform) Wi-Fi thermostats.
|
|
4
|
+
|
|
5
|
+
- **Local**: talks directly to the thermostat over your network (TCP port 2000). No cloud, instant push
|
|
6
|
+
updates, heartbeat and automatic reconnect.
|
|
7
|
+
- **Cloud**: the Saswell v2.0 API used by the Saswell "Thermostat" app.
|
|
8
|
+
|
|
9
|
+
Both clients fill the same `ScinanDevice` model. Used by the
|
|
10
|
+
[Scinan Saswell Thermostat](https://github.com/skarbo/hass-scinan-thermostat) Home Assistant integration.
|
|
11
|
+
|
|
12
|
+
Tested with the Saswell SAS920FHL-7W-WIFI (electric floor heating). Other thermostats using a Saswell
|
|
13
|
+
Thermostat app (for example SAS922WHL-7W-S-WIFI and Prosmart PST50W) are known to work with the cloud API.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install pyscinan
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Python 3.12 or newer.
|
|
22
|
+
|
|
23
|
+
## Local
|
|
24
|
+
|
|
25
|
+
The thermostat must already be on your Wi-Fi (set it up with the Thermostat app). Give it a fixed IP address;
|
|
26
|
+
it can't be discovered automatically.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
from pyscinan import DeviceMode, ScinanLocalClient
|
|
31
|
+
|
|
32
|
+
async def main():
|
|
33
|
+
async with ScinanLocalClient("192.168.1.50") as client:
|
|
34
|
+
dev = client.device
|
|
35
|
+
print(dev.device_id, dev.current_temperature, dev.target_temperature, dev.mode)
|
|
36
|
+
|
|
37
|
+
client.add_listener(lambda: print("update:", dev.current_temperature, dev.target_temperature))
|
|
38
|
+
|
|
39
|
+
await client.set_temperature(21.5)
|
|
40
|
+
await client.set_mode(DeviceMode.COMFORT)
|
|
41
|
+
await client.set_away(True) # "off" on floor heating thermostats
|
|
42
|
+
await asyncio.sleep(60) # pushes arrive every 15 s and on every change
|
|
43
|
+
|
|
44
|
+
asyncio.run(main())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Every command returns the status the thermostat answers with. A command the thermostat ignores (for example
|
|
48
|
+
power on the SAS920FHL) returns the unchanged status, so compare it with what you asked for.
|
|
49
|
+
|
|
50
|
+
## Cloud
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from pyscinan import ScinanCloudClient
|
|
54
|
+
|
|
55
|
+
async with ScinanCloudClient("email@example.com", "password") as cloud:
|
|
56
|
+
devices = await cloud.update_devices()
|
|
57
|
+
for dev in devices.values():
|
|
58
|
+
print(dev.device_id, dev.name, dev.online, dev.target_temperature)
|
|
59
|
+
await cloud.set_temperature(dev.device_id, 21.5)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Pass `session=` to reuse an `aiohttp.ClientSession`. Note that the Saswell cloud only supports plain HTTP.
|
|
63
|
+
|
|
64
|
+
## Command line
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pyscinan status 192.168.1.50
|
|
68
|
+
pyscinan listen 192.168.1.50 --seconds 60
|
|
69
|
+
pyscinan settemp 192.168.1.50 21.5
|
|
70
|
+
pyscinan away 192.168.1.50 on
|
|
71
|
+
pyscinan mode 192.168.1.50 1 # 0 Comfort, 1 Auto (schedule), 2 Day or night
|
|
72
|
+
pyscinan cloud-list email@example.com # password from $SCINAN_PASSWORD or a prompt
|
|
73
|
+
pyscinan --help
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Protocol
|
|
77
|
+
|
|
78
|
+
See [PROTOCOL.md](PROTOCOL.md) for everything known about the local protocol and the cloud API.
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
uv sync
|
|
84
|
+
uv run pytest
|
|
85
|
+
uv run ruff check .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The tests use a fake thermostat (TCP) and a fake cloud server, so no hardware or account is needed.
|
|
89
|
+
`scripts/hw_settings_test.py` runs against a real thermostat and changes its settings (then restores them).
|
|
90
|
+
|
|
91
|
+
## Disclaimer
|
|
92
|
+
|
|
93
|
+
Not affiliated with Saswell or Scinan. Use at your own risk.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyscinan"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Async client for Saswell / Scinan Wi-Fi thermostats (local TCP and cloud API)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
authors = [{ name = "Kris Skarbo" }]
|
|
14
|
+
dependencies = ["aiohttp>=3.9"]
|
|
15
|
+
keywords = ["saswell", "scinan", "thermostat", "home-assistant", "asyncio"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Framework :: AsyncIO",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Home Automation",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/skarbo/pyscinan"
|
|
31
|
+
Issues = "https://github.com/skarbo/pyscinan/issues"
|
|
32
|
+
Changelog = "https://github.com/skarbo/pyscinan/blob/main/CHANGELOG.md"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
pyscinan = "pyscinan.cli:main"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.sdist]
|
|
38
|
+
include = ["src/pyscinan", "tests", "README.md", "PROTOCOL.md", "CHANGELOG.md", "LICENSE"]
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "ruff>=0.6"]
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
asyncio_mode = "auto"
|
|
45
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
|
|
48
|
+
[tool.ruff]
|
|
49
|
+
line-length = 100
|
|
50
|
+
target-version = "py312"
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
select = ["E", "F", "I", "B", "UP", "ASYNC"]
|
|
54
|
+
|
|
55
|
+
[tool.ruff.lint.per-file-ignores]
|
|
56
|
+
"tests/*" = ["ASYNC109", "ASYNC110"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Async client for Scinan / Saswell Wi-Fi thermostats."""
|
|
2
|
+
|
|
3
|
+
from .cloud import ScinanCloudClient
|
|
4
|
+
from .const import Code, DeviceMode, DeviceType
|
|
5
|
+
from .exceptions import (
|
|
6
|
+
ScinanAuthFailed,
|
|
7
|
+
ScinanConnectionError,
|
|
8
|
+
ScinanError,
|
|
9
|
+
ScinanInvalidTokenError,
|
|
10
|
+
ScinanProtocolError,
|
|
11
|
+
ScinanResponseError,
|
|
12
|
+
ScinanTimeoutError,
|
|
13
|
+
)
|
|
14
|
+
from .local import ScinanLocalClient
|
|
15
|
+
from .models import ScinanDevice, ScinanStatus
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Code",
|
|
19
|
+
"DeviceMode",
|
|
20
|
+
"DeviceType",
|
|
21
|
+
"ScinanAuthFailed",
|
|
22
|
+
"ScinanCloudClient",
|
|
23
|
+
"ScinanConnectionError",
|
|
24
|
+
"ScinanDevice",
|
|
25
|
+
"ScinanError",
|
|
26
|
+
"ScinanInvalidTokenError",
|
|
27
|
+
"ScinanLocalClient",
|
|
28
|
+
"ScinanProtocolError",
|
|
29
|
+
"ScinanResponseError",
|
|
30
|
+
"ScinanStatus",
|
|
31
|
+
"ScinanTimeoutError",
|
|
32
|
+
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Command line tool: ``pyscinan <command> ...`` or ``python -m pyscinan``.
|
|
2
|
+
|
|
3
|
+
Local:
|
|
4
|
+
pyscinan listen HOST [--seconds N]
|
|
5
|
+
pyscinan status HOST
|
|
6
|
+
pyscinan settemp HOST 21.5
|
|
7
|
+
pyscinan power HOST on|off
|
|
8
|
+
pyscinan away HOST on|off
|
|
9
|
+
pyscinan program HOST on|off
|
|
10
|
+
pyscinan mode HOST 0|1|2
|
|
11
|
+
pyscinan raw HOST S05 -1,1 [--no-wait]
|
|
12
|
+
Cloud:
|
|
13
|
+
pyscinan cloud-list USERNAME (password from $SCINAN_PASSWORD or prompt)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import asyncio
|
|
20
|
+
import getpass
|
|
21
|
+
import logging
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
from dataclasses import asdict
|
|
25
|
+
|
|
26
|
+
from .cloud import ScinanCloudClient
|
|
27
|
+
from .exceptions import ScinanError
|
|
28
|
+
from .local import ScinanLocalClient
|
|
29
|
+
from .models import ScinanDevice
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _onoff(value: str) -> bool:
|
|
33
|
+
if value.lower() in ("1", "on", "true", "yes"):
|
|
34
|
+
return True
|
|
35
|
+
if value.lower() in ("0", "off", "false", "no"):
|
|
36
|
+
return False
|
|
37
|
+
raise argparse.ArgumentTypeError(f"expected on/off, got {value!r}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _print_device(dev: ScinanDevice | None) -> None:
|
|
41
|
+
if dev is None:
|
|
42
|
+
print("(no device)")
|
|
43
|
+
return
|
|
44
|
+
st = dev.status
|
|
45
|
+
print(f"device_id={dev.device_id} type={dev.type} name={dev.name} online={dev.online}")
|
|
46
|
+
if st:
|
|
47
|
+
fields = {k: v for k, v in asdict(st).items() if k not in ("raw", "extra")}
|
|
48
|
+
print(" " + " ".join(f"{k}={v}" for k, v in fields.items() if v is not None))
|
|
49
|
+
print(f" raw={st.raw}" + (f" extra={st.extra}" if st.extra else ""))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def _run(args: argparse.Namespace) -> int:
|
|
53
|
+
|
|
54
|
+
if args.cmd == "cloud-list":
|
|
55
|
+
password = os.environ.get("SCINAN_PASSWORD") or getpass.getpass("Password: ")
|
|
56
|
+
async with ScinanCloudClient(args.host, password) as cloud:
|
|
57
|
+
devices = await cloud.update_devices()
|
|
58
|
+
for dev in devices.values():
|
|
59
|
+
_print_device(dev)
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
client = ScinanLocalClient(args.host, device_id=args.id, reconnect=args.cmd == "listen")
|
|
63
|
+
client.add_message_listener(lambda m: print("<<", m))
|
|
64
|
+
await client.connect()
|
|
65
|
+
try:
|
|
66
|
+
if args.cmd == "listen":
|
|
67
|
+
await asyncio.sleep(args.seconds or 10**9)
|
|
68
|
+
elif args.cmd == "status":
|
|
69
|
+
pass # connect() already fetched status
|
|
70
|
+
elif args.cmd == "settemp":
|
|
71
|
+
await client.set_temperature(float(args.args[0]))
|
|
72
|
+
elif args.cmd == "power":
|
|
73
|
+
await client.set_power(_onoff(args.args[0]))
|
|
74
|
+
elif args.cmd == "away":
|
|
75
|
+
await client.set_away(_onoff(args.args[0]))
|
|
76
|
+
elif args.cmd == "program":
|
|
77
|
+
await client.set_program(_onoff(args.args[0]))
|
|
78
|
+
elif args.cmd == "mode":
|
|
79
|
+
await client.set_mode(int(args.args[0]))
|
|
80
|
+
elif args.cmd == "raw":
|
|
81
|
+
payload = args.args[1] if len(args.args) > 1 else "-1"
|
|
82
|
+
await client.send_command(args.args[0], payload, wait_for_status=not args.no_wait)
|
|
83
|
+
if args.no_wait:
|
|
84
|
+
await asyncio.sleep(3)
|
|
85
|
+
_print_device(client.device)
|
|
86
|
+
finally:
|
|
87
|
+
await client.close()
|
|
88
|
+
return 0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def main(argv: list[str] | None = None) -> int:
|
|
92
|
+
ap = argparse.ArgumentParser(prog="pyscinan", description=__doc__,
|
|
93
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
94
|
+
ap.add_argument("cmd", choices=["listen", "status", "settemp", "power", "away",
|
|
95
|
+
"program", "mode", "raw", "cloud-list"])
|
|
96
|
+
ap.add_argument("host", help="thermostat IP (or cloud username)")
|
|
97
|
+
ap.add_argument("args", nargs="*")
|
|
98
|
+
ap.add_argument("--id", help="16-char device id (normally learned from the hello)")
|
|
99
|
+
ap.add_argument("--seconds", type=float, help="listen duration")
|
|
100
|
+
ap.add_argument("--no-wait", action="store_true", help="raw: don't wait for S00 reply")
|
|
101
|
+
ap.add_argument("-v", "--verbose", action="store_true")
|
|
102
|
+
args = ap.parse_args(argv)
|
|
103
|
+
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARNING,
|
|
104
|
+
format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
|
105
|
+
try:
|
|
106
|
+
return asyncio.run(_run(args))
|
|
107
|
+
except KeyboardInterrupt:
|
|
108
|
+
return 130
|
|
109
|
+
except ScinanError as err:
|
|
110
|
+
print(f"error: {err}", file=sys.stderr)
|
|
111
|
+
return 1
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == "__main__":
|
|
115
|
+
sys.exit(main())
|