From cca04fc0d2216af8e77af4c60ac0719551fd086c Mon Sep 17 00:00:00 2001 From: Adam Mitchell Date: Thu, 29 May 2025 14:35:30 +0000 Subject: [PATCH 1/3] Add sensible defaults to ThingSet constructor --- python_thingset/thingset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python_thingset/thingset.py b/python_thingset/thingset.py index 50accc5..11a18f1 100755 --- a/python_thingset/thingset.py +++ b/python_thingset/thingset.py @@ -12,20 +12,20 @@ class ThingSet(object): def __init__( self, - backend: str = "can", + backend: str = ThingSetBackend.Socket, can_bus: str = "vcan0", can_addr: int = 0x00, init_block: bool = True, source_bus: int = 0x00, target_bus: int = 0x00, - port: str = "/dev/pts/5", + port: str = "/dev/ttyACM0", baud: int = 115200, - ip_addr: str = "192.0.2.1", + ip_addr: str = "127.0.0.1", ) -> "ThingSet": """Constructor for ThingSet object Args: - backend: communications backend to use - one of `'can'` or `'serial'` + backend: communications backend to use - one of `'can'` or `'serial'` or `'socket'` can_bus: physical (or virtual) CAN device to use if using CAN backend can_addr: intended node address of this ThingSet CAN instance if using CAN backend init_block: whether to block during instantation whilst backend connects From 9090198add99bbde49d184c81f3c724d4525a93d Mon Sep 17 00:00:00 2001 From: Adam Mitchell Date: Thu, 29 May 2025 14:35:48 +0000 Subject: [PATCH 2/3] Remove defunct mkdocs configuration file --- mkdocs.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 mkdocs.yml diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100644 index 2ea935f..0000000 --- a/mkdocs.yml +++ /dev/null @@ -1,23 +0,0 @@ -site_name: Python ThingSet -site_url: https://gitlab.io/Brill-Power/python-thingset -site_dir: public -docs_dir: ./docs - -theme: - name: "material" - -plugins: - - mkdocstrings - -nav: - - index.md - - python.md - - cli.md - - API reference: - - ThingSet: thingset.md - - ThingSetRequest: request.md - - ThingSetResponse: response.md - - ThingSetStatus: status.md - - ThingSetValue: value.md - -copyright: Copyright © 2025 Brill Power From 252757b892b40144aeebcceb1b0cbdc60436a6af Mon Sep 17 00:00:00 2001 From: Adam Mitchell Date: Thu, 29 May 2025 15:21:14 +0000 Subject: [PATCH 3/3] Update README with working (again) examples --- README.md | 118 ++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 8a263e4..b55ecae 100644 --- a/README.md +++ b/README.md @@ -19,89 +19,75 @@ python_thingset @ git+https://github.com/Brill-Power/python-thingset.git@fix-pac ### To get a value ```python -from python_thingset.thingset import ThingSet +from python_thingset import ThingSet -with ThingSet() as ts: - """ node_id=0x36, value_id=0xF03 """ - response = ts.get(0x36, 0xF03) +with ThingSet(backend="can", can_bus="vcan0") as ts: + response = ts.get(0xF03, 0x01) - print(response) - print(f"0x{response.status_code:02X}") - print(response.status_string) - print(response.data) + print(response) # 0x85 (CONTENT): native_posix + print(f"0x{response.status_code:02X}") # 0x85 + print(response.status_string) # CONTENT + print(response.data) # native_posix for v in response.values: - print(v) - print(v.name, f"0x{v.id:02X}", v.value) + print(v) # Build/rBoard (0xF03): native_posix + print(v.name, f"0x{v.id:02X}", v.value) # Build/rBoard 0xF03 native_posix ``` ### To fetch multiple values ```python -from python_thingset.thingset import ThingSet +from python_thingset import ThingSet -with ThingSet() as ts: - """ node_id=0x36, parent_id=0xF, child_ids=0xF03, 0xF02, 0xF01 """ - response = ts.fetch(0x36, 0xF, [0xF03, 0xF02, 0xF01]) +with ThingSet(backend="can", can_bus="vcan0") as ts: + response = ts.fetch(0xF, [0xF03, 0xF01], 0x01) - print(response) - print(f"0x{response.status_code:02X}") - print(response.status_string) - print(response.data) - - for v in response.values: - print(v) - print(v.name, f"0x{v.id:02X}", v.value) + print(response) # 0x85 (CONTENT): ['native_posix', '947c30f8'] + print(f"0x{response.status_code:02X}") # 0x85 + print(response.status_string) # CONTENT + print(response.data) # ['native_posix', '947c30f8'] ``` ### To fetch all child IDs of a parent ```python -from python_thingset.thingset import ThingSet +from python_thingset import ThingSet -with ThingSet() as ts: - """ node_id=0x36, parent_id=0xF, empty list invokes fetch of child IDs """ - response = ts.fetch(0x36, 0xF, []) +with ThingSet(backend="can", can_bus="vcan0") as ts: + response = ts.fetch(0xF, [], 0x01) - print(response) - print(f"0x{response.status_code:02X}") - print(response.status_string) - print(response.data) - - if response.values is not None: - for v in response.values: - print(v) - print(v.name, f"0x{v.id:02X}", [f"0x{i:02X}" for i in v.value]) + print(response) # 0x85 (CONTENT): [3841, 3842, 3843, 3845, 3849] + print(f"0x{response.status_code:02X}") # 0x85 + print(response.status_string) # CONTENT + print(response.data) # [3841, 3842, 3843, 3845, 3849] ``` ### To execute a function ```python -from python_thingset.thingset import ThingSet +from python_thingset import ThingSet -with ThingSet() as ts: - """ node_id=0x36, value_id=0x20, value_args="let-me-in" """ - response = ts.exec(0x36, 0x20, ["let-me-in"]) +with ThingSet(backend="can", can_bus="vcan0") as ts: + response = ts.exec(0x20, ["some-text"], 0x1) - print(response) - print(f"0x{response.status_code:02X}") - print(response.status_string) - print(response.data) + print(response) # 0x84 (CHANGED): 0 + print(f"0x{response.status_code:02X}") # 0x84 + print(response.status_string) # CHANGED + print(response.data) # 0 ``` ### To update a value ```python -from python_thingset.thingset import ThingSet +from python_thingset import ThingSet -with ThingSet() as ts: - """ node_id=0x36, parent_id=0x00, value_id=0x6F, value=21 """ - response = ts.update(0x36, 0x00, 0x6F, 21) +with ThingSet(backend="can", can_bus="vcan0") as ts: + response = ts.update(0x4F, 1, 0x1, 0x0) - print(response) - print(f"0x{response.status_code:02X}") - print(response.status_string) - print(response.data) + print(response) # 0x84 (CHANGED): 0 + print(f"0x{response.status_code:02X}") # 0x84 + print(response.status_string) # CHANGED + print(response.data) # 0 ``` ## To use from terminal @@ -110,14 +96,10 @@ with ThingSet() as ts: ```bash 1. git clone git@github.com:Brill-Power/python-thingset.git -2. cd python_thingset -3. pip install -r requirements.txt -3. chmod +x thingset -4. export PATH="$PATH:$(pwd)" +2. pip install . +3. pip install .[dev] (optional) ``` -This will clone the latest version of the repository, make the file `thingset` executable and then add the directory containing the file `thingset` to your `PATH` such that it will be executable from any directory. - ### Serial examples ``` @@ -160,15 +142,19 @@ thingset schema f -c vcan0 -t 2f ### Socket examples -```python - if __name__ == "__main__": - s = ThingSetSock("192.0.2.1") +``` +thingset get f -i 127.0.0.1 +thingset get f03 -i 127.0.0.1 + +thingset fetch f -i 127.0.0.1 +thingset fetch f f01 f02 -i 127.0.0.1 + +thingset update 0 6f 3 -i 127.0.0.1 - print(s.get(0x300)) - print(s.update(0x300, [77.8], parent_id=0x0)) - print(s.get(0x300)) - print(s.fetch(0, [])) - print(s.exec(0x1000, [4, 5])) +thingset exec 44 aFunctionArgument -i 127.0.0.1 +thingset exec 55 -i 127.0.0.1 +thingset exec 66 1.2 2.3 3.55 -i 127.0.0.1 - s.disconnect() +thingset schema -i 127.0.0.1 +thingset schema f -i 127.0.0.1 ```