Skip to content

Commit 1230d28

Browse files
authored
Merge pull request #11 from reubenmiller/refactor-operation-handlers
refactor: move operation handlers to python module
2 parents e23ca0f + 01594d0 commit 1230d28

34 files changed

+308
-283
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: pylint operations
3737

3838
- name: Check reader
39-
run: pylint modbus_reader
39+
run: pylint tedge_modbus

.pylintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ exclude-too-few-public-methods=
290290
ignored-parents=
291291

292292
# Maximum number of arguments for function / method.
293-
max-args=6
293+
max-args=5
294294

295295
# Maximum number of attributes for a class (see R0902).
296296
max-attributes=7
@@ -302,7 +302,7 @@ max-bool-expr=5
302302
max-branches=12
303303

304304
# Maximum number of locals for function / method body.
305-
max-locals=19
305+
max-locals=15
306306

307307
# Maximum number of parents for a class (see R0901).
308308
max-parents=7
@@ -517,7 +517,7 @@ ignore-imports=yes
517517
ignore-signatures=yes
518518

519519
# Minimum lines number of a similarity.
520-
min-similarity-lines=10
520+
min-similarity-lines=4
521521

522522

523523
[SPELLING]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ There are two configuration files you need to edit for your use case. Any change
7171
All config files are expected to be in the /etc/tedge/plugins/modbus folder.
7272
As an alternative the directory can be based with -c or --configdir to the python script like so:
7373

74-
`python modbus_reader/reader.py --configdir <configfolder>`
74+
`python3 -m tedge_modbus.reader --configdir <configfolder>`
7575

7676
If used with Cumulocity IoT, the plugins can be managed via the Device Management or created with the cloud fieldbus operations.
7777

@@ -192,7 +192,7 @@ After installing, you can build the Debian package with:
192192
- create the virtualenv with `python -m venv venv`
193193
- activate venv environment with `source ./venv/bin/activate`
194194
- install all dependencies with `python -m pip install -r requirements.txt`
195-
- run the reader with `python modbus_reader/reader.py -c ./config`
195+
- run the reader with `python tedge_modbus/reader/reader.py -c ./config`
196196

197197
### As deb file
198198

images/tedge/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM goreleaser/nfpm as build-stage
33

44
# Copy required files
55
WORKDIR /build
6-
COPY modbus_reader /build/modbus_reader
6+
COPY tedge_modbus /build/tedge_modbus
77
COPY operations /build/operations
88
COPY scripts /build/scripts
99
COPY nfpm.yaml /build/nfpm.yaml

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ format:
2424
# Run python linter
2525
lint:
2626
.venv/bin/python3 -m pylint operations
27-
.venv/bin/python3 -m pylint modbus_reader
27+
.venv/bin/python3 -m pylint tedge_modbus
2828

2929
# Build deb package
3030
setup:

nfpm.yaml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,22 @@ license: "Apache-2.0"
1717

1818
contents:
1919
#modbus reader files
20-
- src: ./modbus_reader/
21-
dst: /usr/lib/python3/dist-packages/modbus_reader
20+
- src: ./tedge_modbus/
21+
dst: /usr/lib/python3/dist-packages/tedge_modbus
2222

23-
#c8y_ModbusConfiguration
24-
- src: ./operations/c8y_ModbusConfiguration/c8y_ModbusConfiguration
25-
dst: /etc/tedge/operations/c8y/c8y_ModbusConfiguration
23+
# operation handlers
24+
- src: ./operations/*
25+
dst: /etc/tedge/operations/c8y/
2626
file_info:
27-
mode: 0644
28-
- src: ./operations/c8y_ModbusConfiguration/c8y_ModbusConfiguration.py
29-
dst: /etc/tedge/plugins/modbus/c8y_ModbusConfiguration.py
30-
file_info:
31-
mode: 0755
27+
mode: 0644
3228

33-
# c8y_ModbusDevice
34-
- src: ./operations/c8y_ModbusDevice/c8y_ModbusDevice
35-
dst: /etc/tedge/operations/c8y/c8y_ModbusDevice
36-
file_info:
37-
mode: 0644
38-
- src: ./operations/c8y_ModbusDevice/c8y_ModbusDevice.py
39-
dst: /etc/tedge/plugins/modbus/c8y_ModbusDevice.py
40-
file_info:
41-
mode: 0755
42-
# Empty modbus config
29+
# Empty modbus config
4330
# - dst: /etc/tedge/plugins/modbus/modbus.toml
4431
# type: config
4532
# # Empty device config
4633
# - dst: /etc/tedge/plugins/modbus/devices.toml
4734
# type: config
35+
4836
# System D Unit File
4937
- src: ./tedge-modbus-plugin.service
5038
dst: /lib/systemd/system/tedge-modbus-plugin.service

operations/c8y_Coils

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[exec]
2+
topic = "c8y/s/ds"
3+
on_message = "xy"
4+
command = "python3 -m tedge_modbus.operations c8y_Coils"

operations/c8y_Coils/c8y_Coils

Lines changed: 0 additions & 4 deletions
This file was deleted.

operations/c8y_Coils/c8y_Coils.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

operations/c8y_ModbusConfiguration

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[exec]
2+
topic = "c8y/s/dc/modbus"
3+
on_message = "1"
4+
command = "python3 -m tedge_modbus.operations c8y_ModbusConfiguration"

0 commit comments

Comments
 (0)