Skip to content

Commit 0be2d92

Browse files
committed
moved testing into doc
beefed up the development doc
1 parent 079e409 commit 0be2d92

4 files changed

Lines changed: 138 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ It can also pull code from a web server, so you can run Adafruit example code di
1919

2020
It does not currently support Microsoft Windows. I do not have a Windows machine and have no way to test it with Windows. I understand that a lot of people use Windows and that the lack of support means that a lot of people who might benefit from circremote won't be able to use it. While I'm happy to spend some time and resources on continuing to develop circremote and support users, I don't have the time, energy or desire to bring up a new platform and get it working on it. If a motivated co-maintainer comes along who'd like to get circremote working properly with Windows and then support it, I'd be happy to bring someone like that onto the project.
2121

22-
From here, see how to install circremote and then please check out the [FAQ](doc/FAQ.md) to see how to use it.
23-
2422
- [About circremote](doc/about.md)
2523
- [Install](doc/install.md)
2624
- [Usage](doc/usage.md)
2725
- [Commands](doc/commands.md)
2826
- [Configuration](doc/configuration.md)
2927
- [Contributing](doc/contributing.md)
3028
- [Development](doc/development.md)
29+
- [Testing](doc/testing.md)
3130
- [FAQ](doc/faq.md)
3231

3332

@@ -39,4 +38,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
3938

4039
- CircuitPython community for the excellent ecosystem
4140
- Adafruit for the sensor libraries
42-
- Python community for the package infrastructure
41+
- Python community for, well... Python

doc/development.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,136 @@ python -m pytest -v
2626
# Run with coverage
2727
python -m pytest --cov=circremote --cov-report=html
2828
```
29+
30+
### Command Structure
31+
32+
Commands consist of three files that are stored in a directory with the name of the command.
33+
34+
- `code.py` - the Python code for the command
35+
- `requirements.txt` - required libraries to be installed by `circup`
36+
- `info.json` - information about the command
37+
38+
#### `code.py`
39+
40+
Just like a `code.py` file that's stored on a CircuitPython device, on this file is never saved to the device's internal flash storage.
41+
42+
Maximum size will depend on the available memory on the device.
43+
44+
##### Variables
45+
46+
The file supports very limited substitutions using the syntax `{{NAME}}` - that string will be replaced with the value of the variable named `NAME`. Variables must be listed in `info.json`. We use double curly braces to try to avoid confusion with f-string substitutions.
47+
48+
For instance:
49+
```
50+
import time
51+
import board
52+
import busio
53+
import adafruit_bme680
54+
55+
# Initialize I2C with fallback
56+
try:
57+
i2c = busio.I2C({{ scl }}, {{ sda }})
58+
except:
59+
i2c = board.I2C()
60+
61+
# Initialize BME680
62+
try:
63+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address={{ address }})
64+
65+
```
66+
67+
If suppose `scl` is `board.SCL`, `sda` is `board.SDA` and `address` is `0x76`. The result would be:
68+
```
69+
import time
70+
import board
71+
import busio
72+
import adafruit_bme680
73+
74+
# Initialize I2C with fallback
75+
try:
76+
i2c = busio.I2C(board.SCL, board.SDA)
77+
except:
78+
i2c = board.I2C()
79+
80+
# Initialize BME680
81+
try:
82+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76)
83+
84+
```
85+
86+
If `scl` and `sda` are not defined, the result would be:
87+
```
88+
import time
89+
import board
90+
import busio
91+
import adafruit_bme680
92+
93+
# Initialize I2C with fallback
94+
try:
95+
i2c = busio.I2C()
96+
except:
97+
i2c = board.I2C()
98+
99+
# Initialize BME680
100+
try:
101+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76)
102+
103+
```
104+
105+
The `busio.I2C()` line would throw an exception and control would pass to the `board.I2C()` line which would use the default I2C pins for the board.
106+
107+
Variables are interpolated using direction string replacement, without any type checking - they're all strings. If you need the result in the Python code to be a string, make sure you include quotes around it in the code.
108+
109+
For instance, if `filename` is `settings.toml` then this code would fail:
110+
```
111+
print({{ filename }})
112+
```
113+
and this code would work:
114+
```
115+
print("{{ filename }}")
116+
```
117+
118+
Variables can be optional or required, and can have a default value. Variables with a default value are always optional.
119+
120+
##### Default command line
121+
122+
A command can include a default command line which has variables automatically substituted in it.
123+
124+
For instance, the `cat` command takes one variable, `filename`. It also has a default commandline of `filename`.
125+
126+
You can run it like this:
127+
`circremote DEVICE cat filename=settings.toml`
128+
or like this:
129+
`circremote DEVICE cat settings.toml`
130+
and the filename will automatically be set.
131+
132+
#### `requirements.txt`
133+
134+
Normal file format, one library name per line, comments start with \#
135+
136+
#### `info.json`
137+
138+
This is a JSON file with information about the command. This is an example for the `cat` command:
139+
```
140+
{
141+
"description": "Output a file",
142+
"warn_unavailable": false,
143+
"variables": [
144+
{
145+
"name": "filename",
146+
"required": true,
147+
"description": "File to cat",
148+
"default": null
149+
}
150+
],
151+
"tested": true,
152+
"default_commandline": "filename"
153+
}
154+
```
155+
156+
- `description` is used by `-h` to describe what the command does
157+
- `warn_unavailable` indicates that the user should be warned that this could make the device unavailable or unreachable
158+
- `variables` - an array of variables, each has a `named, `required` flag, `description and a `default` value
159+
- `tested` - this indicates whether the command has been tested. Many commands were written by an LLM. While they're verified to parse correctly they may not yet have been truly tested with hardware.
160+
- `default_commandline` - this is the default command line, used with variable substitutions
161+
File renamed without changes.

doc/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ circremote [options] <serial_port or ip:port> <command_name> [command line optio
99
### Show Version
1010
```bash
1111
circremote --version
12-
# or
1312
circremote -V
1413
```
1514

@@ -55,10 +54,11 @@ circremote -u /usr/local/bin/circup /dev/ttyUSB0 BME280
5554
- `-y, --yes`: Skip confirmation prompts (run untested commands without asking)
5655
- `-c, --skip-circup`: Skip circup dependency installation
5756
- `-u, --circup PATH`: Path to circup executable
58-
- `-C, --config PATH`: Path to circremote.json config file
57+
- `-C, --config PATH`: Path to circremote JSON config file (`~/.circremote/config.json` by default)
5958
- `-l, --list`: List all available commands from all sources
60-
- `-h, --help`: Show help message
59+
- `-h, --help`: Show help message
6160
- `-h COMMAND`: Show help for a specific command
61+
- `-t TIMEOUT: exit TIMEOUT seconds after sending the command - 0 to not exit`
6262
- `-V, --version`: Show version and exit
6363

6464
## Features

0 commit comments

Comments
 (0)