boneIO 0.7.0.dev6__tar.gz → 0.8.0.dev1__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.7.0.dev6 → boneIO-0.8.0.dev1}/PKG-INFO +1 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/bonecli.py +1 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/const.py +3 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/binary_sensor.yaml +2 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/config.yaml +1 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/event.yaml +2 -0
- boneIO-0.8.0.dev1/boneio/example_config/event_all.yaml +186 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/group/output.py +13 -18
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/__init__.py +2 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/async_updater.py +3 -3
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/click_timer.py +8 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/events.py +21 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/gpio.py +53 -17
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/ha_discovery.py +22 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/loader.py +78 -82
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/mqtt.py +3 -1
- boneIO-0.8.0.dev1/boneio/helper/sensor/ina_219_smbus.py +167 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/state_manager.py +13 -3
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/stats.py +29 -10
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/util.py +6 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/yaml_util.py +1 -1
- boneIO-0.8.0.dev1/boneio/input/__init__.py +7 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/input/gpio.py +2 -8
- boneIO-0.7.0.dev6/boneio/input/gpio_beta.py → boneIO-0.8.0.dev1/boneio/input/gpio_new.py +24 -34
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/manager.py +52 -19
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/modbus.py +12 -24
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/mqtt_client.py +4 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/oled.py +24 -16
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/basic.py +42 -18
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/mcp.py +7 -18
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/pca.py +11 -70
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/pcf.py +5 -13
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/runner.py +5 -1
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/actions_sensor.yaml +0 -2
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/actions_switch.yaml +0 -2
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/schema.yaml +117 -34
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/__init__.py +6 -4
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/gpio.py +2 -5
- boneIO-0.7.0.dev6/boneio/sensor/gpio_beta.py → boneIO-0.8.0.dev1/boneio/sensor/gpio_new.py +5 -8
- boneIO-0.8.0.dev1/boneio/sensor/ina219.py +107 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/__init__.py +4 -3
- boneIO-0.8.0.dev1/boneio/version.py +2 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/pyproject.toml +1 -1
- boneIO-0.7.0.dev6/boneio/input/__init__.py +0 -7
- boneIO-0.7.0.dev6/boneio/version.py +0 -2
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/LICENSE +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/README.md +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/__init__.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/cover.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/__init__.py +0 -0
- /boneIO-0.7.0.dev6/boneio/example_config/adc_v0_4.yaml → /boneIO-0.8.0.dev1/boneio/example_config/adc.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/cover.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/led32x4A.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/output24x16A.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/output24x16A_v0.3.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/example_config/output32x5A.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/fonts/danube__.ttf +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/group/__init__.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/config.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/exceptions.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/filter.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/logger.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/oled.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/onewire/W1ThermSensor.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/onewire/__init__.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/onewire/ds2482.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/onewire/onewire.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/pcf8575.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/queue.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/helper/timeperiod.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/__init__.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/relay/gpio.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/actions.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/filters.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/filters_adc.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/id.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/temp_unit.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/schema/update_interval.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/adc.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/dts1964_3f.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/pt100.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/r4dcb08.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/sdm120.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/sdm630.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/modbus/sofar.json +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/temp/__init__.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/temp/dallas.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/temp/lm75.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/boneio/sensor/temp/mcp9808.py +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/tests/32_5_config.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/tests/bandit.yaml +0 -0
- {boneIO-0.7.0.dev6 → boneIO-0.8.0.dev1}/tests/relay_32_5.py +0 -0
|
@@ -56,7 +56,7 @@ UARTS = {
|
|
|
56
56
|
"uart5": {ID: "/dev/ttyS5", TX: "P8.37", RX: "P8.38"},
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
relay_actions = {ON: "
|
|
59
|
+
relay_actions = {ON: "async_turn_on", OFF: "async_turn_off", TOGGLE: "async_toggle"}
|
|
60
60
|
|
|
61
61
|
# HA CONSTS
|
|
62
62
|
HOMEASSISTANT = "homeassistant"
|
|
@@ -158,3 +158,5 @@ cover_actions = {
|
|
|
158
158
|
"TOGGLE_OPEN": "toggle_open",
|
|
159
159
|
"TOGGLE_CLOSE": "toggle_close",
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
INA219 = "ina219"
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
- id: IN_01
|
|
2
|
+
pin: P8_37
|
|
3
|
+
detection_type: "old"
|
|
4
|
+
actions:
|
|
5
|
+
single:
|
|
6
|
+
- action: output
|
|
7
|
+
pin: light 1
|
|
8
|
+
double:
|
|
9
|
+
- action: output
|
|
10
|
+
pin: switch 1
|
|
11
|
+
- id: IN_02
|
|
12
|
+
pin: P8_38
|
|
13
|
+
detection_type: "new"
|
|
14
|
+
actions:
|
|
15
|
+
single:
|
|
16
|
+
- action: output
|
|
17
|
+
pin: light 2
|
|
18
|
+
double:
|
|
19
|
+
- action: output
|
|
20
|
+
pin: switch 2
|
|
21
|
+
- id: IN_03
|
|
22
|
+
pin: P8_39
|
|
23
|
+
actions:
|
|
24
|
+
single:
|
|
25
|
+
- action: output
|
|
26
|
+
pin: light 3
|
|
27
|
+
double:
|
|
28
|
+
- action: output
|
|
29
|
+
pin: switch 3
|
|
30
|
+
- id: IN_04
|
|
31
|
+
pin: P8_40
|
|
32
|
+
actions:
|
|
33
|
+
single:
|
|
34
|
+
- action: output
|
|
35
|
+
pin: light 4
|
|
36
|
+
double:
|
|
37
|
+
- action: output
|
|
38
|
+
pin: switch 4
|
|
39
|
+
- id: IN_05
|
|
40
|
+
pin: P8_41
|
|
41
|
+
actions:
|
|
42
|
+
single:
|
|
43
|
+
- action: output
|
|
44
|
+
pin: light 5
|
|
45
|
+
double:
|
|
46
|
+
- action: output
|
|
47
|
+
pin: switch 5
|
|
48
|
+
- id: IN_06
|
|
49
|
+
pin: P8_42
|
|
50
|
+
actions:
|
|
51
|
+
single:
|
|
52
|
+
- action: output
|
|
53
|
+
pin: light 6
|
|
54
|
+
double:
|
|
55
|
+
- action: output
|
|
56
|
+
pin: switch 6
|
|
57
|
+
- id: IN_07
|
|
58
|
+
pin: P8_43
|
|
59
|
+
actions:
|
|
60
|
+
single:
|
|
61
|
+
- action: output
|
|
62
|
+
pin: light 7
|
|
63
|
+
|
|
64
|
+
- id: IN_08
|
|
65
|
+
pin: P8_44
|
|
66
|
+
actions:
|
|
67
|
+
single:
|
|
68
|
+
- action: output
|
|
69
|
+
pin: light 8
|
|
70
|
+
- id: IN_09
|
|
71
|
+
pin: P8_45
|
|
72
|
+
actions:
|
|
73
|
+
single:
|
|
74
|
+
- action: output
|
|
75
|
+
pin: light 9
|
|
76
|
+
- id: IN_10
|
|
77
|
+
pin: P8_46
|
|
78
|
+
actions:
|
|
79
|
+
single:
|
|
80
|
+
- action: output
|
|
81
|
+
pin: light 10
|
|
82
|
+
- id: IN_11
|
|
83
|
+
pin: P9_42
|
|
84
|
+
actions:
|
|
85
|
+
single:
|
|
86
|
+
- action: output
|
|
87
|
+
pin: light 11
|
|
88
|
+
- id: IN_12
|
|
89
|
+
pin: P9_31
|
|
90
|
+
actions:
|
|
91
|
+
single:
|
|
92
|
+
- action: output
|
|
93
|
+
pin: light 12
|
|
94
|
+
- id: IN_13
|
|
95
|
+
pin: P9_30
|
|
96
|
+
actions:
|
|
97
|
+
single:
|
|
98
|
+
- action: output
|
|
99
|
+
pin: light 13
|
|
100
|
+
- id: IN_14
|
|
101
|
+
pin: P9_29
|
|
102
|
+
actions:
|
|
103
|
+
single:
|
|
104
|
+
- action: output
|
|
105
|
+
pin: light 14
|
|
106
|
+
|
|
107
|
+
- id: IN_15
|
|
108
|
+
pin: P9_28
|
|
109
|
+
actions:
|
|
110
|
+
single:
|
|
111
|
+
- action: output
|
|
112
|
+
pin: light 15
|
|
113
|
+
- id: IN_16
|
|
114
|
+
pin: P9_27
|
|
115
|
+
actions:
|
|
116
|
+
single:
|
|
117
|
+
- action: output
|
|
118
|
+
pin: light 16
|
|
119
|
+
- id: IN_17
|
|
120
|
+
pin: P9_25
|
|
121
|
+
actions:
|
|
122
|
+
single:
|
|
123
|
+
- action: output
|
|
124
|
+
pin: light 4
|
|
125
|
+
- id: IN_18
|
|
126
|
+
pin: P9_23
|
|
127
|
+
- id: IN_19
|
|
128
|
+
pin: P9_22
|
|
129
|
+
- id: IN_20
|
|
130
|
+
pin: P9_21
|
|
131
|
+
- id: IN_21
|
|
132
|
+
pin: P9_18
|
|
133
|
+
|
|
134
|
+
- id: IN_22
|
|
135
|
+
pin: P9_17
|
|
136
|
+
- id: IN_23
|
|
137
|
+
pin: P9_16
|
|
138
|
+
- id: IN_24
|
|
139
|
+
pin: P9_15
|
|
140
|
+
- id: IN_25
|
|
141
|
+
pin: P9_14
|
|
142
|
+
- id: IN_26
|
|
143
|
+
pin: P9_13
|
|
144
|
+
- id: IN_27
|
|
145
|
+
pin: P9_12
|
|
146
|
+
- id: IN_28
|
|
147
|
+
pin: P9_11
|
|
148
|
+
|
|
149
|
+
- id: IN_29
|
|
150
|
+
pin: P8_36
|
|
151
|
+
- id: IN_30
|
|
152
|
+
pin: P8_35
|
|
153
|
+
- id: IN_31
|
|
154
|
+
pin: P8_34
|
|
155
|
+
- id: IN_32
|
|
156
|
+
pin: P8_33
|
|
157
|
+
|
|
158
|
+
- id: IN_33
|
|
159
|
+
pin: P8_32
|
|
160
|
+
- id: IN_34
|
|
161
|
+
pin: P8_31
|
|
162
|
+
- id: IN_35
|
|
163
|
+
pin: P8_30
|
|
164
|
+
- id: IN_36
|
|
165
|
+
pin: P8_29
|
|
166
|
+
- id: IN_37
|
|
167
|
+
pin: P8_28
|
|
168
|
+
- id: IN_38
|
|
169
|
+
pin: P8_27
|
|
170
|
+
- id: IN_39
|
|
171
|
+
pin: P8_26
|
|
172
|
+
|
|
173
|
+
- id: IN_40
|
|
174
|
+
pin: P8_19
|
|
175
|
+
- id: IN_41
|
|
176
|
+
pin: P8_18
|
|
177
|
+
- id: IN_42
|
|
178
|
+
pin: P8_17
|
|
179
|
+
- id: IN_43
|
|
180
|
+
pin: P8_16
|
|
181
|
+
- id: IN_44
|
|
182
|
+
pin: P8_15
|
|
183
|
+
- id: IN_45
|
|
184
|
+
pin: P8_14
|
|
185
|
+
- id: IN_46
|
|
186
|
+
pin: P8_13
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Group output module."""
|
|
2
2
|
from __future__ import annotations
|
|
3
|
-
import logging
|
|
4
3
|
import asyncio
|
|
5
4
|
from typing import List
|
|
6
|
-
|
|
7
5
|
from boneio.const import COVER, SWITCH, ON, OFF
|
|
8
6
|
from boneio.relay.basic import BasicRelay
|
|
9
7
|
|
|
10
|
-
_LOGGER = logging.getLogger(__name__)
|
|
11
|
-
|
|
12
8
|
|
|
13
9
|
class OutputGroup(BasicRelay):
|
|
14
10
|
"""Cover class of boneIO"""
|
|
@@ -41,23 +37,22 @@ class OutputGroup(BasicRelay):
|
|
|
41
37
|
self._state = state
|
|
42
38
|
self._loop.call_soon_threadsafe(self.send_state)
|
|
43
39
|
|
|
44
|
-
def
|
|
40
|
+
async def async_turn_on(self) -> None:
|
|
45
41
|
"""Call turn on action."""
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
await asyncio.gather(
|
|
43
|
+
*[self._loop.run_in_executor(self.executor, x.turn_on) for x in self._group_members]
|
|
44
|
+
)
|
|
48
45
|
|
|
49
|
-
def
|
|
46
|
+
async def async_turn_off(self) -> None:
|
|
50
47
|
"""Call turn off action."""
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
await asyncio.gather(
|
|
49
|
+
*[self._loop.run_in_executor(self.executor, x.turn_off) for x in self._group_members]
|
|
50
|
+
)
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
self.turn_off()
|
|
59
|
-
else:
|
|
60
|
-
self.turn_on()
|
|
52
|
+
@property
|
|
53
|
+
def is_active(self) -> bool:
|
|
54
|
+
"""Is relay active."""
|
|
55
|
+
return self._state == ON
|
|
61
56
|
|
|
62
57
|
def send_state(self) -> None:
|
|
63
58
|
"""Send state to Mqtt on action."""
|
|
@@ -21,6 +21,7 @@ from boneio.helper.ha_discovery import (
|
|
|
21
21
|
ha_sensor_temp_availabilty_message,
|
|
22
22
|
ha_switch_availabilty_message,
|
|
23
23
|
ha_led_availabilty_message,
|
|
24
|
+
ha_sensor_ina_availabilty_message
|
|
24
25
|
)
|
|
25
26
|
from boneio.helper.mqtt import BasicMqtt
|
|
26
27
|
from boneio.helper.async_updater import AsyncUpdater
|
|
@@ -54,6 +55,7 @@ __all__ = [
|
|
|
54
55
|
"ha_sensor_temp_availabilty_message",
|
|
55
56
|
"ha_binary_sensor_availabilty_message",
|
|
56
57
|
"ha_button_availabilty_message",
|
|
58
|
+
"ha_sensor_ina_availabilty_message",
|
|
57
59
|
"ha_event_availabilty_message",
|
|
58
60
|
"ha_led_availabilty_message",
|
|
59
61
|
"GPIOInputException",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import asyncio
|
|
3
|
-
|
|
3
|
+
import time
|
|
4
4
|
# Typing imports that create a circular dependency
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
@@ -19,11 +19,11 @@ class AsyncUpdater:
|
|
|
19
19
|
while True:
|
|
20
20
|
if hasattr(self, "async_update"):
|
|
21
21
|
update_interval = (
|
|
22
|
-
await self.async_update(time=
|
|
22
|
+
await self.async_update(time=time.time())
|
|
23
23
|
or self._update_interval.total_in_seconds
|
|
24
24
|
)
|
|
25
25
|
else:
|
|
26
26
|
update_interval = (
|
|
27
|
-
self.update(time=
|
|
27
|
+
self.update(time=time.time()) or self._update_interval.total_in_seconds
|
|
28
28
|
)
|
|
29
29
|
await asyncio.sleep(update_interval)
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
import logging
|
|
2
3
|
import asyncio
|
|
3
4
|
from boneio.helper.timeperiod import TimePeriod
|
|
4
5
|
import time
|
|
5
6
|
|
|
7
|
+
_LOGGER = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
6
10
|
class ClickTimer:
|
|
7
11
|
"""Represent async call later function with variable to check if timing is ON."""
|
|
8
12
|
|
|
@@ -16,6 +20,10 @@ class ClickTimer:
|
|
|
16
20
|
def is_waiting(self) -> bool:
|
|
17
21
|
"""If variable is set then timer is ON, if None is Off."""
|
|
18
22
|
return self._remove_listener is not None
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def delay(self) -> float:
|
|
26
|
+
return self._delay
|
|
19
27
|
|
|
20
28
|
def reset(self) -> None:
|
|
21
29
|
"""Uninitialize variable remove_listener."""
|
|
@@ -4,7 +4,8 @@ import logging
|
|
|
4
4
|
import signal
|
|
5
5
|
import time
|
|
6
6
|
from datetime import datetime
|
|
7
|
-
from typing import Callable, Optional
|
|
7
|
+
from typing import Any, Coroutine, List, Optional, Callable, Optional
|
|
8
|
+
|
|
8
9
|
|
|
9
10
|
from boneio.helper.util import callback
|
|
10
11
|
|
|
@@ -261,3 +262,22 @@ def async_call_later_miliseconds(
|
|
|
261
262
|
return async_track_point_in_timestamp(
|
|
262
263
|
loop=loop, action=action, timestamp=expected_fire_timestamp
|
|
263
264
|
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def create_unawaited_task_threadsafe(
|
|
268
|
+
loop: asyncio.AbstractEventLoop,
|
|
269
|
+
transient_tasks: List["asyncio.Task[Any]"],
|
|
270
|
+
coro: Coroutine[Any, Any, None],
|
|
271
|
+
task_future: Optional["asyncio.Future[asyncio.Task[Any]]"] = None,
|
|
272
|
+
) -> None:
|
|
273
|
+
"""
|
|
274
|
+
Schedule a coroutine on the loop and add the Task to transient_tasks.
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
def callback() -> None:
|
|
278
|
+
task = loop.create_task(coro)
|
|
279
|
+
transient_tasks.append(task)
|
|
280
|
+
if task_future is not None:
|
|
281
|
+
task_future.set_result(task)
|
|
282
|
+
|
|
283
|
+
loop.call_soon_threadsafe(callback)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import asyncio
|
|
3
3
|
import logging
|
|
4
|
-
|
|
4
|
+
from datetime import datetime
|
|
5
5
|
try:
|
|
6
6
|
from Adafruit_BBIO import GPIO
|
|
7
7
|
except ModuleNotFoundError:
|
|
@@ -17,13 +17,14 @@ except ModuleNotFoundError:
|
|
|
17
17
|
pass
|
|
18
18
|
|
|
19
19
|
import subprocess
|
|
20
|
-
from typing import Callable
|
|
20
|
+
from typing import Callable, Awaitable, List
|
|
21
21
|
|
|
22
22
|
from boneio.const import CONFIG_PIN, FALLING
|
|
23
23
|
from boneio.const import GPIO as GPIO_STR
|
|
24
|
-
from boneio.const import GPIO_MODE, LOW, ClickTypes, Gpio_Edges, Gpio_States
|
|
24
|
+
from boneio.const import GPIO_MODE, LOW, ClickTypes, Gpio_Edges, Gpio_States, InputTypes
|
|
25
25
|
from boneio.helper.exceptions import GPIOInputException
|
|
26
26
|
from boneio.helper.timeperiod import TimePeriod
|
|
27
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
27
28
|
|
|
28
29
|
_LOGGER = logging.getLogger(__name__)
|
|
29
30
|
|
|
@@ -81,22 +82,20 @@ def edge_detect(
|
|
|
81
82
|
GPIO.add_event_detect(gpio=pin, edge=edge, callback=callback, bouncetime=bounce)
|
|
82
83
|
except RuntimeError as err:
|
|
83
84
|
raise GPIOInputException(err)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
) -> None:
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def add_event_detect(pin: str, edge: Gpio_Edges = FALLING) -> None:
|
|
88
88
|
"""Add detection for RISING and FALLING events."""
|
|
89
89
|
try:
|
|
90
90
|
GPIO.add_event_detect(gpio=pin, edge=edge)
|
|
91
91
|
except RuntimeError as err:
|
|
92
92
|
raise GPIOInputException(err)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
) -> None:
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def add_event_callback(pin: str, callback: Callable) -> None:
|
|
97
96
|
"""Add detection for RISING and FALLING events."""
|
|
98
97
|
try:
|
|
99
|
-
GPIO.add_event_callback(gpio=pin,callback=callback)
|
|
98
|
+
GPIO.add_event_callback(gpio=pin, callback=callback)
|
|
100
99
|
except RuntimeError as err:
|
|
101
100
|
raise GPIOInputException(err)
|
|
102
101
|
|
|
@@ -105,24 +104,61 @@ class GpioBaseClass:
|
|
|
105
104
|
"""Base class for initialize GPIO"""
|
|
106
105
|
|
|
107
106
|
def __init__(
|
|
108
|
-
self,
|
|
107
|
+
self,
|
|
108
|
+
pin: str,
|
|
109
|
+
press_callback: Callable[
|
|
110
|
+
[ClickTypes, str, List, InputTypes, bool, float | None], Awaitable[None]
|
|
111
|
+
],
|
|
112
|
+
name: str,
|
|
113
|
+
actions: dict,
|
|
114
|
+
input_type,
|
|
115
|
+
empty_message_after: bool,
|
|
116
|
+
**kwargs,
|
|
109
117
|
) -> None:
|
|
110
118
|
"""Setup GPIO Input Button"""
|
|
111
119
|
self._pin = pin
|
|
112
120
|
gpio_mode = kwargs.get(GPIO_MODE, GPIO_STR)
|
|
113
|
-
|
|
121
|
+
bounce_time: TimePeriod = kwargs.get("bounce_time", TimePeriod(milliseconds=50))
|
|
122
|
+
self._bounce_time = bounce_time.total_in_seconds
|
|
114
123
|
self._loop = asyncio.get_running_loop()
|
|
115
124
|
self._press_callback = press_callback
|
|
125
|
+
self._name = name
|
|
116
126
|
setup_input(pin=self._pin, pull_mode=gpio_mode)
|
|
127
|
+
self.executor = ThreadPoolExecutor()
|
|
128
|
+
self._actions = actions
|
|
129
|
+
self._input_type = input_type
|
|
130
|
+
self._empty_message_after = empty_message_after
|
|
117
131
|
|
|
118
|
-
def
|
|
119
|
-
self.
|
|
132
|
+
def press_callback(self, click_type: ClickTypes, duration: float | None = None) -> None:
|
|
133
|
+
actions = self._actions.get(click_type, [])
|
|
134
|
+
self._loop.create_task(self.async_press_callback(click_type, duration, actions))
|
|
135
|
+
|
|
136
|
+
async def async_press_callback(
|
|
137
|
+
self, click_type: ClickTypes, duration: float | None = None, actions: List = []
|
|
138
|
+
) -> None:
|
|
139
|
+
_LOGGER.warn("press callback %s", datetime.now())
|
|
140
|
+
await self._press_callback(
|
|
141
|
+
click_type,
|
|
142
|
+
self._pin,
|
|
143
|
+
actions,
|
|
144
|
+
self._input_type,
|
|
145
|
+
self._empty_message_after,
|
|
146
|
+
duration,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def set_actions(self, actions: dict) -> None:
|
|
150
|
+
self._actions = actions
|
|
120
151
|
|
|
121
152
|
@property
|
|
122
153
|
def is_pressed(self) -> bool:
|
|
123
154
|
"""Is button pressed."""
|
|
124
155
|
return read_input(self._pin)
|
|
125
|
-
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def name(self) -> str:
|
|
159
|
+
"""Name of the GPIO visible in HA/MQTT."""
|
|
160
|
+
return self._name
|
|
161
|
+
|
|
126
162
|
@property
|
|
127
163
|
def pin(self) -> str:
|
|
128
164
|
"""Return configured pin."""
|
|
@@ -131,6 +131,28 @@ def ha_binary_sensor_availabilty_message(id: str, name: str, device_class: str,
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
|
|
134
|
+
def ha_sensor_ina_availabilty_message(
|
|
135
|
+
id: str, name: str, topic: str = "boneIO", **kwargs
|
|
136
|
+
):
|
|
137
|
+
"""Create availability topic for HA."""
|
|
138
|
+
return {
|
|
139
|
+
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
140
|
+
"device": {
|
|
141
|
+
"identifiers": [topic],
|
|
142
|
+
"manufacturer": "boneIO",
|
|
143
|
+
"model": "boneIO Relay Board",
|
|
144
|
+
"name": f"boneIO {topic}",
|
|
145
|
+
"sw_version": __version__,
|
|
146
|
+
},
|
|
147
|
+
"name": name,
|
|
148
|
+
"state_topic": f"{topic}/{SENSOR}/{id}",
|
|
149
|
+
"unique_id": f"{topic}{SENSOR}{id}",
|
|
150
|
+
"state_class": "measurement",
|
|
151
|
+
"value_template": "{{ value_json.state }}",
|
|
152
|
+
**kwargs,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
134
156
|
def ha_sensor_temp_availabilty_message(
|
|
135
157
|
id: str, name: str, topic: str = "boneIO", **kwargs
|
|
136
158
|
):
|