Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ __pycache__
**/*.log

# Mac files
.DS_Store
.DS_Store

# build metadata / files
*build
python_thingset.egg-info
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

## To use from Python

#### To install:
### To install

Simply include in your `requirements.txt` (or equivalent file) as:

```
python_thingset @ git+ssh://git@github.com:Brill-Power/python-thingset.git
python_thingset @ git+https://github.com/Brill-Power/python-thingset.git
```

If you wish to work from a specific branch, for example a branch called `fix-package-imports`, append `@fix-package-imports` to the above line in `requirements.txt`, as follows:

```
python_thingset @ git+ssh://git@github.com:Brill-Power/python-thingset.git@fix-package-imports
python_thingset @ git+https://github.com/Brill-Power/python-thingset.git@fix-package-imports
```

#### To get a value:
```
### To get a value

```python
from python_thingset.thingset import ThingSet

with ThingSet() as ts:
Expand All @@ -34,8 +35,9 @@ with ThingSet() as ts:
print(v.name, f"0x{v.id:02X}", v.value)
```

#### To fetch multiple values:
```
### To fetch multiple values

```python
from python_thingset.thingset import ThingSet

with ThingSet() as ts:
Expand All @@ -52,8 +54,9 @@ with ThingSet() as ts:
print(v.name, f"0x{v.id:02X}", v.value)
```

#### To fetch all child IDs of a parent:
```
### To fetch all child IDs of a parent

```python
from python_thingset.thingset import ThingSet

with ThingSet() as ts:
Expand All @@ -71,8 +74,9 @@ with ThingSet() as ts:
print(v.name, f"0x{v.id:02X}", [f"0x{i:02X}" for i in v.value])
```

#### To execute a function:
```
### To execute a function

```python
from python_thingset.thingset import ThingSet

with ThingSet() as ts:
Expand All @@ -85,8 +89,9 @@ with ThingSet() as ts:
print(response.data)
```

#### To update a value:
```
### To update a value

```python
from python_thingset.thingset import ThingSet

with ThingSet() as ts:
Expand All @@ -101,9 +106,9 @@ with ThingSet() as ts:

## To use from terminal

#### To install:
### To install

```
```bash
1. git clone git@github.com:Brill-Power/python-thingset.git
2. cd python_thingset
3. pip install -r requirements.txt
Expand All @@ -113,7 +118,7 @@ with ThingSet() as ts:

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:
### Serial examples

```
thingset get SomeGroup -p /dev/pts/5
Expand All @@ -134,7 +139,7 @@ thingset schema SomeGroup -p /dev/pts/5
thingset schema "" -p /dev/pts/5
```

#### CAN examples:
### CAN examples

```
thingset get f -c vcan0 -t 2f
Expand All @@ -151,4 +156,19 @@ thingset exec 66 1.2 2.3 3.55 -c vcan0 -t 2f

thingset schema -c vcan0 -t 2f
thingset schema f -c vcan0 -t 2f
```
```

### Socket examples

```python
if __name__ == "__main__":
s = ThingSetSock("192.0.2.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]))

s.disconnect()
```
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "python_thingset"
version = "0.1.0"
version = "0.2.0"
description = "A Python library for ThingSet functionality"
authors = [
{ name = "Adam Mitchell", email = "adam.mitchell@brillpower.com" }
Expand All @@ -30,3 +30,6 @@ dev = [
homepage = "https://gitlab.io/Brill-Power/python-thingset/"
repository = "https://gitlab.com/Brill-Power/python-thingset/"
documentation = "https://gitlab.com/Brill-Power/python-thingset/"

[project.scripts]
thingset = "python_thingset.cli:run_cli"
21 changes: 6 additions & 15 deletions python_thingset/backend.py → python_thingset/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@


class ThingSetBackend(ABC):
CAN: str = "can"
CAN: str = "can"
Serial: str = "serial"
Socket: str = "socket"

def __init__(self):
self._running = False
self._thread = None

self.is_connected = False

@property
def is_connected(self) -> bool:
return self._is_connected

@is_connected.setter
def is_connected(self, _is_connected) -> None:
self._is_connected = _is_connected

def start_receiving(self) -> None:
if not self._running:
self._running = True
Expand All @@ -52,20 +43,20 @@ def _handle_message(self, message: Union[bytes, can.Message]) -> None:

@abstractmethod
def connect(self) -> None:
""" perform backend initialisation """
"""perform backend initialisation"""
pass

@abstractmethod
def disconnect(self) -> None:
""" perform backend teardown """
"""perform backend teardown"""
pass

@abstractmethod
def send(self, _data: Union[bytes, can.Message]) -> None:
""" send data """
"""send data"""
pass

@abstractmethod
def receive(self) -> Union[bytes, can.Message]:
""" receive data """
"""receive data"""
pass
Loading
Loading