boneIO 0.8.0.dev1__tar.gz → 0.8.0.dev3__tar.gz

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.
Files changed (100) hide show
  1. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/PKG-INFO +1 -1
  2. boneIO-0.8.0.dev3/boneio/bonecli.py +289 -0
  3. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/const.py +56 -2
  4. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/filter.py +4 -1
  5. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/loader.py +21 -8
  6. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/mqtt.py +5 -1
  7. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/state_manager.py +8 -4
  8. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/util.py +16 -2
  9. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/manager.py +98 -32
  10. boneIO-0.8.0.dev3/boneio/modbus/__init__.py +5 -0
  11. boneIO-0.8.0.dev3/boneio/modbus/client.py +166 -0
  12. boneIO-0.8.0.dev3/boneio/modbus/cwt.json +34 -0
  13. boneIO-0.8.0.dev3/boneio/modbus/modbuscli.py +187 -0
  14. boneIO-0.8.0.dev3/boneio/modbus/orno-or-we-517.json +20 -0
  15. boneIO-0.8.0.dev3/boneio/modbus/sdm630.json +299 -0
  16. boneIO-0.8.0.dev1/boneio/sensor/modbus/__init__.py → boneIO-0.8.0.dev3/boneio/modbus/sensor.py +40 -74
  17. boneIO-0.8.0.dev3/boneio/modbus/socomec_e23.json +103 -0
  18. boneIO-0.8.0.dev3/boneio/modbus/utils.py +73 -0
  19. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/pcf.py +8 -3
  20. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/schema.yaml +15 -1
  21. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/temp/__init__.py +2 -1
  22. boneIO-0.8.0.dev3/boneio/version.py +2 -0
  23. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/pyproject.toml +3 -2
  24. boneIO-0.8.0.dev1/boneio/bonecli.py +0 -121
  25. boneIO-0.8.0.dev1/boneio/modbus.py +0 -104
  26. boneIO-0.8.0.dev1/boneio/sensor/modbus/sdm630.json +0 -300
  27. boneIO-0.8.0.dev1/boneio/version.py +0 -2
  28. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/LICENSE +0 -0
  29. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/README.md +0 -0
  30. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/__init__.py +0 -0
  31. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/cover.py +0 -0
  32. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/__init__.py +0 -0
  33. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/adc.yaml +0 -0
  34. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/binary_sensor.yaml +0 -0
  35. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/config.yaml +0 -0
  36. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/cover.yaml +0 -0
  37. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/event.yaml +0 -0
  38. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/event_all.yaml +0 -0
  39. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/led32x4A.yaml +0 -0
  40. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/output24x16A.yaml +0 -0
  41. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/output24x16A_v0.3.yaml +0 -0
  42. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/example_config/output32x5A.yaml +0 -0
  43. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/fonts/danube__.ttf +0 -0
  44. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/group/__init__.py +0 -0
  45. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/group/output.py +0 -0
  46. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/__init__.py +0 -0
  47. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/async_updater.py +0 -0
  48. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/click_timer.py +0 -0
  49. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/config.py +0 -0
  50. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/events.py +0 -0
  51. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/exceptions.py +0 -0
  52. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/gpio.py +0 -0
  53. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/ha_discovery.py +0 -0
  54. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/logger.py +0 -0
  55. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/oled.py +0 -0
  56. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/onewire/W1ThermSensor.py +0 -0
  57. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/onewire/__init__.py +0 -0
  58. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/onewire/ds2482.py +0 -0
  59. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/onewire/onewire.py +0 -0
  60. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/pcf8575.py +0 -0
  61. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/queue.py +0 -0
  62. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/sensor/ina_219_smbus.py +0 -0
  63. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/stats.py +0 -0
  64. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/timeperiod.py +0 -0
  65. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/helper/yaml_util.py +0 -0
  66. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/input/__init__.py +0 -0
  67. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/input/gpio.py +0 -0
  68. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/input/gpio_new.py +0 -0
  69. {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev3/boneio}/modbus/dts1964_3f.json +0 -0
  70. {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev3/boneio}/modbus/pt100.json +0 -0
  71. {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev3/boneio}/modbus/r4dcb08.json +0 -0
  72. {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev3/boneio}/modbus/sdm120.json +0 -0
  73. {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev3/boneio}/modbus/sofar.json +0 -0
  74. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/mqtt_client.py +0 -0
  75. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/oled.py +0 -0
  76. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/__init__.py +0 -0
  77. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/basic.py +0 -0
  78. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/gpio.py +0 -0
  79. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/mcp.py +0 -0
  80. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/relay/pca.py +0 -0
  81. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/runner.py +0 -0
  82. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/actions.yaml +0 -0
  83. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/actions_sensor.yaml +0 -0
  84. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/actions_switch.yaml +0 -0
  85. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/filters.yaml +0 -0
  86. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/filters_adc.yaml +0 -0
  87. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/id.yaml +0 -0
  88. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/temp_unit.yaml +0 -0
  89. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/schema/update_interval.yaml +0 -0
  90. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/__init__.py +0 -0
  91. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/adc.py +0 -0
  92. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/gpio.py +0 -0
  93. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/gpio_new.py +0 -0
  94. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/ina219.py +0 -0
  95. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/temp/dallas.py +0 -0
  96. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/temp/lm75.py +0 -0
  97. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/boneio/sensor/temp/mcp9808.py +0 -0
  98. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/tests/32_5_config.yaml +0 -0
  99. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/tests/bandit.yaml +0 -0
  100. {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev3}/tests/relay_32_5.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneIO
3
- Version: 0.8.0.dev1
3
+ Version: 0.8.0.dev3
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>
@@ -0,0 +1,289 @@
1
+ """Bonecli script."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ os.environ["W1THERMSENSOR_NO_KERNEL_MODULE"] = "1"
8
+
9
+ import argparse
10
+ import asyncio
11
+ import logging
12
+ import sys
13
+ from colorlog import ColoredFormatter
14
+ from yaml import MarkedYAMLError
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
+
20
+ from boneio.const import ACTION
21
+ from boneio.helper import load_config_from_file
22
+ from boneio.helper.exceptions import (
23
+ ConfigurationException,
24
+ RestartRequestException,
25
+ )
26
+ from boneio.helper.events import GracefulExit
27
+ from boneio.helper.logger import configure_logger
28
+ from boneio.runner import async_run
29
+ from boneio.version import __version__
30
+
31
+ TASK_CANCELATION_TIMEOUT = 1
32
+
33
+ _LOGGER = logging.getLogger(__name__)
34
+ logging.basicConfig(level=logging.INFO)
35
+ fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
36
+ datefmt = "%Y-%m-%d %H:%M:%S"
37
+ colorfmt = f"%(log_color)s{fmt}%(reset)s"
38
+ logging.getLogger().handlers[0].setFormatter(
39
+ ColoredFormatter(
40
+ colorfmt,
41
+ datefmt=datefmt,
42
+ reset=True,
43
+ log_colors={
44
+ "DEBUG": "cyan",
45
+ "INFO": "green",
46
+ "WARNING": "yellow",
47
+ "ERROR": "red",
48
+ "CRITICAL": "red",
49
+ },
50
+ )
51
+ )
52
+
53
+
54
+ def get_arguments() -> argparse.Namespace:
55
+ """Get parsed passed in arguments."""
56
+
57
+ parser = argparse.ArgumentParser(
58
+ description="boneIO app for BeagleBone Black.",
59
+ )
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(
70
+ "-c",
71
+ "--config",
72
+ metavar="path_to_config_dir",
73
+ default="./config.yaml",
74
+ help="File which contains boneIO configuration",
75
+ )
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)",
104
+ )
105
+ modbus_parser.add_argument(
106
+ "--baudrate",
107
+ type=int,
108
+ choices=[2400, 4800, 9600, 19200],
109
+ required=True,
110
+ help="Current baudrate",
111
+ )
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",
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__)
185
+ arguments = parser.parse_args()
186
+
187
+ return arguments
188
+
189
+
190
+ def run(
191
+ config: str, debug: int, mqttusername: str = "", mqttpassword: str = ""
192
+ ) -> int:
193
+ """Run BoneIO."""
194
+ _LOGGER.info("BoneIO %s starting.", __version__)
195
+ try:
196
+ _config = load_config_from_file(config_file=config)
197
+ if not _config:
198
+ _LOGGER.error("Config not loaded. Exiting.")
199
+ return 1
200
+ configure_logger(log_config=_config.get("logger"), debug=debug)
201
+ asyncio.run(
202
+ async_run(
203
+ config=_config,
204
+ config_file=config,
205
+ mqttusername=mqttusername,
206
+ mqttpassword=mqttpassword,
207
+ ),
208
+ )
209
+ return 0
210
+ except (RestartRequestException, GracefulExit) as err:
211
+ if err is not None:
212
+ _LOGGER.info(err)
213
+ return 0
214
+ except (ConfigurationException, MarkedYAMLError) as err:
215
+ _LOGGER.error("Failed to load config. %s Exiting.", err)
216
+ return 1
217
+
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
+
264
+ def main() -> int:
265
+ """Start boneIO."""
266
+
267
+ args = get_arguments()
268
+ debug = args.debug
269
+
270
+ exit_code = 0
271
+ if args.action == "run":
272
+ exit_code = run(
273
+ config=args.config,
274
+ mqttusername=args.mqttusername,
275
+ mqttpassword=args.mqttpassword,
276
+ debug=debug,
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
+
284
+ _LOGGER.info("Exiting with exit code %s", exit_code)
285
+ return exit_code
286
+
287
+
288
+ if __name__ == "__main__":
289
+ sys.exit(main())
@@ -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
+ }
@@ -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:
@@ -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)
@@ -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)
@@ -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