-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve documentation and auto generate API doc
- Loading branch information
Showing
13 changed files
with
241 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Build a markdown file and summary for all Python files in the module.""" | ||
from pathlib import Path | ||
|
||
import mkdocs_gen_files | ||
|
||
|
||
def main() -> None: | ||
"""Generate API documentation for all files.""" | ||
nav = mkdocs_gen_files.Nav() | ||
|
||
root = Path(__file__).parent.parent | ||
src_root = root / "ember_mug" | ||
|
||
for path in sorted(src_root.rglob("*.py")): | ||
module_path = path.relative_to(src_root).with_suffix("") | ||
doc_path = path.relative_to(src_root).with_suffix(".md") | ||
full_doc_path = Path("api", doc_path) | ||
parts = tuple(module_path.parts) | ||
|
||
# __init__ should create index | ||
if parts[-1] == "__init__": | ||
parts = parts[:-1] | ||
doc_path = doc_path.with_name("index.md") | ||
full_doc_path = full_doc_path.with_name("index.md") | ||
|
||
# Ignore __init__ and __main__ files | ||
elif parts[-1].startswith("__"): | ||
continue | ||
|
||
nav_parts = [f"{part}.py" for part in parts] | ||
if not nav_parts: | ||
continue | ||
|
||
nav[tuple(nav_parts)] = doc_path.as_posix() | ||
|
||
with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
ident = ".".join(parts) | ||
fd.write(f"---\ntitle: {ident}\n---\n\n::: {ident}") | ||
|
||
mkdocs_gen_files.set_edit_path(full_doc_path, ".." / path.relative_to(root)) | ||
|
||
with mkdocs_gen_files.open("api/SUMMARY.md", "w") as nav_file: | ||
nav_file.writelines(nav.build_literate_nav()) | ||
|
||
|
||
main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Once this library is installed in your active python environment you can also use the `ember-mug` to interact with your device. | ||
If you clone this project you may also run the commands via `hatch` in the project root. Simply use `hatch run ember-mug` with your desired options | ||
|
||
## Command Overview | ||
|
||
| Command | Use | | ||
|-------------|-----------------------------------------------------------------------------------| | ||
| `discover` | Find/List all detected unpaired devices in pairing mode | | ||
| `find` | Find *one* already paired devices | | ||
| `info` | Connect to *one* device and print its current state | | ||
| `poll` | Connect to *one* device and print its current state and keep watching for changes | | ||
| `get` | Get the value(s) of one or more attribute(s) by name | | ||
| `set` | Set one or more values on the device | | ||
|
||
A few useful common arguments: | ||
- `--mac your:mac:address` (or `-m`) to restrict to that address (useful if you have multiple devices) | ||
- `--raw` (or `-r`) flag to restrict to very basic and parsable output (useful if you want to use the output in a script.) | ||
- `--debug` (or `-d`) flag to enable very verbose output | ||
|
||
Some commands have extra options. You can see them by using the `--help` flag after specifying a command. ex. | ||
```bash | ||
ember-mug set --help | ||
``` | ||
|
||
## Examples | ||
|
||
### Find a device in pairing mode (for the first time) | ||
<!-- termynal --> | ||
```bash | ||
$ ember-mug discover | ||
Found Mug: C9:0F:59:D6:33:F9 | ||
Name: EMBER MUG | ||
Model: Ember Mug 2 [CM19/CM21M] | ||
Colour: Black | ||
Capacity: 295ml | ||
``` | ||
|
||
### Find a previously paired device | ||
<!-- termynal --> | ||
```bash | ||
$ ember-mug discover | ||
Found device: C9:0F:59:D6:33:F9: Ember Ceramic Mug | ||
``` | ||
|
||
### Fetch info and keep listening for changes | ||
<!-- termynal --> | ||
```bash | ||
$ ember-mug poll | ||
Found mug: C9:0F:59:D6:33:F9: Ember Ceramic Mug | ||
``` | ||
|
||
### Get the value(s) of specific attribute(s) | ||
<!-- termynal --> | ||
```bash | ||
$ ember-mug get name target-temp | ||
``` | ||
|
||
### Set the value(s) of specific attribute(s) | ||
<!-- termynal --> | ||
```bash | ||
$ ember-mug set --name "My mug" --target-temp 56.8 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Installation | ||
|
||
To install Python Ember Mug, run this command in your terminal: | ||
|
||
``` console | ||
pip install python-ember-mug | ||
``` | ||
|
||
This is the preferred method to install Python Ember Mug, as it will always install the most recent stable release. | ||
|
||
If you don't have `pip` installed, this [Python installation guide](https://pip.pypa.io/en/stable/installation/) can guide you through the process. | ||
|
||
## From source | ||
|
||
The source for Python Ember Mug can be downloaded from the [GitHub repo](https://github.com/sopelj/python-ember-mug). | ||
|
||
You can either clone the public repository: | ||
|
||
``` console | ||
git clone git://github.com/sopelj/python-ember-mug | ||
``` | ||
|
||
Or download the [tarball](https://github.com/sopelj/python-ember-mug/tarball/main): | ||
|
||
``` console | ||
curl -OJL https://github.com/sopelj/python-ember-mug/tarball/main | ||
``` | ||
|
||
Once you have a copy of the source, you can install it with: | ||
|
||
``` console | ||
pip install . | ||
``` | ||
|
||
[pip]: https://pip.pypa.io | ||
[Python installation guide]: http://docs.python-guide.org/en/latest/starting/installation/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
```python | ||
from ember_mug.scanner import find_mug, discover_mugs | ||
from ember_mug.mug import EmberMug | ||
|
||
# if first time with mug in pairing | ||
mugs = await discover_mugs() | ||
device = mugs[0] | ||
# after paired you can simply use | ||
device = await find_mug() | ||
mug = EmberMug(device) | ||
await mug.update_all() | ||
print(mug.data.formatted) | ||
await mug.disconnect() | ||
|
||
# You can also use connection as a context manager | ||
# if you want to ensure connection before starting and cleanup on exit | ||
async with mug.connection(): | ||
print('Connected.\nFetching Info') | ||
await mug.update_all() | ||
print(mug.data.formatted) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.