boneIO 0.2.2__tar.gz → 0.3.0__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.2.2/boneio.egg-info → boneio-0.3.0}/PKG-INFO +2 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio/bonecli.py +20 -13
- {boneio-0.2.2 → boneio-0.3.0}/boneio/const.py +11 -6
- {boneio-0.2.2 → boneio-0.3.0}/boneio/cover.py +7 -6
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/config.yaml +2 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/cover.yaml +2 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/output32x5A.yaml +110 -72
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/__init__.py +6 -1
- boneio-0.3.0/boneio/helper/config.py +47 -0
- boneio-0.3.0/boneio/helper/ds2482/__init__.py +10 -0
- boneio-0.3.0/boneio/helper/ds2482/ds2482.py +163 -0
- boneio-0.3.0/boneio/helper/ds2482/onewire.py +44 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/events.py +77 -2
- boneio-0.3.0/boneio/helper/exceptions.py +29 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/gpio.py +30 -6
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/loader.py +110 -74
- boneio-0.3.0/boneio/helper/timeperiod.py +185 -0
- boneio-0.3.0/boneio/helper/util.py +15 -0
- boneio-0.3.0/boneio/helper/yaml_util.py +306 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/input/gpio.py +13 -8
- {boneio-0.2.2 → boneio-0.3.0}/boneio/manager.py +121 -48
- {boneio-0.2.2 → boneio-0.3.0}/boneio/modbus.py +8 -3
- {boneio-0.2.2 → boneio-0.3.0}/boneio/mqtt_client.py +28 -7
- {boneio-0.2.2 → boneio-0.3.0}/boneio/oled.py +10 -10
- {boneio-0.2.2 → boneio-0.3.0}/boneio/relay/basic.py +5 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/relay/mcp.py +21 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio/runner.py +15 -5
- {boneio-0.2.2 → boneio-0.3.0}/boneio/schema/actions.yaml +1 -1
- {boneio-0.2.2 → boneio-0.3.0}/boneio/schema/actions_sensor.yaml +1 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/schema/actions_switch.yaml +1 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/schema/schema.yaml +168 -27
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/__init__.py +4 -1
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/adc.py +15 -3
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/gpio.py +4 -1
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/modbus/__init__.py +44 -35
- boneio-0.3.0/boneio/sensor/temp/__init__.py +76 -0
- boneio-0.3.0/boneio/sensor/temp/dallas.py +43 -0
- boneio-0.3.0/boneio/sensor/temp/lm75.py +11 -0
- boneio-0.3.0/boneio/sensor/temp/mcp9808.py +12 -0
- boneio-0.3.0/boneio/version.py +2 -0
- {boneio-0.2.2 → boneio-0.3.0/boneio.egg-info}/PKG-INFO +2 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio.egg-info/SOURCES.txt +11 -2
- {boneio-0.2.2 → boneio-0.3.0}/boneio.egg-info/requires.txt +2 -1
- {boneio-0.2.2 → boneio-0.3.0}/requirements.txt +1 -1
- {boneio-0.2.2 → boneio-0.3.0}/setup.py +2 -1
- boneio-0.2.2/boneio/helper/exceptions.py +0 -13
- boneio-0.2.2/boneio/helper/yaml.py +0 -64
- boneio-0.2.2/boneio/sensor/temp/__init__.py +0 -52
- boneio-0.2.2/boneio/version.py +0 -2
- {boneio-0.2.2 → boneio-0.3.0}/LICENSE +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/MANIFEST.in +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/README.md +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/__init__.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/__init__.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/adc.yaml +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/input.yaml +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/example_config/output24x16A.yaml +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/fonts/danube__.ttf +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/ha_discovery.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/logger.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/mqtt.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/oled.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/queue.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/state_manager.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/helper/stats.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/input/__init__.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/relay/__init__.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/relay/gpio.py +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/modbus/sdm120.json +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/modbus/sdm630.json +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio/sensor/modbus/sofar.json +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio.egg-info/dependency_links.txt +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio.egg-info/entry_points.txt +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/boneio.egg-info/top_level.txt +0 -0
- {boneio-0.2.2 → boneio-0.3.0}/setup.cfg +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python App for BoneIO
|
|
5
5
|
Home-page: https://github.com/boneIO-eu/app_bbb
|
|
6
|
-
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.
|
|
6
|
+
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.3.0.zip
|
|
7
7
|
License: GNU General Public License v3.0
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
@@ -8,9 +8,11 @@ from colorlog import ColoredFormatter
|
|
|
8
8
|
|
|
9
9
|
from boneio.const import ACTION
|
|
10
10
|
from boneio.helper import load_config_from_file
|
|
11
|
+
from boneio.helper.exceptions import ConfigurationException
|
|
11
12
|
from boneio.helper.logger import configure_logger
|
|
12
13
|
from boneio.runner import async_run
|
|
13
14
|
from boneio.version import __version__
|
|
15
|
+
from yaml import MarkedYAMLError
|
|
14
16
|
|
|
15
17
|
TASK_CANCELATION_TIMEOUT = 1
|
|
16
18
|
|
|
@@ -66,19 +68,24 @@ def get_arguments() -> argparse.Namespace:
|
|
|
66
68
|
|
|
67
69
|
def run(config: str, debug: int, mqttusername: str = "", mqttpassword: str = ""):
|
|
68
70
|
"""Run BoneIO."""
|
|
69
|
-
_LOGGER.info("BoneIO starting.")
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
_LOGGER.info("BoneIO %s starting.", __version__)
|
|
72
|
+
try:
|
|
73
|
+
_config = load_config_from_file(config_file=config)
|
|
74
|
+
if not _config:
|
|
75
|
+
_LOGGER.error("Config not loaded. Exiting.")
|
|
76
|
+
return 1
|
|
77
|
+
configure_logger(log_config=_config.get("logger"), debug=debug)
|
|
78
|
+
return asyncio.run(
|
|
79
|
+
async_run(
|
|
80
|
+
config=_config,
|
|
81
|
+
config_file=config,
|
|
82
|
+
mqttusername=mqttusername,
|
|
83
|
+
mqttpassword=mqttpassword,
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
except (ConfigurationException, MarkedYAMLError) as err:
|
|
87
|
+
_LOGGER.error("Failed to load config. %s Exiting.", err)
|
|
88
|
+
return 1
|
|
82
89
|
|
|
83
90
|
|
|
84
91
|
def main() -> int:
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
from datetime import timedelta
|
|
3
3
|
|
|
4
4
|
try:
|
|
5
|
-
from Adafruit_BBIO.GPIO import HIGH, LOW, BOTH, FALLING
|
|
5
|
+
from Adafruit_BBIO.GPIO import HIGH, LOW, BOTH, FALLING, RISING
|
|
6
6
|
except ModuleNotFoundError:
|
|
7
|
+
HIGH = "high"
|
|
8
|
+
LOW = "low"
|
|
9
|
+
BOTH = "both"
|
|
10
|
+
FALLING = "falling"
|
|
11
|
+
RISING = "rising"
|
|
7
12
|
pass
|
|
8
13
|
from typing_extensions import Literal
|
|
9
14
|
|
|
@@ -43,14 +48,12 @@ RESTORE_STATE = "restore_state"
|
|
|
43
48
|
MODEL = "model"
|
|
44
49
|
UARTS = {
|
|
45
50
|
"uart1": {ID: "/dev/ttyS1", TX: "P9.24", RX: "P9.26"},
|
|
51
|
+
"uart2": {ID: "/dev/ttyS2", TX: "P9.21", RX: "P9.22"},
|
|
52
|
+
"uart3": {ID: "/dev/ttyS3", TX: "P9.42", RX: None},
|
|
46
53
|
"uart4": {ID: "/dev/ttyS4", TX: "P9.13", RX: "P9.11"},
|
|
54
|
+
"uart5": {ID: "/dev/ttyS5", TX: "P8.37", RX: "P8.38"},
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
# TIMINGS FOR BUTTONS
|
|
50
|
-
DEBOUNCE_DURATION = timedelta(seconds=0.2)
|
|
51
|
-
LONG_PRESS_DURATION = timedelta(seconds=0.7)
|
|
52
|
-
DELAY_DURATION = 0.1
|
|
53
|
-
SECOND_DELAY_DURATION = 0.3
|
|
54
57
|
|
|
55
58
|
# HA CONSTS
|
|
56
59
|
HOMEASSISTANT = "homeassistant"
|
|
@@ -109,6 +112,8 @@ BINARY_SENSOR = "binary_sensor"
|
|
|
109
112
|
LM75 = "lm75"
|
|
110
113
|
MCP_TEMP_9808 = "mcp9808"
|
|
111
114
|
INPUT_SENSOR = "inputsensor"
|
|
115
|
+
DS2482 = "ds2482"
|
|
116
|
+
DALLAS = "dallas"
|
|
112
117
|
|
|
113
118
|
BASE = "base"
|
|
114
119
|
LENGTH = "length"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"""Cover module."""
|
|
2
2
|
import asyncio
|
|
3
3
|
import logging
|
|
4
|
-
from typing import
|
|
4
|
+
from typing import Callable
|
|
5
5
|
from boneio.const import CLOSE, COVER, IDLE, OPEN, OPENING, CLOSING, CLOSED, STOP
|
|
6
6
|
from boneio.helper.events import EventBus
|
|
7
7
|
from boneio.helper.mqtt import BasicMqtt
|
|
8
|
+
from boneio.helper.timeperiod import TimePeriod
|
|
8
9
|
from boneio.relay import MCPRelay
|
|
9
10
|
|
|
10
11
|
_LOGGER = logging.getLogger(__name__)
|
|
@@ -21,10 +22,10 @@ COVER_COMMANDS = {
|
|
|
21
22
|
class RelayHelper:
|
|
22
23
|
"""Relay helper for cover either open/close."""
|
|
23
24
|
|
|
24
|
-
def __init__(self, relay: MCPRelay, time:
|
|
25
|
+
def __init__(self, relay: MCPRelay, time: TimePeriod) -> None:
|
|
25
26
|
"""Initialize helper."""
|
|
26
27
|
self._relay = relay
|
|
27
|
-
self._steps = 100 / time
|
|
28
|
+
self._steps = 100 / time.total_seconds
|
|
28
29
|
|
|
29
30
|
@property
|
|
30
31
|
def relay(self) -> MCPRelay:
|
|
@@ -43,11 +44,11 @@ class Cover(BasicMqtt):
|
|
|
43
44
|
def __init__(
|
|
44
45
|
self,
|
|
45
46
|
id: str,
|
|
46
|
-
open_relay:
|
|
47
|
+
open_relay: MCPRelay,
|
|
47
48
|
close_relay: MCPRelay,
|
|
48
49
|
state_save: Callable,
|
|
49
|
-
open_time:
|
|
50
|
-
close_time:
|
|
50
|
+
open_time: TimePeriod,
|
|
51
|
+
close_time: TimePeriod,
|
|
51
52
|
event_bus: EventBus,
|
|
52
53
|
restored_state: int = 100,
|
|
53
54
|
**kwargs,
|
|
@@ -1,160 +1,198 @@
|
|
|
1
|
-
-
|
|
1
|
+
# mcp1 - upper left 8 relays
|
|
2
|
+
- id: OUT_01
|
|
2
3
|
kind: mcp
|
|
3
4
|
mcp_id: mcp1
|
|
4
5
|
pin: 0
|
|
5
6
|
output_type: light
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
- id: OUT_02
|
|
7
9
|
kind: mcp
|
|
8
10
|
mcp_id: mcp1
|
|
9
11
|
pin: 1
|
|
10
12
|
output_type: light
|
|
11
|
-
|
|
13
|
+
|
|
14
|
+
- id: OUT_03
|
|
12
15
|
kind: mcp
|
|
13
16
|
mcp_id: mcp1
|
|
14
17
|
pin: 2
|
|
15
18
|
output_type: light
|
|
16
|
-
|
|
19
|
+
|
|
20
|
+
- id: OUT_04
|
|
17
21
|
kind: mcp
|
|
18
22
|
mcp_id: mcp1
|
|
19
23
|
pin: 3
|
|
20
24
|
output_type: light
|
|
21
|
-
|
|
25
|
+
|
|
26
|
+
- id: OUT_05
|
|
22
27
|
kind: mcp
|
|
23
28
|
mcp_id: mcp1
|
|
24
29
|
pin: 4
|
|
25
30
|
output_type: light
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
- id: OUT_06
|
|
27
33
|
kind: mcp
|
|
28
34
|
mcp_id: mcp1
|
|
29
35
|
pin: 5
|
|
30
36
|
output_type: light
|
|
31
|
-
|
|
37
|
+
|
|
38
|
+
- id: OUT_07
|
|
32
39
|
kind: mcp
|
|
33
40
|
mcp_id: mcp1
|
|
34
41
|
pin: 6
|
|
35
42
|
output_type: light
|
|
36
|
-
|
|
43
|
+
|
|
44
|
+
- id: OUT_08
|
|
37
45
|
kind: mcp
|
|
38
46
|
mcp_id: mcp1
|
|
39
47
|
pin: 7
|
|
40
48
|
output_type: light
|
|
41
|
-
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# mcp2 - upper right 8 relays
|
|
52
|
+
- id: OUT_09
|
|
53
|
+
kind: mcp
|
|
54
|
+
mcp_id: mcp2
|
|
55
|
+
pin: 0
|
|
56
|
+
output_type: light
|
|
57
|
+
|
|
58
|
+
- id: OUT_10
|
|
59
|
+
kind: mcp
|
|
60
|
+
mcp_id: mcp2
|
|
61
|
+
pin: 1
|
|
62
|
+
output_type: light
|
|
63
|
+
|
|
64
|
+
- id: OUT_11
|
|
65
|
+
kind: mcp
|
|
66
|
+
mcp_id: mcp2
|
|
67
|
+
pin: 2
|
|
68
|
+
output_type: light
|
|
69
|
+
|
|
70
|
+
- id: OUT_12
|
|
71
|
+
kind: mcp
|
|
72
|
+
mcp_id: mcp2
|
|
73
|
+
pin: 3
|
|
74
|
+
output_type: light
|
|
75
|
+
|
|
76
|
+
- id: OUT_13
|
|
77
|
+
kind: mcp
|
|
78
|
+
mcp_id: mcp2
|
|
79
|
+
pin: 4
|
|
80
|
+
output_type: light
|
|
81
|
+
|
|
82
|
+
- id: OUT_14
|
|
83
|
+
kind: mcp
|
|
84
|
+
mcp_id: mcp2
|
|
85
|
+
pin: 5
|
|
86
|
+
output_type: light
|
|
87
|
+
|
|
88
|
+
- id: OUT_15
|
|
89
|
+
kind: mcp
|
|
90
|
+
mcp_id: mcp2
|
|
91
|
+
pin: 6
|
|
92
|
+
output_type: light
|
|
93
|
+
|
|
94
|
+
- id: OUT_16
|
|
95
|
+
kind: mcp
|
|
96
|
+
mcp_id: mcp2
|
|
97
|
+
pin: 7
|
|
98
|
+
output_type: light
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# mcp1 - lower left 8 relays
|
|
102
|
+
- id: OUT_17
|
|
42
103
|
kind: mcp
|
|
43
104
|
mcp_id: mcp1
|
|
44
105
|
pin: 8
|
|
45
106
|
output_type: light
|
|
46
|
-
|
|
107
|
+
|
|
108
|
+
- id: OUT_18
|
|
47
109
|
kind: mcp
|
|
48
110
|
mcp_id: mcp1
|
|
49
111
|
pin: 9
|
|
50
112
|
output_type: light
|
|
51
|
-
|
|
113
|
+
|
|
114
|
+
- id: OUT_19
|
|
52
115
|
kind: mcp
|
|
53
116
|
mcp_id: mcp1
|
|
54
117
|
pin: 10
|
|
55
118
|
output_type: light
|
|
56
|
-
|
|
119
|
+
|
|
120
|
+
- id: OUT_20
|
|
57
121
|
kind: mcp
|
|
58
122
|
mcp_id: mcp1
|
|
59
123
|
pin: 11
|
|
60
124
|
output_type: light
|
|
61
|
-
|
|
125
|
+
|
|
126
|
+
- id: OUT_21
|
|
62
127
|
kind: mcp
|
|
63
128
|
mcp_id: mcp1
|
|
64
129
|
pin: 12
|
|
65
130
|
output_type: light
|
|
66
|
-
|
|
131
|
+
|
|
132
|
+
- id: OUT_22
|
|
67
133
|
kind: mcp
|
|
68
134
|
mcp_id: mcp1
|
|
69
135
|
pin: 13
|
|
70
136
|
output_type: light
|
|
71
|
-
|
|
137
|
+
|
|
138
|
+
- id: OUT_23
|
|
72
139
|
kind: mcp
|
|
73
140
|
mcp_id: mcp1
|
|
74
141
|
pin: 14
|
|
75
142
|
output_type: light
|
|
76
|
-
|
|
143
|
+
|
|
144
|
+
- id: OUT_24
|
|
77
145
|
kind: mcp
|
|
78
146
|
mcp_id: mcp1
|
|
79
147
|
pin: 15
|
|
80
148
|
output_type: light
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
output_type: switch
|
|
86
|
-
- id: switch 2
|
|
87
|
-
kind: mcp
|
|
88
|
-
mcp_id: mcp2
|
|
89
|
-
pin: 1
|
|
90
|
-
output_type: switch
|
|
91
|
-
- id: switch 3
|
|
92
|
-
kind: mcp
|
|
93
|
-
mcp_id: mcp2
|
|
94
|
-
pin: 2
|
|
95
|
-
output_type: switch
|
|
96
|
-
- id: switch 4
|
|
97
|
-
kind: mcp
|
|
98
|
-
mcp_id: mcp2
|
|
99
|
-
pin: 3
|
|
100
|
-
output_type: switch
|
|
101
|
-
- id: switch 5
|
|
102
|
-
kind: mcp
|
|
103
|
-
mcp_id: mcp2
|
|
104
|
-
pin: 4
|
|
105
|
-
output_type: switch
|
|
106
|
-
- id: switch 6
|
|
107
|
-
kind: mcp
|
|
108
|
-
mcp_id: mcp2
|
|
109
|
-
pin: 5
|
|
110
|
-
output_type: switch
|
|
111
|
-
- id: switch 7
|
|
112
|
-
kind: mcp
|
|
113
|
-
mcp_id: mcp2
|
|
114
|
-
pin: 6
|
|
115
|
-
output_type: switch
|
|
116
|
-
- id: switch 8
|
|
117
|
-
kind: mcp
|
|
118
|
-
mcp_id: mcp2
|
|
119
|
-
pin: 7
|
|
120
|
-
output_type: switch
|
|
121
|
-
- id: switch 9
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# mcp2 - lower right 8 relays
|
|
152
|
+
- id: OUT_25
|
|
122
153
|
kind: mcp
|
|
123
154
|
mcp_id: mcp2
|
|
124
155
|
pin: 8
|
|
125
|
-
output_type:
|
|
126
|
-
|
|
156
|
+
output_type: light
|
|
157
|
+
|
|
158
|
+
- id: OUT_26
|
|
127
159
|
kind: mcp
|
|
128
160
|
mcp_id: mcp2
|
|
129
161
|
pin: 9
|
|
130
|
-
output_type:
|
|
131
|
-
|
|
162
|
+
output_type: light
|
|
163
|
+
|
|
164
|
+
- id: OUT_27
|
|
132
165
|
kind: mcp
|
|
133
166
|
mcp_id: mcp2
|
|
134
167
|
pin: 10
|
|
135
|
-
output_type:
|
|
136
|
-
|
|
168
|
+
output_type: light
|
|
169
|
+
|
|
170
|
+
- id: OUT_28
|
|
137
171
|
kind: mcp
|
|
138
172
|
mcp_id: mcp2
|
|
139
173
|
pin: 11
|
|
140
|
-
output_type:
|
|
141
|
-
|
|
174
|
+
output_type: light
|
|
175
|
+
|
|
176
|
+
- id: OUT_29
|
|
142
177
|
kind: mcp
|
|
143
178
|
mcp_id: mcp2
|
|
144
179
|
pin: 12
|
|
145
|
-
output_type:
|
|
146
|
-
|
|
180
|
+
output_type: light
|
|
181
|
+
|
|
182
|
+
- id: OUT_30
|
|
147
183
|
kind: mcp
|
|
148
184
|
mcp_id: mcp2
|
|
149
185
|
pin: 13
|
|
150
|
-
output_type:
|
|
151
|
-
|
|
186
|
+
output_type: light
|
|
187
|
+
|
|
188
|
+
- id: OUT_31
|
|
152
189
|
kind: mcp
|
|
153
190
|
mcp_id: mcp2
|
|
154
191
|
pin: 14
|
|
155
|
-
output_type:
|
|
156
|
-
|
|
192
|
+
output_type: light
|
|
193
|
+
|
|
194
|
+
- id: OUT_32
|
|
157
195
|
kind: mcp
|
|
158
196
|
mcp_id: mcp2
|
|
159
197
|
pin: 15
|
|
160
|
-
output_type:
|
|
198
|
+
output_type: light
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Helper dir for BoneIO."""
|
|
2
|
+
|
|
2
3
|
from boneio.helper.gpio import (
|
|
3
4
|
edge_detect,
|
|
4
5
|
setup_input,
|
|
@@ -11,7 +12,7 @@ from boneio.helper.gpio import (
|
|
|
11
12
|
from boneio.helper.oled import make_font
|
|
12
13
|
from boneio.helper.mqtt import BasicMqtt
|
|
13
14
|
from boneio.helper.stats import HostData, host_stats
|
|
14
|
-
from boneio.helper.
|
|
15
|
+
from boneio.helper.yaml_util import (
|
|
15
16
|
CustomValidator,
|
|
16
17
|
load_yaml_file,
|
|
17
18
|
schema_file,
|
|
@@ -31,6 +32,7 @@ from boneio.helper.ha_discovery import (
|
|
|
31
32
|
)
|
|
32
33
|
from boneio.helper.exceptions import GPIOInputException, I2CError
|
|
33
34
|
from boneio.helper.queue import UniqueQueue
|
|
35
|
+
from boneio.helper.timeperiod import TimePeriod
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
__all__ = [
|
|
@@ -62,4 +64,7 @@ __all__ = [
|
|
|
62
64
|
"schema_file",
|
|
63
65
|
"load_config_from_string",
|
|
64
66
|
"load_config_from_file",
|
|
67
|
+
"TimePeriod",
|
|
68
|
+
"callback",
|
|
69
|
+
"is_callback",
|
|
65
70
|
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module to provide basic config options.
|
|
3
|
+
"""
|
|
4
|
+
from boneio.const import BONEIO, HOMEASSISTANT
|
|
5
|
+
from _collections_abc import dict_values
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ConfigHelper:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
topic_prefix: str = BONEIO,
|
|
12
|
+
ha_discovery: bool = True,
|
|
13
|
+
ha_discovery_prefix: str = HOMEASSISTANT,
|
|
14
|
+
):
|
|
15
|
+
self._topic_prefix = topic_prefix
|
|
16
|
+
self._ha_discovery = ha_discovery
|
|
17
|
+
self._ha_discovery_prefix = ha_discovery_prefix
|
|
18
|
+
self._autodiscovery_messages = {}
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def topic_prefix(self) -> str:
|
|
22
|
+
return self._topic_prefix
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def ha_discovery(self) -> bool:
|
|
26
|
+
return self._ha_discovery
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def ha_discovery_prefix(self) -> str:
|
|
30
|
+
return self._ha_discovery_prefix
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def cmd_topic_prefix(self) -> str:
|
|
34
|
+
return f"{self.topic_prefix}/cmd/"
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def subscribe_topic(self) -> str:
|
|
38
|
+
return f"{self.cmd_topic_prefix}+/+/#"
|
|
39
|
+
|
|
40
|
+
def add_autodiscovery_msg(self, topic: str, payload: str):
|
|
41
|
+
"""Add autodiscovery message."""
|
|
42
|
+
self._autodiscovery_messages[topic] = {"topic": topic, "payload": payload}
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def autodiscovery_msgs(self) -> dict_values:
|
|
46
|
+
"""Get autodiscovery messages"""
|
|
47
|
+
return self._autodiscovery_messages.values()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Helper dir for DS2482."""
|
|
2
|
+
from boneio.helper.ds2482.ds2482 import DS2482, DS2482_ADDRESS
|
|
3
|
+
from boneio.helper.ds2482.onewire import OneWire, OneWireBus
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def ds_address(rom: bytes) -> int:
|
|
7
|
+
return int.from_bytes(rom, "little")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__all__ = ["DS2482", "OneWire", "OneWireBus", "ds_address", "DS2482_ADDRESS"]
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""DS2482 base class.
|
|
2
|
+
Module by https://github.com/fgervais/ds2482
|
|
3
|
+
"""
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import adafruit_bus_device.i2c_device as i2c_device
|
|
7
|
+
|
|
8
|
+
# Default i2c address (AD0 = GND, AD1 = GND)
|
|
9
|
+
DS2482_ADDRESS = 0x18
|
|
10
|
+
|
|
11
|
+
# DS2482 device commands
|
|
12
|
+
COMMAND_DEVICE_RESET = 0xF0
|
|
13
|
+
COMMAND_SET_POINTER = 0xE1
|
|
14
|
+
COMMAND_WRITE_CONFIG = 0xD2
|
|
15
|
+
COMMAND_1W_RESET = 0xB4
|
|
16
|
+
COMMAND_1W_SINGLE_BIT = 0x87
|
|
17
|
+
COMMAND_1W_WRITE_BYTE = 0xA5
|
|
18
|
+
COMMAND_1W_READ_BYTE = 0x96
|
|
19
|
+
COMMAND_1W_TRIPLET = 0x78
|
|
20
|
+
|
|
21
|
+
# DS2482 read pointer codes
|
|
22
|
+
POINTER_STATUS = 0xF0
|
|
23
|
+
POINTER_DATA = 0xE1
|
|
24
|
+
POINTER_CONFIG = 0xC3
|
|
25
|
+
|
|
26
|
+
# DS2482 configuration register
|
|
27
|
+
CONFIG_ACTIVE_PULLUP = 0x01
|
|
28
|
+
CONFIG_STRONG_PULLUP = 0x04
|
|
29
|
+
CONFIG_1W_OVERDRIVE = 0x08
|
|
30
|
+
|
|
31
|
+
CONFIG_MASK = 0x0F
|
|
32
|
+
|
|
33
|
+
# DS2482 status register
|
|
34
|
+
STATUS_1W_BUSY = 0x01
|
|
35
|
+
STATUS_PRESENCE_PULSE = 0x02
|
|
36
|
+
STATUT_SHORT_DETECTED = 0x04
|
|
37
|
+
STATUS_LOGIC_LEVEL = 0x08
|
|
38
|
+
STATUS_DEVICE_RESET = 0x10
|
|
39
|
+
STATUS_SINGLE_BIT = 0x20
|
|
40
|
+
STATUS_TRIPLET_BIT = 0x40
|
|
41
|
+
STATUS_BRANCH_TAKEN = 0x80
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class DS2482:
|
|
45
|
+
def __init__(self, i2c, address=DS2482_ADDRESS, active_pullup=False):
|
|
46
|
+
self._i2c = i2c_device.I2CDevice(i2c, address)
|
|
47
|
+
self.device_reset()
|
|
48
|
+
if active_pullup:
|
|
49
|
+
self.device_config = CONFIG_ACTIVE_PULLUP
|
|
50
|
+
|
|
51
|
+
# 1-Wire bus busy with STRONG_PULLUP
|
|
52
|
+
self._bus_busy = time.monotonic()
|
|
53
|
+
|
|
54
|
+
def device_reset(self):
|
|
55
|
+
"""Terminate any 1-wire communication and reset the DS2482"""
|
|
56
|
+
with self._i2c as i2c:
|
|
57
|
+
i2c.write(bytes([COMMAND_DEVICE_RESET]))
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def device_status(self):
|
|
61
|
+
with self._i2c as i2c:
|
|
62
|
+
buf = bytearray([COMMAND_SET_POINTER, POINTER_STATUS])
|
|
63
|
+
i2c.write_then_readinto(buf, buf, in_end=1)
|
|
64
|
+
return buf[0]
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def device_config(self):
|
|
68
|
+
with self._i2c as i2c:
|
|
69
|
+
buf = bytearray([COMMAND_SET_POINTER, POINTER_CONFIG])
|
|
70
|
+
i2c.write_then_readinto(buf, buf, in_end=1)
|
|
71
|
+
return buf[0] & 0x0F
|
|
72
|
+
|
|
73
|
+
@device_config.setter
|
|
74
|
+
def device_config(self, config):
|
|
75
|
+
with self._i2c as i2c:
|
|
76
|
+
i2c.write(
|
|
77
|
+
bytes([COMMAND_WRITE_CONFIG, (config & 0x0F) | ((~config << 4) & 0xF0)])
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def reset(self):
|
|
81
|
+
with self._i2c as i2c:
|
|
82
|
+
buf = bytearray([COMMAND_1W_RESET])
|
|
83
|
+
i2c.write(buf)
|
|
84
|
+
while True:
|
|
85
|
+
i2c.readinto(buf)
|
|
86
|
+
if not buf[0] & STATUS_1W_BUSY:
|
|
87
|
+
break
|
|
88
|
+
time.sleep(0.001)
|
|
89
|
+
return not buf[0] & STATUS_PRESENCE_PULSE
|
|
90
|
+
|
|
91
|
+
def single_bit(self, bit=1, strong_pullup=False, busy=None):
|
|
92
|
+
with self._i2c as i2c:
|
|
93
|
+
buf = bytearray(2)
|
|
94
|
+
if strong_pullup:
|
|
95
|
+
buf[0:2] = [COMMAND_SET_POINTER, POINTER_CONFIG]
|
|
96
|
+
i2c.write_then_readinto(buf, buf, in_start=1)
|
|
97
|
+
buf[0] = COMMAND_WRITE_CONFIG
|
|
98
|
+
buf[1] = buf[1] & CONFIG_MASK | CONFIG_STRONG_PULLUP
|
|
99
|
+
buf[1] |= (~buf[1] << 4) & 0xFF
|
|
100
|
+
i2c.write(buf)
|
|
101
|
+
buf[0:2] = [COMMAND_1W_SINGLE_BIT, 0x80 if bit else 0x00]
|
|
102
|
+
i2c.write(buf)
|
|
103
|
+
while True:
|
|
104
|
+
i2c.readinto(buf, end=1)
|
|
105
|
+
if not buf[0] & STATUS_1W_BUSY:
|
|
106
|
+
break
|
|
107
|
+
time.sleep(0.001)
|
|
108
|
+
if busy:
|
|
109
|
+
self._bus_busy = time.monotonic() + busy
|
|
110
|
+
return buf[0] & STATUS_SINGLE_BIT != 0
|
|
111
|
+
|
|
112
|
+
def write_byte(self, data, strong_pullup=False, busy=None):
|
|
113
|
+
with self._i2c as i2c:
|
|
114
|
+
buf = bytearray(2)
|
|
115
|
+
if strong_pullup:
|
|
116
|
+
buf[0:2] = [COMMAND_SET_POINTER, POINTER_CONFIG]
|
|
117
|
+
i2c.write_then_readinto(buf, buf, in_start=1)
|
|
118
|
+
buf[0] = COMMAND_WRITE_CONFIG
|
|
119
|
+
buf[1] = buf[1] & CONFIG_MASK | CONFIG_STRONG_PULLUP
|
|
120
|
+
buf[1] |= (~buf[1] << 4) & 0xFF
|
|
121
|
+
i2c.write(buf)
|
|
122
|
+
buf[0:2] = [COMMAND_1W_WRITE_BYTE, data]
|
|
123
|
+
i2c.write(buf)
|
|
124
|
+
while True:
|
|
125
|
+
i2c.readinto(buf, end=1)
|
|
126
|
+
if buf[0] & STATUS_1W_BUSY == 0:
|
|
127
|
+
break
|
|
128
|
+
time.sleep(0.001)
|
|
129
|
+
if busy:
|
|
130
|
+
self._bus_busy = time.monotonic() + busy
|
|
131
|
+
|
|
132
|
+
def read_byte(self):
|
|
133
|
+
with self._i2c as i2c:
|
|
134
|
+
buf = bytearray([COMMAND_1W_READ_BYTE, 0x00])
|
|
135
|
+
i2c.write(buf, end=1)
|
|
136
|
+
while True:
|
|
137
|
+
i2c.readinto(buf, end=1)
|
|
138
|
+
if not buf[0] & STATUS_1W_BUSY:
|
|
139
|
+
break
|
|
140
|
+
time.sleep(0.001)
|
|
141
|
+
buf[0:2] = [COMMAND_SET_POINTER, POINTER_DATA]
|
|
142
|
+
i2c.write_then_readinto(buf, buf, in_end=1)
|
|
143
|
+
return buf[0]
|
|
144
|
+
|
|
145
|
+
def wait_ready(self):
|
|
146
|
+
while True:
|
|
147
|
+
t = self._bus_busy - time.monotonic()
|
|
148
|
+
if t > 0:
|
|
149
|
+
time.sleep(t)
|
|
150
|
+
else:
|
|
151
|
+
break
|
|
152
|
+
with self._i2c as i2c:
|
|
153
|
+
buf = bytearray([COMMAND_SET_POINTER, POINTER_STATUS])
|
|
154
|
+
i2c.write(buf)
|
|
155
|
+
while True:
|
|
156
|
+
i2c.readinto(buf, end=1)
|
|
157
|
+
if not buf[0] & STATUS_1W_BUSY:
|
|
158
|
+
break
|
|
159
|
+
time.sleep(0.001)
|
|
160
|
+
return buf[0]
|
|
161
|
+
|
|
162
|
+
def triplet(self, dir):
|
|
163
|
+
pass
|