boneIO 0.8.0.dev1__py3-none-any.whl → 0.8.0.dev3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneIO
3
- Version: 0.8.0dev1
3
+ Version: 0.8.0dev3
4
4
  Summary: Python App for BoneIO
5
5
  License: GNU General Public License v3.0
6
6
  Author-email: Paweł Szafer <pszafer@gmail.com>
@@ -16,6 +16,7 @@ Requires-Dist: adafruit-circuitpython-onewire>=2.0.5
16
16
  Requires-Dist: adafruit-circuitpython-pca9685>=3.4.10
17
17
  Requires-Dist: adafruit-circuitpython-pcf8575>=1.0.2
18
18
  Requires-Dist: adafruit-circuitpython-pct2075>=1.1.19
19
+ Requires-Dist: adafruit-circuitpython-typing==1.9.5
19
20
  Requires-Dist: aiomqtt>=1.1.0
20
21
  Requires-Dist: colorlog>=6.7.0
21
22
  Requires-Dist: gpio>=1.0.0
@@ -1,6 +1,6 @@
1
1
  boneio/__init__.py,sha256=hoLKnu6h1uEsiCHA9Ql2MMDC7VQS0E-s_2cxBS-CTOg,147
2
- boneio/bonecli.py,sha256=fKPcTEMjYG8zhWig3F6dqE2jDxBd17ydWHp0XVnq6sc,3491
3
- boneio/const.py,sha256=zV6kqBF1YnIQrfFpRj6CjEWm8MZGZHS6cQYjM6fpIYI,3293
2
+ boneio/bonecli.py,sha256=nOXC7ZJ0t9wRMpkkNDKijmREmV26qvRSK4HOAybIbQ4,8005
3
+ boneio/const.py,sha256=eIpq1EvFYh1p9I83xaDSOrF_JfdYr-1-yXO5vsAaqCg,5093
4
4
  boneio/cover.py,sha256=EfO1DAOGTPQykfgJHzg1WqPs0U8b1AnD2NMI-sLZccM,8444
5
5
  boneio/example_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  boneio/example_config/adc.yaml,sha256=GKNpl2t7ebsH57UhJlJioXNuBflsL6eO4JMnyYwZrFs,168
@@ -22,12 +22,12 @@ boneio/helper/click_timer.py,sha256=Gu8sEi1S8GG42SYbfaMju7WXFhnnil9gYfirLZX7kJk,
22
22
  boneio/helper/config.py,sha256=5cDnJ7usJDlUvXv8K2rSWEx30OFcU2k1U1vUEjO69WY,2431
23
23
  boneio/helper/events.py,sha256=f4JDMMkyp0lWz9w8ABZ_hlKyAbJWtYHGnGTs2vv4vac,8648
24
24
  boneio/helper/exceptions.py,sha256=vyYSUojwB7OttOPUjbxeHFM7C_o5ZQmRUcZ_vYpxYYI,717
25
- boneio/helper/filter.py,sha256=UcjifjaC5wHDW2He7wmwCX2IjSSeLVhXyhrXHeT8RmA,885
25
+ boneio/helper/filter.py,sha256=8jgSbHDaInEVlAPd7nrahnFYsi1y6C2fmI0yn55XzK0,935
26
26
  boneio/helper/gpio.py,sha256=q2r2uklPWePuuekPO63kVfoaQdkvNObUJ3ktwsHgOB0,4771
27
27
  boneio/helper/ha_discovery.py,sha256=B2t1cfOfKWys4EM1H7OxvOaYL8H_v18CTuHCEVP2w2c,7107
28
- boneio/helper/loader.py,sha256=zbg6WrKg7sfFRjny6qNQL7l-6ENbPq5AoEuW2T69PQE,17333
28
+ boneio/helper/loader.py,sha256=mkvM6Fg_4xHI079iiWFcUQFW1w8819AXAkiBja0vKxo,17473
29
29
  boneio/helper/logger.py,sha256=zyF_Vk3o2eSHuXypJhNzK99eZgkWDWybuB5KcJgurDs,1801
30
- boneio/helper/mqtt.py,sha256=novgn5Xl--dmwJ3p6gYVnurVxF5uf-i_t9rj5EmmvP8,859
30
+ boneio/helper/mqtt.py,sha256=1YgwO0RjkarN5qS5HS5rONf4H3_m3ak7tT_hHm-HeOQ,931
31
31
  boneio/helper/oled.py,sha256=f0XYbaFstUbJ6ISmFe1vQCnmNVMctQWtnStNdROrblc,351
32
32
  boneio/helper/onewire/W1ThermSensor.py,sha256=Pu5Fp29pKbxjJqDbFs05Mjg3Vy-9z_DTVoBpSWM_byA,2430
33
33
  boneio/helper/onewire/__init__.py,sha256=4djH-uxiq5XhAiFTOxyqjvWVoJe0c8U8iN0BfmH8nSU,448
@@ -36,16 +36,29 @@ boneio/helper/onewire/onewire.py,sha256=tHofTu1l0qG7hH2XoSf-lj8gW7wVKe27j57qQWpV
36
36
  boneio/helper/pcf8575.py,sha256=qeNYLqV5foDEQCyAz1WRQRi1CYYxtbPIha06Z5TyZVQ,311
37
37
  boneio/helper/queue.py,sha256=7fE7d344-BEW8sljN40wmqsbBr4kPLvz4ShBjkT04p8,1066
38
38
  boneio/helper/sensor/ina_219_smbus.py,sha256=eXp2epjUgsqaXamTSWSn3LMow5X_YxAxdREaWD7N3mk,6170
39
- boneio/helper/state_manager.py,sha256=W63oGPCKo1vZ8zr5Q_3SALM0mgjuab5b8Y397HAiO_o,2633
39
+ boneio/helper/state_manager.py,sha256=6OeqJsLQPCyQhhmFlNxCd80cTYLnKb02L4AZ1ZFFVBE,2616
40
40
  boneio/helper/stats.py,sha256=Ard04Z0WpkV7U6hgv1Uf4KxkjIde5iIW8W2cqRGXZyg,6731
41
41
  boneio/helper/timeperiod.py,sha256=xpg9oe30Z5WiLDQPq3EBKKScejOnN47NhcpeFvDd3bY,5806
42
- boneio/helper/util.py,sha256=SwTxVnUFe-YCmzubRzfICJDgrr0xMAJaR0G1wBXCMR8,681
42
+ boneio/helper/util.py,sha256=DyppBTE2zTWoxVpl83Kb4SpJLEqOOSEkxXEITCrwnfk,938
43
43
  boneio/helper/yaml_util.py,sha256=aaXMwXC2JoDYkBMcZkkB8nic3QOyGOhxPTRxWvMf3G4,11334
44
44
  boneio/input/__init__.py,sha256=8Hcps-wCCl6bCAMoEmDJecR-Q9giFL29AvG1ZGe0dZw,200
45
45
  boneio/input/gpio.py,sha256=mqmce4P_dNzmNHqNNiNAmKeeZKbbKtPUtQ6zd8-R-9I,2438
46
46
  boneio/input/gpio_new.py,sha256=gpPfDr39B8FVUyh9XHtLgVQr4glMGFBgQsyIMzXDPaw,2822
47
- boneio/manager.py,sha256=3Grw8fTWzsDfTXpk5arD5V_EY1wR6eTA8Oq-SCgPQaI,28589
48
- boneio/modbus.py,sha256=v0unQKtHnmNFpGC1lBcVmjlM6A8UFy6oXELPdAm7Hjo,3682
47
+ boneio/manager.py,sha256=06smEmgB9UDWUjCvy2l_lEHFyONU6N6ppW_dOiRv-wM,29866
48
+ boneio/modbus/__init__.py,sha256=yeHIxZ0_u7eCL7CqScvob5Utcru6Iza0LEtTagEtNtw,116
49
+ boneio/modbus/client.py,sha256=tmArCt9ac6rxUymdmFMEn4xpZtGdU7Yby7r3RkGJVxM,6030
50
+ boneio/modbus/cwt.json,sha256=4zJAHAV-h1JsV_Yp4VF6ecg_0eef-EHOdzRnhnMHRQs,814
51
+ boneio/modbus/dts1964_3f.json,sha256=WABph_2X4OgMidSM28vw4dLd9ZByRoiUP-RqE0UMpR8,8810
52
+ boneio/modbus/modbuscli.py,sha256=OjWVUPPHEOJ-Z2WMG9M-ycUx2Qu5EGImDG_RfFx8jcI,5832
53
+ boneio/modbus/orno-or-we-517.json,sha256=PtaG0B_uNLCemN2vrIXFS4Kzt6JBVoGCYhNMG-1wZhg,505
54
+ boneio/modbus/pt100.json,sha256=bzKNYDc3lMto94Ut8gutVIsHytQiMobwFCkonOiMegs,526
55
+ boneio/modbus/r4dcb08.json,sha256=oj4eK3bD1bG8BTRE4STVHB5L92luWaJ3FYFHQvFg-ZA,2735
56
+ boneio/modbus/sdm120.json,sha256=4sueFfSw7G6a77gdIUhbfJvE-MNVJFOeVbRvHDw5Rvk,4145
57
+ boneio/modbus/sdm630.json,sha256=TUiuc060IpF64p_HSDvdxEQcwkWHWUpnd48_xaGU-_o,8255
58
+ boneio/modbus/sensor.py,sha256=tfFYQNK0dE1yA0Otw66dxoM5wJ1b6nvW2_k4y8WAk_g,8303
59
+ boneio/modbus/socomec_e23.json,sha256=Is51YelEd4d6SYmz4Gd_oKx4Qi3bp-VHsl9zxWOFI5s,2882
60
+ boneio/modbus/sofar.json,sha256=A_YztQN_ctyItIm2LH1tfcs-pSyG18I530qleLd2tOw,5592
61
+ boneio/modbus/utils.py,sha256=cG75mmKTGaw_qrCG_D1qw-jl9XybUXa03i1ap5oBxGE,1753
49
62
  boneio/mqtt_client.py,sha256=hzGT3IyftPHNrQXSKbWUXGYZBpP-VdRBkOrILkXDNHs,8665
50
63
  boneio/oled.py,sha256=dLfAaH2Qto9P3mil_JK4siGvkSQ7LebhCabhL-OYGaM,5505
51
64
  boneio/relay/__init__.py,sha256=Cz6D37GKHxm8DiuPuxE2EMaey2wdUdJYVet_hfR0lzA,231
@@ -53,7 +66,7 @@ boneio/relay/basic.py,sha256=UfckgRtLC7qp4nuQihqmjTRPu-xJDL53YV9lJb3LnUU,4377
53
66
  boneio/relay/gpio.py,sha256=s64FBf6zlxciF57xJ6nrvy0t5Rie0uiXlwos0HL3RKM,1163
54
67
  boneio/relay/mcp.py,sha256=m1-AtmgFiIzy00uns3gGGCTwr-ppfAiN_zeIdZXVtQE,2000
55
68
  boneio/relay/pca.py,sha256=qiO5YWaywbtkbjVlqKi0y9VomsWuMHsfdQiGG6b_yug,2951
56
- boneio/relay/pcf.py,sha256=Nl0b3MMB0Ydlw-_vFjwBtdVz9betnX6rxyiBNX-a8G8,2288
69
+ boneio/relay/pcf.py,sha256=TU5yCqUVMFj_-W1rRqweRtCQWOu24Z6kFnBKGZHjptk,2498
57
70
  boneio/runner.py,sha256=PC1rbgsURBbtXe3xIX1zk0bDgSGNKwxTdgX1eq68vfc,2855
58
71
  boneio/schema/actions.yaml,sha256=kaJZ9B6SOl4Wbujtnr5k-g5JcAi2NSC1oGc0wZy8fnQ,1039
59
72
  boneio/schema/actions_sensor.yaml,sha256=rWd8pfsN7KvmvVvW6VedelFayRVehNQt6x4ou6yN9BY,91
@@ -61,7 +74,7 @@ boneio/schema/actions_switch.yaml,sha256=cDgSi12k4S-TWADQ20Fy9NvYKOXnm7YkyMaWpPy
61
74
  boneio/schema/filters.yaml,sha256=WopX1SmCZsSZXNiGccLoi7uMCsUpdbs0eVfsAjmbay4,286
62
75
  boneio/schema/filters_adc.yaml,sha256=3e0ts92MoFKOnfGOOn6WYIHxu0-tnZe9OjAjN9m7hiI,304
63
76
  boneio/schema/id.yaml,sha256=vHI_6dxkJwoiGp5ien_pPpyaWA1F06eirTgfWMyWa1E,75
64
- boneio/schema/schema.yaml,sha256=CRkOlCkXHpbn6EDfHgcPkpRToXR-e3t81W-UtO_W47o,18131
77
+ boneio/schema/schema.yaml,sha256=R9EqtON1dTNsyCtIXDy6B1vJQArGnSQlnSLExJhVmqc,18418
65
78
  boneio/schema/temp_unit.yaml,sha256=m32VGz9RTW92Lz08l9n6RftkcVNZquOGPPr5mc3eZVc,65
66
79
  boneio/schema/update_interval.yaml,sha256=L_YLddAZdybcdO-T57Qhlv1GaWIVDwhvH-GadD1oOIo,133
67
80
  boneio/sensor/__init__.py,sha256=Ztj-xzey-SWrEdVEozcwFsZSuEmJW8STVaf_vPMWiVc,619
@@ -69,20 +82,13 @@ boneio/sensor/adc.py,sha256=tCUdr3KN5uSbgXiwhNXbMjeNkO2CzPYhIOncHR5_LD0,1328
69
82
  boneio/sensor/gpio.py,sha256=8m07tW1xDsrhBM2dZ9_VvmvYRn-5hLQVTTUhPlKg1rg,1199
70
83
  boneio/sensor/gpio_new.py,sha256=m54agOF2gUh3aoC6f8WpCPAmBRADvqlKeWLqwlon9fg,1223
71
84
  boneio/sensor/ina219.py,sha256=kBwaCjY63CNFj1mRZ2EEtm2BrMZ6BW4ahjAD2LT-0jo,3439
72
- boneio/sensor/modbus/__init__.py,sha256=QkWfM3HXKLpc2rLHIy6lB9lAb9sjTKGnQGDUl3TAE0A,8573
73
- boneio/sensor/modbus/dts1964_3f.json,sha256=WABph_2X4OgMidSM28vw4dLd9ZByRoiUP-RqE0UMpR8,8810
74
- boneio/sensor/modbus/pt100.json,sha256=bzKNYDc3lMto94Ut8gutVIsHytQiMobwFCkonOiMegs,526
75
- boneio/sensor/modbus/r4dcb08.json,sha256=oj4eK3bD1bG8BTRE4STVHB5L92luWaJ3FYFHQvFg-ZA,2735
76
- boneio/sensor/modbus/sdm120.json,sha256=4sueFfSw7G6a77gdIUhbfJvE-MNVJFOeVbRvHDw5Rvk,4145
77
- boneio/sensor/modbus/sdm630.json,sha256=6LbIfXWk_PVRW-OuJwrsFEnRGLVEmEqqGIbj-1FDaiI,10969
78
- boneio/sensor/modbus/sofar.json,sha256=A_YztQN_ctyItIm2LH1tfcs-pSyG18I530qleLd2tOw,5592
79
- boneio/sensor/temp/__init__.py,sha256=OViqBb7DwVn_aFIy6V0iqkSUDjsDNLQ5sOS_4frYdwg,1808
85
+ boneio/sensor/temp/__init__.py,sha256=JLNH6Nc78ezleftnIYylIcNtKIm0rdqetbPZLsuCgDc,1844
80
86
  boneio/sensor/temp/dallas.py,sha256=xrvd1LNBh1fRcjz_yd_9S29Lv26ItVtLCmhZgVQWJos,2485
81
87
  boneio/sensor/temp/lm75.py,sha256=-mpOv78429plRPBp9s09Ljz1x2Bdxuagalqz40vlAKE,243
82
88
  boneio/sensor/temp/mcp9808.py,sha256=yAh5yJzZLGTqa39xV4fyqsruj7oy3niOZAUV2W6eyCM,271
83
- boneio/version.py,sha256=NVg2CbevSdeI0e8-U8dS8r-FiVV8W9Qx16WxoX74WXA,41
84
- boneIO-0.8.0.dev1.dist-info/entry_points.txt,sha256=Igl1SMDEWwMg144bwRz28UOCb80hdxomC99QJ3u6qC0,46
85
- boneIO-0.8.0.dev1.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
86
- boneIO-0.8.0.dev1.dist-info/METADATA,sha256=Es3lCLyoQaXjEh82lyY6r4uNWL3kwib1OgruffKxQD4,1749
87
- boneIO-0.8.0.dev1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
88
- boneIO-0.8.0.dev1.dist-info/RECORD,,
89
+ boneio/version.py,sha256=SyrsNjuIX7MqP9j5MeW39jpFuPZjcEoVFV9gCwzypPM,41
90
+ boneIO-0.8.0.dev3.dist-info/entry_points.txt,sha256=Igl1SMDEWwMg144bwRz28UOCb80hdxomC99QJ3u6qC0,46
91
+ boneIO-0.8.0.dev3.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
92
+ boneIO-0.8.0.dev3.dist-info/METADATA,sha256=hTnkcXT3BZzrVpDEaJNjowugUPS2yU4A3Hi8UlSO9fg,1801
93
+ boneIO-0.8.0.dev3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
94
+ boneIO-0.8.0.dev3.dist-info/RECORD,,
boneio/bonecli.py CHANGED
@@ -1,20 +1,28 @@
1
1
  """Bonecli script."""
2
+
2
3
  from __future__ import annotations
3
- import argparse
4
- import asyncio
5
- import logging
6
- import sys
4
+
7
5
  import os
8
- from typing import Any
9
6
 
10
7
  os.environ["W1THERMSENSOR_NO_KERNEL_MODULE"] = "1"
11
8
 
9
+ import argparse
10
+ import asyncio
11
+ import logging
12
+ import sys
12
13
  from colorlog import ColoredFormatter
13
14
  from yaml import MarkedYAMLError
14
15
 
16
+ from boneio.modbus.modbuscli import async_run_modbus_set, async_run_modbus_get
17
+ from boneio.modbus.client import VALUE_TYPES
18
+
19
+
15
20
  from boneio.const import ACTION
16
21
  from boneio.helper import load_config_from_file
17
- from boneio.helper.exceptions import ConfigurationException, RestartRequestException
22
+ from boneio.helper.exceptions import (
23
+ ConfigurationException,
24
+ RestartRequestException,
25
+ )
18
26
  from boneio.helper.events import GracefulExit
19
27
  from boneio.helper.logger import configure_logger
20
28
  from boneio.runner import async_run
@@ -49,30 +57,139 @@ def get_arguments() -> argparse.Namespace:
49
57
  parser = argparse.ArgumentParser(
50
58
  description="boneIO app for BeagleBone Black.",
51
59
  )
52
- parser.add_argument(ACTION, type=str, default="run")
53
- parser.add_argument("--version", action="version", version=__version__)
54
- parser.add_argument(
60
+ subparsers = parser.add_subparsers(dest=ACTION, required=True)
61
+ run_parser = subparsers.add_parser("run")
62
+ run_parser.add_argument(
63
+ "--debug",
64
+ "-d",
65
+ action="count",
66
+ help="Start boneIO in debug mode",
67
+ default=0,
68
+ )
69
+ run_parser.add_argument(
55
70
  "-c",
56
71
  "--config",
57
72
  metavar="path_to_config_dir",
58
73
  default="./config.yaml",
59
74
  help="File which contains boneIO configuration",
60
75
  )
61
- parser.add_argument(
62
- "--debug", "-d", action="count", help="Start boneIO in debug mode", default=0
76
+ run_parser.add_argument(
77
+ "--mqttusername",
78
+ help="Mqtt username to use if you don't want provide in file.",
79
+ )
80
+ run_parser.add_argument(
81
+ "--mqttpassword",
82
+ help="Mqtt password to use if you don't want provide in file.",
83
+ )
84
+ modbus_parser = subparsers.add_parser("modbus")
85
+ modbus_parser.add_argument(
86
+ "--debug",
87
+ "-d",
88
+ action="count",
89
+ help="Start boneIO in debug mode",
90
+ default=0,
91
+ )
92
+ modbus_parser.add_argument(
93
+ "--uart",
94
+ type=str,
95
+ choices=["uart1", "uart4"],
96
+ help="Choose UART",
97
+ required=True,
98
+ )
99
+ modbus_parser.add_argument(
100
+ "--address",
101
+ type=lambda x: int(x, 0),
102
+ required=True,
103
+ help="Current device address (hex or integer)",
63
104
  )
64
- parser.add_argument(
65
- "--mqttusername", help="Mqtt username to use if you don't want provide in file."
105
+ modbus_parser.add_argument(
106
+ "--baudrate",
107
+ type=int,
108
+ choices=[2400, 4800, 9600, 19200],
109
+ required=True,
110
+ help="Current baudrate",
66
111
  )
67
- parser.add_argument(
68
- "--mqttpassword", help="Mqtt password to use if you don't want provide in file."
112
+
113
+ modbus_parser.add_argument(
114
+ "--bytesize",
115
+ type=int,
116
+ required=True,
117
+ default=8,
118
+ help="Bytesize",
119
+ )
120
+
121
+ modbus_parser.add_argument(
122
+ "--stopbits",
123
+ type=int,
124
+ required=True,
125
+ default=1,
126
+ help="stopbits",
69
127
  )
128
+
129
+ modbus_parser.add_argument(
130
+ "--parity",
131
+ type=str,
132
+ choices=["P", "E", "N"],
133
+ default="N",
134
+ required=True,
135
+ help="Parity",
136
+ )
137
+
138
+ modbus_sub_parser = modbus_parser.add_subparsers(
139
+ dest="modbus_action", required=True
140
+ )
141
+ set_modbus_parser = modbus_sub_parser.add_parser("set")
142
+ set_modbus_parser.add_argument(
143
+ "--device",
144
+ type=str,
145
+ choices=["cwt"],
146
+ help="Choose device to set modbus address/baudrate",
147
+ required=True,
148
+ )
149
+ set_modbus_parser_group = set_modbus_parser.add_mutually_exclusive_group()
150
+ set_modbus_parser_group.add_argument(
151
+ "--new-address",
152
+ type=lambda x: int(x, 0),
153
+ help="Set new address (hex or integer / 1 - 253/)",
154
+ )
155
+
156
+ set_modbus_parser_group.add_argument(
157
+ "--new-baudrate",
158
+ type=int,
159
+ choices=[2400, 4800, 9600, 19200],
160
+ help="Choose new baudrate to set",
161
+ )
162
+
163
+ get_modbus_parser = modbus_sub_parser.add_parser("get")
164
+ get_modbus_parser.add_argument(
165
+ "--register-address",
166
+ type=int,
167
+ help="Register address",
168
+ required=True,
169
+ )
170
+ get_modbus_parser.add_argument(
171
+ "--register-type",
172
+ type=str,
173
+ choices=["input", "holding"],
174
+ help="Register type",
175
+ required=True,
176
+ )
177
+ get_modbus_parser.add_argument(
178
+ "--value-type",
179
+ type=str,
180
+ choices=VALUE_TYPES.keys(),
181
+ help="Value types",
182
+ required=True,
183
+ )
184
+ parser.add_argument("--version", action="version", version=__version__)
70
185
  arguments = parser.parse_args()
71
186
 
72
187
  return arguments
73
188
 
74
189
 
75
- def run(config: str, debug: int, mqttusername: str = "", mqttpassword: str = "") -> int:
190
+ def run(
191
+ config: str, debug: int, mqttusername: str = "", mqttpassword: str = ""
192
+ ) -> int:
76
193
  """Run BoneIO."""
77
194
  _LOGGER.info("BoneIO %s starting.", __version__)
78
195
  try:
@@ -99,6 +216,51 @@ def run(config: str, debug: int, mqttusername: str = "", mqttpassword: str = "")
99
216
  return 1
100
217
 
101
218
 
219
+ def run_modbus_command(
220
+ args: argparse.Namespace,
221
+ ) -> int:
222
+ """Run BoneIO."""
223
+ _LOGGER.info("BoneIO %s starting.", __version__)
224
+ try:
225
+ configure_logger(log_config={}, debug=args.debug)
226
+ if args.modbus_action == "set":
227
+ ret = asyncio.run(
228
+ async_run_modbus_set(
229
+ device=args.device,
230
+ uart=args.uart,
231
+ address=args.address,
232
+ baudrate=args.baudrate,
233
+ parity=args.parity,
234
+ bytesize=args.bytesize,
235
+ stopbits=args.stopbits,
236
+ new_baudrate=args.new_baudrate,
237
+ new_address=args.new_address,
238
+ ),
239
+ )
240
+ else:
241
+ ret = asyncio.run(
242
+ async_run_modbus_get(
243
+ uart=args.uart,
244
+ device_address=args.address,
245
+ baudrate=args.baudrate,
246
+ register_address=args.register_address,
247
+ register_type=args.register_type,
248
+ parity=args.parity,
249
+ bytesize=args.bytesize,
250
+ stopbits=args.stopbits,
251
+ value_type=args.value_type,
252
+ ),
253
+ )
254
+ return ret
255
+ except (RestartRequestException, GracefulExit) as err:
256
+ if err is not None:
257
+ _LOGGER.info(err)
258
+ return 0
259
+ except (ConfigurationException, MarkedYAMLError) as err:
260
+ _LOGGER.error("Failed to load config. %s Exiting.", err)
261
+ return 1
262
+
263
+
102
264
  def main() -> int:
103
265
  """Start boneIO."""
104
266
 
@@ -113,6 +275,12 @@ def main() -> int:
113
275
  mqttpassword=args.mqttpassword,
114
276
  debug=debug,
115
277
  )
278
+ elif args.action == "modbus":
279
+ _LOGGER.info("BoneIO Modbus helper %s .", __version__)
280
+ exit_code = run_modbus_command(
281
+ args=args,
282
+ )
283
+
116
284
  _LOGGER.info("Exiting with exit code %s", exit_code)
117
285
  return exit_code
118
286
 
boneio/const.py CHANGED
@@ -56,7 +56,11 @@ UARTS = {
56
56
  "uart5": {ID: "/dev/ttyS5", TX: "P8.37", RX: "P8.38"},
57
57
  }
58
58
 
59
- relay_actions = {ON: "async_turn_on", OFF: "async_turn_off", TOGGLE: "async_toggle"}
59
+ relay_actions = {
60
+ ON: "async_turn_on",
61
+ OFF: "async_turn_off",
62
+ TOGGLE: "async_toggle",
63
+ }
60
64
 
61
65
  # HA CONSTS
62
66
  HOMEASSISTANT = "homeassistant"
@@ -67,7 +71,8 @@ SHOW_HA = "show_in_ha"
67
71
  # OLED CONST
68
72
  OLED = "oled"
69
73
  FONTS = "fonts"
70
- OLED_PIN = "P9_41"
74
+ OLED_PIN = ("",)
75
+ "P9_41"
71
76
  GIGABYTE = 1073741824
72
77
  MEGABYTE = 1048576
73
78
  WIDTH = 128
@@ -160,3 +165,52 @@ cover_actions = {
160
165
  }
161
166
 
162
167
  INA219 = "ina219"
168
+ PINS = {
169
+ "P9_22": {"chip": 0, "line": 2},
170
+ "P9_21": {"chip": 0, "line": 3},
171
+ "P9_18": {"chip": 0, "line": 4},
172
+ "P9_17": {"chip": 0, "line": 5},
173
+ "P8_35": {"chip": 0, "line": 8},
174
+ "P8_33": {"chip": 0, "line": 9},
175
+ "P8_31": {"chip": 0, "line": 10},
176
+ "P8_32": {"chip": 0, "line": 11},
177
+ "P8_19": {"chip": 0, "line": 22},
178
+ "P8_13": {"chip": 0, "line": 23},
179
+ "P8_14": {"chip": 0, "line": 26},
180
+ "P8_17": {"chip": 0, "line": 27},
181
+ "P8_12": {"chip": 1, "line": 12},
182
+ "P8_11": {"chip": 1, "line": 13},
183
+ "P8_16": {"chip": 1, "line": 14},
184
+ "P8_15": {"chip": 1, "line": 15},
185
+ "P9_23": {"chip": 1, "line": 17},
186
+ "P9_14": {"chip": 1, "line": 18},
187
+ "P9_16": {"chip": 1, "line": 19},
188
+ "P8_26": {"chip": 1, "line": 29},
189
+ "P8_18": {"chip": 2, "line": 1},
190
+ "P8_7": {"chip": 2, "line": 2},
191
+ "P8_8": {"chip": 2, "line": 3},
192
+ "P8_10": {"chip": 2, "line": 4},
193
+ "P8_9": {"chip": 2, "line": 5},
194
+ "P8_45": {"chip": 2, "line": 6},
195
+ "P8_46": {"chip": 2, "line": 7},
196
+ "P8_43": {"chip": 2, "line": 8},
197
+ "P8_44": {"chip": 2, "line": 9},
198
+ "P8_41": {"chip": 2, "line": 10},
199
+ "P8_42": {"chip": 2, "line": 11},
200
+ "P8_39": {"chip": 2, "line": 12},
201
+ "P8_40": {"chip": 2, "line": 13},
202
+ "P8_37": {"chip": 2, "line": 14},
203
+ "P8_38": {"chip": 2, "line": 15},
204
+ "P8_36": {"chip": 2, "line": 16},
205
+ "P8_34": {"chip": 2, "line": 17},
206
+ "P8_27": {"chip": 2, "line": 22},
207
+ "P8_29": {"chip": 2, "line": 23},
208
+ "P8_28": {"chip": 2, "line": 24},
209
+ "P8_30": {"chip": 2, "line": 25},
210
+ "P9_31": {"chip": 3, "line": 14},
211
+ "P9_29": {"chip": 3, "line": 15},
212
+ "P9_30": {"chip": 3, "line": 16},
213
+ "P9_28": {"chip": 3, "line": 17},
214
+ "P9_27": {"chip": 3, "line": 19},
215
+ "P9_25": {"chip": 3, "line": 21},
216
+ }
boneio/helper/filter.py CHANGED
@@ -1,4 +1,5 @@
1
1
  """Filter class to adjust sensor values."""
2
+
2
3
  from __future__ import annotations
3
4
  import logging
4
5
 
@@ -22,7 +23,9 @@ class Filter:
22
23
  for filter in self._filters:
23
24
  for k, v in filter.items():
24
25
  if k not in FILTERS:
25
- _LOGGER.warn("Filter %s doesn't exists. Fix it in config.", k)
26
+ _LOGGER.warning(
27
+ "Filter %s doesn't exists. Fix it in config.", k
28
+ )
26
29
  continue
27
30
  value = FILTERS[k](value, v)
28
31
  if value is None:
boneio/helper/loader.py CHANGED
@@ -103,7 +103,9 @@ def create_adc(manager: Manager, topic_prefix: str, adc_list: list = []):
103
103
  manager=manager,
104
104
  send_message=manager.send_message,
105
105
  topic_prefix=topic_prefix,
106
- update_interval=gpio.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
106
+ update_interval=gpio.get(
107
+ UPDATE_INTERVAL, TimePeriod(seconds=60)
108
+ ),
107
109
  filters=gpio.get(FILTERS, []),
108
110
  )
109
111
  if gpio.get(SHOW_HA, True):
@@ -163,7 +165,10 @@ expander_class = {MCP: MCP23017, PCA: PCA9685, PCF: PCF8575}
163
165
 
164
166
 
165
167
  def create_expander(
166
- expander_dict: dict, expander_config: list, exp_type: ExpanderTypes, i2cbusio: I2C
168
+ expander_dict: dict,
169
+ expander_config: list,
170
+ exp_type: ExpanderTypes,
171
+ i2cbusio: I2C,
167
172
  ) -> dict:
168
173
  grouped_outputs = {}
169
174
  for expander in expander_config:
@@ -189,7 +194,7 @@ def create_expander(
189
194
 
190
195
  def create_modbus_sensors(manager: Manager, sensors, **kwargs) -> None:
191
196
  """Create Modbus sensor for each device."""
192
- from boneio.sensor.modbus import ModbusSensor
197
+ from boneio.modbus.sensor import ModbusSensor
193
198
 
194
199
  for sensor in sensors:
195
200
  name = sensor.get(ID)
@@ -202,7 +207,9 @@ def create_modbus_sensors(manager: Manager, sensors, **kwargs) -> None:
202
207
  manager=manager,
203
208
  model=sensor[MODEL],
204
209
  send_message=manager.send_message,
205
- update_interval=sensor.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
210
+ update_interval=sensor.get(
211
+ UPDATE_INTERVAL, TimePeriod(seconds=60)
212
+ ),
206
213
  **kwargs,
207
214
  )
208
215
  except FileNotFoundError as err:
@@ -272,7 +279,9 @@ def configure_relay(
272
279
  if restore_state
273
280
  else False
274
281
  )
275
- if output_type == NONE and state_manager.get(attr_type=RELAY, attr=relay_id):
282
+ if output_type == NONE and state_manager.get(
283
+ attr_type=RELAY, attr=relay_id
284
+ ):
276
285
  state_manager.del_attribute(attr_type=RELAY, attribute=relay_id)
277
286
  restored_state = False
278
287
 
@@ -347,7 +356,7 @@ def configure_event_sensor(
347
356
  pin: str,
348
357
  press_callback: Callable,
349
358
  send_ha_autodiscovery: Callable,
350
- input: GpioEventButtonOld | GpioEventButtonNew | None = None
359
+ input: GpioEventButtonOld | GpioEventButtonNew | None = None,
351
360
  ) -> GpioEventButtonOld | GpioEventButtonNew | None:
352
361
  """Configure input sensor or button."""
353
362
  try:
@@ -473,7 +482,9 @@ def configure_cover(
473
482
  return cover
474
483
 
475
484
 
476
- def configure_ds2482(i2cbusio: I2C, address: str = DS2482_ADDRESS) -> OneWireBus:
485
+ def configure_ds2482(
486
+ i2cbusio: I2C, address: str = DS2482_ADDRESS
487
+ ) -> OneWireBus:
477
488
  ds2482 = DS2482(i2c=i2cbusio, address=address)
478
489
  ow_bus = OneWireBus(ds2482=ds2482)
479
490
  return ow_bus
@@ -493,7 +504,9 @@ def find_onewire_devices(
493
504
  devices = ow_bus.scan()
494
505
  for device in devices:
495
506
  _addr: int = device.int_address
496
- _LOGGER.debug("Found device on bus %s with address %s", bus_id, hex(_addr))
507
+ _LOGGER.debug(
508
+ "Found device on bus %s with address %s", bus_id, hex(_addr)
509
+ )
497
510
  out[_addr] = device
498
511
  except RuntimeError as err:
499
512
  _LOGGER.error("Problem with scanning %s bus. %s", bus_type, err)
boneio/helper/mqtt.py CHANGED
@@ -1,6 +1,8 @@
1
1
  """Class to help initialize classes which uses mqtt send."""
2
+
2
3
  from typing import Callable, Union
3
4
  from boneio.helper.util import strip_accents
5
+ from typing import Optional
4
6
 
5
7
 
6
8
  class BasicMqtt:
@@ -11,7 +13,9 @@ class BasicMqtt:
11
13
  id: str,
12
14
  topic_prefix: str,
13
15
  name: str,
14
- send_message: Callable[[str, Union[str, dict], bool], None],
16
+ send_message: Callable[
17
+ [str, Union[str, int, dict, None], Optional[bool]], None
18
+ ],
15
19
  topic_type: str,
16
20
  **kwargs,
17
21
  ):
@@ -1,4 +1,5 @@
1
1
  """State files manager."""
2
+
2
3
  from __future__ import annotations
3
4
  import asyncio
4
5
  import logging
@@ -38,16 +39,19 @@ class StateManager:
38
39
  if attr_type in self._state and attribute in self._state[attr_type]:
39
40
  del self._state[attr_type][attribute]
40
41
 
41
- def save_attribute(self, attr_type: str, attribute: str, value: str) -> None:
42
+ def save_attribute(
43
+ self, attr_type: str, attribute: str, value: str
44
+ ) -> None:
42
45
  """Save single attribute to file."""
43
46
  if attr_type not in self._state:
44
47
  self._state[attr_type] = {}
45
48
  self._state[attr_type][attribute] = value
46
49
  if self._save_attributes_callback is not None:
47
- print(self._save_attributes_callback)
48
50
  self._save_attributes_callback.cancel()
49
51
  self._save_attributes_callback = None
50
- self._save_attributes_callback = self._loop.call_later(1, lambda: self._loop.create_task(self.save_state()))
52
+ self._save_attributes_callback = self._loop.call_later(
53
+ 1, lambda: self._loop.create_task(self.save_state())
54
+ )
51
55
 
52
56
  def get(self, attr_type: str, attr: str, default_value: Any = None) -> Any:
53
57
  """Retrieve attribute from json."""
@@ -60,7 +64,7 @@ class StateManager:
60
64
  def state(self) -> dict:
61
65
  """Retrieve all states."""
62
66
  return self._state
63
-
67
+
64
68
  def _save_state(self) -> None:
65
69
  with open(self._file, "w+", encoding="utf-8") as f:
66
70
  json.dump(self._state, f, indent=2)
boneio/helper/util.py CHANGED
@@ -1,4 +1,6 @@
1
1
  import unicodedata
2
+ import os
3
+ import json
2
4
  from typing import Any, Callable, TypeVar
3
5
 
4
6
  CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable[..., Any])
@@ -17,5 +19,17 @@ def is_callback(func: Callable[..., Any]) -> bool:
17
19
 
18
20
 
19
21
  def strip_accents(s):
20
- return ''.join(c for c in unicodedata.normalize('NFD', s)
21
- if unicodedata.category(c) != 'Mn' and c != ' ')
22
+
23
+ return "".join(
24
+ c
25
+ for c in unicodedata.normalize("NFD", s)
26
+ if unicodedata.category(c) != "Mn" and c != " "
27
+ )
28
+
29
+
30
+ def open_json(path: str, model: str) -> dict:
31
+ """Open json file."""
32
+ file = f"{os.path.join(path)}/{model}.json"
33
+ with open(file, "r") as db_file:
34
+ datastore = json.load(db_file)
35
+ return datastore