boneIO 0.8.0.dev1__tar.gz → 0.8.0.dev2__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.
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/PKG-INFO +1 -1
- boneIO-0.8.0.dev2/boneio/bonecli.py +258 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/const.py +56 -2
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/filter.py +4 -1
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/loader.py +21 -8
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/mqtt.py +5 -1
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/state_manager.py +8 -4
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/util.py +16 -2
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/manager.py +98 -32
- boneIO-0.8.0.dev2/boneio/modbus/__init__.py +5 -0
- boneIO-0.8.0.dev2/boneio/modbus/client.py +166 -0
- boneIO-0.8.0.dev2/boneio/modbus/cwt.json +34 -0
- boneIO-0.8.0.dev2/boneio/modbus/modbuscli.py +175 -0
- boneIO-0.8.0.dev2/boneio/modbus/orno-or-we-517.json +20 -0
- boneIO-0.8.0.dev2/boneio/modbus/sdm630.json +299 -0
- boneIO-0.8.0.dev1/boneio/sensor/modbus/__init__.py → boneIO-0.8.0.dev2/boneio/modbus/sensor.py +40 -74
- boneIO-0.8.0.dev2/boneio/modbus/socomec_e23.json +103 -0
- boneIO-0.8.0.dev2/boneio/modbus/utils.py +73 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/pcf.py +8 -3
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/schema.yaml +15 -1
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/temp/__init__.py +2 -1
- boneIO-0.8.0.dev2/boneio/version.py +2 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/pyproject.toml +3 -2
- boneIO-0.8.0.dev1/boneio/bonecli.py +0 -121
- boneIO-0.8.0.dev1/boneio/modbus.py +0 -104
- boneIO-0.8.0.dev1/boneio/sensor/modbus/sdm630.json +0 -300
- boneIO-0.8.0.dev1/boneio/version.py +0 -2
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/LICENSE +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/README.md +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/cover.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/adc.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/binary_sensor.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/config.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/cover.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/event.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/event_all.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/led32x4A.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/output24x16A.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/output24x16A_v0.3.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/example_config/output32x5A.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/fonts/danube__.ttf +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/group/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/group/output.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/async_updater.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/click_timer.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/config.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/events.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/exceptions.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/gpio.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/ha_discovery.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/logger.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/oled.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/onewire/W1ThermSensor.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/onewire/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/onewire/ds2482.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/onewire/onewire.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/pcf8575.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/queue.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/sensor/ina_219_smbus.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/stats.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/timeperiod.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/helper/yaml_util.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/input/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/input/gpio.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/input/gpio_new.py +0 -0
- {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev2/boneio}/modbus/dts1964_3f.json +0 -0
- {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev2/boneio}/modbus/pt100.json +0 -0
- {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev2/boneio}/modbus/r4dcb08.json +0 -0
- {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev2/boneio}/modbus/sdm120.json +0 -0
- {boneIO-0.8.0.dev1/boneio/sensor → boneIO-0.8.0.dev2/boneio}/modbus/sofar.json +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/mqtt_client.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/oled.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/basic.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/gpio.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/mcp.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/relay/pca.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/runner.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/actions.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/actions_sensor.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/actions_switch.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/filters.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/filters_adc.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/id.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/temp_unit.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/schema/update_interval.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/__init__.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/adc.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/gpio.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/gpio_new.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/ina219.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/temp/dallas.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/temp/lm75.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/boneio/sensor/temp/mcp9808.py +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/tests/32_5_config.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/tests/bandit.yaml +0 -0
- {boneIO-0.8.0.dev1 → boneIO-0.8.0.dev2}/tests/relay_32_5.py +0 -0
|
@@ -0,0 +1,258 @@
|
|
|
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_sub_parser = modbus_parser.add_subparsers(
|
|
114
|
+
dest="modbus_action", required=True
|
|
115
|
+
)
|
|
116
|
+
set_modbus_parser = modbus_sub_parser.add_parser("set")
|
|
117
|
+
set_modbus_parser.add_argument(
|
|
118
|
+
"--device",
|
|
119
|
+
type=str,
|
|
120
|
+
choices=["cwt"],
|
|
121
|
+
help="Choose device to set modbus address/baudrate",
|
|
122
|
+
required=True,
|
|
123
|
+
)
|
|
124
|
+
set_modbus_parser_group = set_modbus_parser.add_mutually_exclusive_group()
|
|
125
|
+
set_modbus_parser_group.add_argument(
|
|
126
|
+
"--new-address",
|
|
127
|
+
type=lambda x: int(x, 0),
|
|
128
|
+
help="Set new address (hex or integer / 1 - 253/)",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
set_modbus_parser_group.add_argument(
|
|
132
|
+
"--new-baudrate",
|
|
133
|
+
type=int,
|
|
134
|
+
choices=[2400, 4800, 9600, 19200],
|
|
135
|
+
help="Choose new baudrate to set",
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
get_modbus_parser = modbus_sub_parser.add_parser("get")
|
|
139
|
+
get_modbus_parser.add_argument(
|
|
140
|
+
"--register-address",
|
|
141
|
+
type=int,
|
|
142
|
+
help="Register address",
|
|
143
|
+
required=True,
|
|
144
|
+
)
|
|
145
|
+
get_modbus_parser.add_argument(
|
|
146
|
+
"--register-type",
|
|
147
|
+
type=str,
|
|
148
|
+
choices=["input", "holding"],
|
|
149
|
+
help="Register type",
|
|
150
|
+
required=True,
|
|
151
|
+
)
|
|
152
|
+
get_modbus_parser.add_argument(
|
|
153
|
+
"--value-type",
|
|
154
|
+
type=str,
|
|
155
|
+
choices=VALUE_TYPES.keys(),
|
|
156
|
+
help="Value types",
|
|
157
|
+
required=True,
|
|
158
|
+
)
|
|
159
|
+
parser.add_argument("--version", action="version", version=__version__)
|
|
160
|
+
arguments = parser.parse_args()
|
|
161
|
+
|
|
162
|
+
return arguments
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def run(
|
|
166
|
+
config: str, debug: int, mqttusername: str = "", mqttpassword: str = ""
|
|
167
|
+
) -> int:
|
|
168
|
+
"""Run BoneIO."""
|
|
169
|
+
_LOGGER.info("BoneIO %s starting.", __version__)
|
|
170
|
+
try:
|
|
171
|
+
_config = load_config_from_file(config_file=config)
|
|
172
|
+
if not _config:
|
|
173
|
+
_LOGGER.error("Config not loaded. Exiting.")
|
|
174
|
+
return 1
|
|
175
|
+
configure_logger(log_config=_config.get("logger"), debug=debug)
|
|
176
|
+
asyncio.run(
|
|
177
|
+
async_run(
|
|
178
|
+
config=_config,
|
|
179
|
+
config_file=config,
|
|
180
|
+
mqttusername=mqttusername,
|
|
181
|
+
mqttpassword=mqttpassword,
|
|
182
|
+
),
|
|
183
|
+
)
|
|
184
|
+
return 0
|
|
185
|
+
except (RestartRequestException, GracefulExit) as err:
|
|
186
|
+
if err is not None:
|
|
187
|
+
_LOGGER.info(err)
|
|
188
|
+
return 0
|
|
189
|
+
except (ConfigurationException, MarkedYAMLError) as err:
|
|
190
|
+
_LOGGER.error("Failed to load config. %s Exiting.", err)
|
|
191
|
+
return 1
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def run_modbus_command(
|
|
195
|
+
args: argparse.Namespace,
|
|
196
|
+
) -> int:
|
|
197
|
+
"""Run BoneIO."""
|
|
198
|
+
_LOGGER.info("BoneIO %s starting.", __version__)
|
|
199
|
+
try:
|
|
200
|
+
configure_logger(log_config={}, debug=args.debug)
|
|
201
|
+
if args.modbus_action == "set":
|
|
202
|
+
ret = asyncio.run(
|
|
203
|
+
async_run_modbus_set(
|
|
204
|
+
device=args.device,
|
|
205
|
+
uart=args.uart,
|
|
206
|
+
address=args.address,
|
|
207
|
+
baudrate=args.baudrate,
|
|
208
|
+
new_baudrate=args.new_baudrate,
|
|
209
|
+
new_address=args.new_address,
|
|
210
|
+
),
|
|
211
|
+
)
|
|
212
|
+
else:
|
|
213
|
+
ret = asyncio.run(
|
|
214
|
+
async_run_modbus_get(
|
|
215
|
+
uart=args.uart,
|
|
216
|
+
device_address=args.address,
|
|
217
|
+
baudrate=args.baudrate,
|
|
218
|
+
register_address=args.register_address,
|
|
219
|
+
register_type=args.register_type,
|
|
220
|
+
value_type=args.value_type,
|
|
221
|
+
),
|
|
222
|
+
)
|
|
223
|
+
return ret
|
|
224
|
+
except (RestartRequestException, GracefulExit) as err:
|
|
225
|
+
if err is not None:
|
|
226
|
+
_LOGGER.info(err)
|
|
227
|
+
return 0
|
|
228
|
+
except (ConfigurationException, MarkedYAMLError) as err:
|
|
229
|
+
_LOGGER.error("Failed to load config. %s Exiting.", err)
|
|
230
|
+
return 1
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def main() -> int:
|
|
234
|
+
"""Start boneIO."""
|
|
235
|
+
|
|
236
|
+
args = get_arguments()
|
|
237
|
+
debug = args.debug
|
|
238
|
+
|
|
239
|
+
exit_code = 0
|
|
240
|
+
if args.action == "run":
|
|
241
|
+
exit_code = run(
|
|
242
|
+
config=args.config,
|
|
243
|
+
mqttusername=args.mqttusername,
|
|
244
|
+
mqttpassword=args.mqttpassword,
|
|
245
|
+
debug=debug,
|
|
246
|
+
)
|
|
247
|
+
elif args.action == "modbus":
|
|
248
|
+
_LOGGER.info("BoneIO Modbus helper %s .", __version__)
|
|
249
|
+
exit_code = run_modbus_command(
|
|
250
|
+
args=args,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
_LOGGER.info("Exiting with exit code %s", exit_code)
|
|
254
|
+
return exit_code
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
if __name__ == "__main__":
|
|
258
|
+
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 = {
|
|
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 = "
|
|
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.
|
|
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(
|
|
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,
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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[
|
|
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(
|
|
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(
|
|
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
|
-
|
|
21
|
-
|
|
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
|