boneIO 0.4.0dev1__tar.gz → 0.5.0dev1__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.
Potentially problematic release.
This version of boneIO might be problematic. Click here for more details.
- boneIO-0.5.0.dev1/PKG-INFO +36 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/const.py +2 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/output32x5A.yaml +13 -14
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/__init__.py +3 -2
- boneIO-0.5.0.dev1/boneio/helper/async_updater.py +29 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/loader.py +38 -20
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/mqtt.py +1 -0
- boneIO-0.5.0.dev1/boneio/helper/onewire/W1ThermSensor.py +73 -0
- boneIO-0.5.0.dev1/boneio/helper/onewire/__init__.py +20 -0
- boneIO-0.5.0.dev1/boneio/helper/onewire/onewire.py +91 -0
- boneIO-0.5.0.dev1/boneio/helper/stats.py +185 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/timeperiod.py +6 -1
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/manager.py +81 -42
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/runner.py +5 -2
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/schema/schema.yaml +33 -12
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/__init__.py +2 -2
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/adc.py +10 -15
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/modbus/__init__.py +43 -47
- boneIO-0.5.0.dev1/boneio/sensor/temp/__init__.py +39 -0
- boneIO-0.5.0.dev1/boneio/sensor/temp/dallas.py +69 -0
- boneIO-0.5.0.dev1/boneio/version.py +2 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/pyproject.toml +4 -2
- boneIO-0.4.0.dev1/PKG-INFO +0 -35
- boneIO-0.4.0.dev1/boneio/helper/ds2482/__init__.py +0 -10
- boneIO-0.4.0.dev1/boneio/helper/ds2482/onewire.py +0 -44
- boneIO-0.4.0.dev1/boneio/helper/stats.py +0 -185
- boneIO-0.4.0.dev1/boneio/sensor/temp/__init__.py +0 -71
- boneIO-0.4.0.dev1/boneio/sensor/temp/dallas.py +0 -40
- boneIO-0.4.0.dev1/boneio/version.py +0 -2
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/LICENSE +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/README.md +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/__init__.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/bonecli.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/cover.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/__init__.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/adc.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/config.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/cover.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/input.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/example_config/output24x16A.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/fonts/danube__.ttf +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/config.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/events.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/exceptions.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/gpio.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/ha_discovery.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/logger.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/oled.py +0 -0
- {boneIO-0.4.0.dev1/boneio/helper/ds2482 → boneIO-0.5.0.dev1/boneio/helper/onewire}/ds2482.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/queue.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/state_manager.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/util.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/helper/yaml_util.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/input/__init__.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/input/gpio.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/modbus.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/mqtt_client.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/oled.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/relay/__init__.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/relay/basic.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/relay/gpio.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/relay/mcp.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/schema/actions.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/schema/actions_sensor.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/schema/actions_switch.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/gpio.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/modbus/sdm120.json +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/modbus/sdm630.json +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/modbus/sofar.json +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/temp/lm75.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/boneio/sensor/temp/mcp9808.py +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/tests/32_5_config.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/tests/bandit.yaml +0 -0
- {boneIO-0.4.0.dev1 → boneIO-0.5.0.dev1}/tests/relay_32_5.py +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: boneIO
|
|
3
|
+
Version: 0.5.0dev1
|
|
4
|
+
Summary: Python App for BoneIO
|
|
5
|
+
License: GNU General Public License v3.0
|
|
6
|
+
Author-email: Paweł Szafer <pszafer@gmail.com>
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
Project-URL: Changelog, https://github.com/boneIO-eu/app_bbb/releases
|
|
9
|
+
Project-URL: Documentation, https://boneio.eu/docs/intro/
|
|
10
|
+
Project-URL: Homepage, https://boneio.eu
|
|
11
|
+
Project-URL: Repository, https://github.com/boneIO-eu/app_bbb
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
Example usage:
|
|
15
|
+
boneio run -dd -c config.yaml
|
|
16
|
+
|
|
17
|
+
# Installation instructions
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
sudo apt-get install libopenjp2-7-dev libatlas-base-dev python3-venv
|
|
21
|
+
mkdir ~/boneio
|
|
22
|
+
python3 -m venv ~/boneio/venv
|
|
23
|
+
source ~/boneio/venv/bin/activate
|
|
24
|
+
pip3 install --upgrade boneio
|
|
25
|
+
cp ~/venv/lib/python3.7/site-packages/boneio/example_config/*.yaml ~/boneio/
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Edit config.yaml
|
|
29
|
+
|
|
30
|
+
# Start app
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
source ~/boneio/venv/bin/activate
|
|
34
|
+
boneio run -c ~/boneio/config.yaml -dd
|
|
35
|
+
```
|
|
36
|
+
|
|
@@ -113,6 +113,7 @@ MCP_TEMP_9808 = "mcp9808"
|
|
|
113
113
|
INPUT_SENSOR = "inputsensor"
|
|
114
114
|
DS2482 = "ds2482"
|
|
115
115
|
DALLAS = "dallas"
|
|
116
|
+
ONEWIRE = "onewire"
|
|
116
117
|
|
|
117
118
|
BASE = "base"
|
|
118
119
|
LENGTH = "length"
|
|
@@ -134,3 +135,4 @@ Gpio_States = Literal[HIGH, LOW]
|
|
|
134
135
|
Gpio_Edges = Literal[BOTH, FALLING]
|
|
135
136
|
InputTypes = Literal[INPUT, INPUT_SENSOR]
|
|
136
137
|
DEVICE_CLASS = "device_class"
|
|
138
|
+
DallasBusTypes = Literal[DS2482, DALLAS]
|
|
@@ -97,36 +97,35 @@
|
|
|
97
97
|
pin: 7
|
|
98
98
|
output_type: light
|
|
99
99
|
|
|
100
|
-
|
|
101
100
|
# mcp1 - lower left 8 relays
|
|
102
101
|
- id: OUT_17
|
|
103
102
|
kind: mcp
|
|
104
103
|
mcp_id: mcp1
|
|
105
|
-
pin:
|
|
104
|
+
pin: 15
|
|
106
105
|
output_type: light
|
|
107
106
|
|
|
108
107
|
- id: OUT_18
|
|
109
108
|
kind: mcp
|
|
110
109
|
mcp_id: mcp1
|
|
111
|
-
pin:
|
|
110
|
+
pin: 14
|
|
112
111
|
output_type: light
|
|
113
112
|
|
|
114
113
|
- id: OUT_19
|
|
115
114
|
kind: mcp
|
|
116
115
|
mcp_id: mcp1
|
|
117
|
-
pin:
|
|
116
|
+
pin: 13
|
|
118
117
|
output_type: light
|
|
119
118
|
|
|
120
119
|
- id: OUT_20
|
|
121
120
|
kind: mcp
|
|
122
121
|
mcp_id: mcp1
|
|
123
|
-
pin:
|
|
122
|
+
pin: 12
|
|
124
123
|
output_type: light
|
|
125
124
|
|
|
126
125
|
- id: OUT_21
|
|
127
126
|
kind: mcp
|
|
128
127
|
mcp_id: mcp1
|
|
129
|
-
pin:
|
|
128
|
+
pin: 11
|
|
130
129
|
output_type: light
|
|
131
130
|
|
|
132
131
|
- id: OUT_22
|
|
@@ -138,13 +137,13 @@
|
|
|
138
137
|
- id: OUT_23
|
|
139
138
|
kind: mcp
|
|
140
139
|
mcp_id: mcp1
|
|
141
|
-
pin:
|
|
140
|
+
pin: 9
|
|
142
141
|
output_type: light
|
|
143
142
|
|
|
144
143
|
- id: OUT_24
|
|
145
144
|
kind: mcp
|
|
146
145
|
mcp_id: mcp1
|
|
147
|
-
pin:
|
|
146
|
+
pin: 8
|
|
148
147
|
output_type: light
|
|
149
148
|
|
|
150
149
|
|
|
@@ -152,7 +151,7 @@
|
|
|
152
151
|
- id: OUT_25
|
|
153
152
|
kind: mcp
|
|
154
153
|
mcp_id: mcp2
|
|
155
|
-
pin:
|
|
154
|
+
pin: 15
|
|
156
155
|
output_type: light
|
|
157
156
|
|
|
158
157
|
- id: OUT_26
|
|
@@ -164,31 +163,31 @@
|
|
|
164
163
|
- id: OUT_27
|
|
165
164
|
kind: mcp
|
|
166
165
|
mcp_id: mcp2
|
|
167
|
-
pin:
|
|
166
|
+
pin: 13
|
|
168
167
|
output_type: light
|
|
169
168
|
|
|
170
169
|
- id: OUT_28
|
|
171
170
|
kind: mcp
|
|
172
171
|
mcp_id: mcp2
|
|
173
|
-
pin:
|
|
172
|
+
pin: 12
|
|
174
173
|
output_type: light
|
|
175
174
|
|
|
176
175
|
- id: OUT_29
|
|
177
176
|
kind: mcp
|
|
178
177
|
mcp_id: mcp2
|
|
179
|
-
pin:
|
|
178
|
+
pin: 11
|
|
180
179
|
output_type: light
|
|
181
180
|
|
|
182
181
|
- id: OUT_30
|
|
183
182
|
kind: mcp
|
|
184
183
|
mcp_id: mcp2
|
|
185
|
-
pin:
|
|
184
|
+
pin: 10
|
|
186
185
|
output_type: light
|
|
187
186
|
|
|
188
187
|
- id: OUT_31
|
|
189
188
|
kind: mcp
|
|
190
189
|
mcp_id: mcp2
|
|
191
|
-
pin:
|
|
190
|
+
pin: 9
|
|
192
191
|
output_type: light
|
|
193
192
|
|
|
194
193
|
- id: OUT_32
|
|
@@ -21,10 +21,11 @@ from boneio.helper.ha_discovery import (
|
|
|
21
21
|
ha_switch_availabilty_message,
|
|
22
22
|
)
|
|
23
23
|
from boneio.helper.mqtt import BasicMqtt
|
|
24
|
+
from boneio.helper.async_updater import AsyncUpdater
|
|
24
25
|
from boneio.helper.oled import make_font
|
|
25
26
|
from boneio.helper.queue import UniqueQueue
|
|
26
27
|
from boneio.helper.state_manager import StateManager
|
|
27
|
-
from boneio.helper.stats import HostData
|
|
28
|
+
from boneio.helper.stats import HostData
|
|
28
29
|
from boneio.helper.timeperiod import TimePeriod
|
|
29
30
|
from boneio.helper.yaml_util import (
|
|
30
31
|
CustomValidator,
|
|
@@ -38,7 +39,6 @@ __all__ = [
|
|
|
38
39
|
"CustomValidator",
|
|
39
40
|
"load_yaml_file",
|
|
40
41
|
"HostData",
|
|
41
|
-
"host_stats",
|
|
42
42
|
"setup_input",
|
|
43
43
|
"setup_output",
|
|
44
44
|
"edge_detect",
|
|
@@ -59,6 +59,7 @@ __all__ = [
|
|
|
59
59
|
"StateManager",
|
|
60
60
|
"configure_pin",
|
|
61
61
|
"BasicMqtt",
|
|
62
|
+
"AsyncUpdater",
|
|
62
63
|
"UniqueQueue",
|
|
63
64
|
"schema_file",
|
|
64
65
|
"load_config_from_string",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
# Typing imports that create a circular dependency
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from ..manager import Manager
|
|
9
|
+
from boneio.helper.timeperiod import TimePeriod
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AsyncUpdater:
|
|
13
|
+
def __init__(self, manager: Manager, update_interval: TimePeriod, **kwargs):
|
|
14
|
+
self.manager = manager
|
|
15
|
+
self._update_interval = update_interval or TimePeriod(seconds=60)
|
|
16
|
+
self.manager.append_task(coro=self._refresh, name=self.id)
|
|
17
|
+
|
|
18
|
+
async def _refresh(self):
|
|
19
|
+
while True:
|
|
20
|
+
if hasattr(self, "async_update"):
|
|
21
|
+
update_interval = (
|
|
22
|
+
await self.async_update(time=None)
|
|
23
|
+
or self._update_interval.total_in_seconds
|
|
24
|
+
)
|
|
25
|
+
else:
|
|
26
|
+
update_interval = (
|
|
27
|
+
self.update(time=None) or self._update_interval.total_in_seconds
|
|
28
|
+
)
|
|
29
|
+
await asyncio.sleep(update_interval)
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import asyncio
|
|
4
3
|
import logging
|
|
5
4
|
import time
|
|
6
5
|
from collections import namedtuple
|
|
7
|
-
from typing import TYPE_CHECKING, Any, Callable
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, Union
|
|
8
7
|
|
|
9
8
|
from adafruit_mcp230xx.mcp23017 import MCP23017
|
|
10
|
-
from adafruit_onewire.bus import OneWireAddress
|
|
11
9
|
|
|
12
10
|
from boneio.const import (
|
|
13
11
|
ACTIONS,
|
|
@@ -34,6 +32,7 @@ from boneio.const import (
|
|
|
34
32
|
SENSOR,
|
|
35
33
|
SHOW_HA,
|
|
36
34
|
UPDATE_INTERVAL,
|
|
35
|
+
DallasBusTypes,
|
|
37
36
|
)
|
|
38
37
|
from boneio.cover import Cover
|
|
39
38
|
from boneio.helper import (
|
|
@@ -45,11 +44,18 @@ from boneio.helper import (
|
|
|
45
44
|
ha_input_availabilty_message,
|
|
46
45
|
ha_sensor_temp_availabilty_message,
|
|
47
46
|
)
|
|
48
|
-
from boneio.helper.
|
|
47
|
+
from boneio.helper.onewire import (
|
|
48
|
+
DS2482,
|
|
49
|
+
DS2482_ADDRESS,
|
|
50
|
+
OneWireBus,
|
|
51
|
+
AsyncBoneIOW1ThermSensor,
|
|
52
|
+
OneWireAddress,
|
|
53
|
+
)
|
|
49
54
|
from boneio.helper.ha_discovery import ha_cover_availabilty_message
|
|
50
55
|
from boneio.helper.timeperiod import TimePeriod
|
|
51
56
|
from boneio.input.gpio import GpioInputButton
|
|
52
|
-
from boneio.sensor import
|
|
57
|
+
from boneio.sensor import DallasSensorDS2482
|
|
58
|
+
from boneio.sensor.temp.dallas import DallasSensorW1
|
|
53
59
|
|
|
54
60
|
# Typing imports that create a circular dependency
|
|
55
61
|
if TYPE_CHECKING:
|
|
@@ -75,10 +81,11 @@ def create_adc(manager: Manager, topic_prefix: str, adc_list: list = []):
|
|
|
75
81
|
id = name.replace(" ", "")
|
|
76
82
|
pin = gpio[PIN]
|
|
77
83
|
try:
|
|
78
|
-
|
|
84
|
+
GpioADCSensor(
|
|
79
85
|
id=id,
|
|
80
86
|
pin=pin,
|
|
81
87
|
name=name,
|
|
88
|
+
manager=manager,
|
|
82
89
|
send_message=manager.send_message,
|
|
83
90
|
topic_prefix=topic_prefix,
|
|
84
91
|
update_interval=gpio.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
|
|
@@ -90,7 +97,6 @@ def create_adc(manager: Manager, topic_prefix: str, adc_list: list = []):
|
|
|
90
97
|
ha_type=SENSOR,
|
|
91
98
|
availability_msg_func=ha_adc_sensor_availabilty_message,
|
|
92
99
|
)
|
|
93
|
-
manager.append_task(asyncio.create_task(adc.send_state()))
|
|
94
100
|
except I2CError as err:
|
|
95
101
|
_LOGGER.error("Can't configure ADC sensor %s. %s", id, err)
|
|
96
102
|
pass
|
|
@@ -165,16 +171,16 @@ def create_modbus_sensors(manager: Manager, sensors, **kwargs) -> None:
|
|
|
165
171
|
name = sensor.get(ID)
|
|
166
172
|
id = name.replace(" ", "")
|
|
167
173
|
try:
|
|
168
|
-
|
|
174
|
+
ModbusSensor(
|
|
169
175
|
address=sensor[ADDRESS],
|
|
170
176
|
id=id,
|
|
171
177
|
name=name,
|
|
178
|
+
manager=manager,
|
|
172
179
|
model=sensor[MODEL],
|
|
173
180
|
send_message=manager.send_message,
|
|
174
181
|
update_interval=sensor.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
|
|
175
182
|
**kwargs,
|
|
176
183
|
)
|
|
177
|
-
manager.append_task(asyncio.create_task(sdm.send_state()))
|
|
178
184
|
except FileNotFoundError as err:
|
|
179
185
|
_LOGGER.error(
|
|
180
186
|
"Can't configure Modbus sensor %s. %s. No such model in database.",
|
|
@@ -349,27 +355,39 @@ def configure_ds2482(i2cbusio: I2C, address: str = DS2482_ADDRESS) -> OneWireBus
|
|
|
349
355
|
return ow_bus
|
|
350
356
|
|
|
351
357
|
|
|
352
|
-
def
|
|
353
|
-
|
|
358
|
+
def configure_dallas() -> AsyncBoneIOW1ThermSensor:
|
|
359
|
+
return AsyncBoneIOW1ThermSensor
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def find_onewire_devices(
|
|
363
|
+
ow_bus: Union[OneWireBus, AsyncBoneIOW1ThermSensor],
|
|
364
|
+
bus_id: str,
|
|
365
|
+
bus_type: DallasBusTypes,
|
|
366
|
+
) -> Dict[OneWireAddress]:
|
|
354
367
|
out = {}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
368
|
+
try:
|
|
369
|
+
devices = ow_bus.scan()
|
|
370
|
+
for device in devices:
|
|
371
|
+
_addr: int = device.int_address
|
|
372
|
+
_LOGGER.debug("Found device on bus %s with address %s", bus_id, hex(_addr))
|
|
373
|
+
out[_addr] = device
|
|
374
|
+
except RuntimeError as err:
|
|
375
|
+
_LOGGER.error("Problem with scanning %s bus. %s", bus_type, err)
|
|
359
376
|
return out
|
|
360
377
|
|
|
361
378
|
|
|
362
|
-
def
|
|
379
|
+
def create_dallas_sensor(
|
|
363
380
|
manager: Manager,
|
|
364
|
-
ds2482_bus: OneWireBus,
|
|
365
381
|
address: OneWireAddress,
|
|
366
382
|
config: dict,
|
|
367
383
|
**kwargs,
|
|
368
|
-
):
|
|
384
|
+
) -> Union[DallasSensorDS2482, DallasSensorW1]:
|
|
369
385
|
name = config.get(ID) or hex(address)
|
|
370
386
|
id = name.replace(" ", "")
|
|
371
|
-
|
|
372
|
-
|
|
387
|
+
bus: OneWireBus = kwargs.get("bus")
|
|
388
|
+
cls = DallasSensorDS2482 if bus else DallasSensorW1
|
|
389
|
+
sensor = cls(
|
|
390
|
+
manager=manager,
|
|
373
391
|
address=address,
|
|
374
392
|
id=id,
|
|
375
393
|
name=name,
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Custom W1ThermSensor class to support hex addressing of W1 sensors.
|
|
2
|
+
"""
|
|
3
|
+
from typing import List
|
|
4
|
+
from w1thermsensor import AsyncW1ThermSensor, Sensor
|
|
5
|
+
from boneio.helper.onewire import OneWireAddress, reverse_dallas_id
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def crc82(data: bytearray) -> int:
|
|
9
|
+
"""
|
|
10
|
+
Perform the 1-Wire CRC check on the provided data. Function from Circuit Python Adafruit.
|
|
11
|
+
|
|
12
|
+
:param bytearray data: 8 byte array representing 64 bit ROM code
|
|
13
|
+
"""
|
|
14
|
+
crc = 0
|
|
15
|
+
|
|
16
|
+
for byte in data:
|
|
17
|
+
crc ^= byte
|
|
18
|
+
for _ in range(8):
|
|
19
|
+
if crc & 0x01:
|
|
20
|
+
crc = (crc >> 1) ^ 0x8C
|
|
21
|
+
else:
|
|
22
|
+
crc >>= 1
|
|
23
|
+
crc &= 0xFF
|
|
24
|
+
return crc
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AsyncBoneIOW1ThermSensor(AsyncW1ThermSensor):
|
|
28
|
+
def __init__(self, *args, **kwargs): # pragma: no cover
|
|
29
|
+
"""Custom init function to work with same addressing type as esphome."""
|
|
30
|
+
self._ds18b20_str_id = hex(Sensor.DS18B20)[2:]
|
|
31
|
+
try:
|
|
32
|
+
sensor_id = kwargs.pop("sensor_id")
|
|
33
|
+
if type(sensor_id) == OneWireAddress:
|
|
34
|
+
sensor_id = sensor_id.hw_id
|
|
35
|
+
super().__init__(*args, **kwargs, sensor_id=sensor_id)
|
|
36
|
+
except KeyError:
|
|
37
|
+
super().__init__(*args, **kwargs)
|
|
38
|
+
_crc = crc82(
|
|
39
|
+
bytes.fromhex(f"{self._ds18b20_str_id}{reverse_dallas_id(self.id)}")
|
|
40
|
+
)
|
|
41
|
+
self._hex_id = f"{hex(_crc)}{self.id}{self._ds18b20_str_id}".lower()
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def scan(cls) -> List["OneWireAddress"]:
|
|
45
|
+
"""Return only DS18B20 sensors. Add more sensors in the future."""
|
|
46
|
+
|
|
47
|
+
def is_sensor(dir_name):
|
|
48
|
+
return dir_name.startswith(hex(Sensor.DS18B20)[2:])
|
|
49
|
+
|
|
50
|
+
def get_hex(name):
|
|
51
|
+
_hex_id = bytes.fromhex(f"{name[:2]}{reverse_dallas_id(name[3:])}")
|
|
52
|
+
return _hex_id + bytes([crc82(_hex_id)])
|
|
53
|
+
|
|
54
|
+
return [
|
|
55
|
+
OneWireAddress(get_hex(name=s.name))
|
|
56
|
+
for s in cls.BASE_DIRECTORY.iterdir()
|
|
57
|
+
if is_sensor(s.name)
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def rom(self) -> bytes:
|
|
62
|
+
"""Get rom id."""
|
|
63
|
+
return bytearray.fromhex(self.hex_id)
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def hex_id(self) -> str:
|
|
67
|
+
"""Get hex representation of sensor."""
|
|
68
|
+
if not self._hex_id:
|
|
69
|
+
_crc = crc82(
|
|
70
|
+
bytes.fromhex(f"{self._ds18b20_str_id}{reverse_dallas_id(self.id)}")
|
|
71
|
+
)
|
|
72
|
+
self._hex_id = f"{hex(_crc)}{self.id}{self._ds18b20_str_id}".lower()
|
|
73
|
+
return self._hex_id
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Helper dir for DS2482."""
|
|
2
|
+
from boneio.helper.onewire.ds2482 import DS2482, DS2482_ADDRESS
|
|
3
|
+
from boneio.helper.onewire.onewire import (
|
|
4
|
+
OneWire,
|
|
5
|
+
OneWireBus,
|
|
6
|
+
OneWireAddress,
|
|
7
|
+
reverse_dallas_id,
|
|
8
|
+
)
|
|
9
|
+
from boneio.helper.onewire.W1ThermSensor import AsyncBoneIOW1ThermSensor
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"DS2482",
|
|
14
|
+
"OneWire",
|
|
15
|
+
"OneWireBus",
|
|
16
|
+
"DS2482_ADDRESS",
|
|
17
|
+
"AsyncBoneIOW1ThermSensor",
|
|
18
|
+
"OneWireAddress",
|
|
19
|
+
"reverse_dallas_id",
|
|
20
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""OneWire base class for DS2482.
|
|
2
|
+
Module by https://github.com/fgervais/ds2482
|
|
3
|
+
"""
|
|
4
|
+
import adafruit_onewire.bus
|
|
5
|
+
from onewireio import OneWire as OneWireIO
|
|
6
|
+
from boneio.helper.onewire import DS2482
|
|
7
|
+
from typing import List
|
|
8
|
+
from adafruit_onewire.bus import OneWireAddress as AdafruitOneWireAddress
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def ds_address(rom: bytes) -> int:
|
|
12
|
+
return int.from_bytes(rom, "little")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def reverse_dallas_id(a: str) -> str:
|
|
16
|
+
"""Reverse sensor address."""
|
|
17
|
+
return "".join(reversed([a[i : i + 2] for i in range(0, len(a), 2)]))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OneWireAddress(AdafruitOneWireAddress):
|
|
21
|
+
@property
|
|
22
|
+
def int_address(self) -> int:
|
|
23
|
+
return ds_address(self.rom)
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def hex_id(self) -> str:
|
|
27
|
+
return reverse_dallas_id(self.rom.hex())
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def hw_id(self) -> str:
|
|
31
|
+
return self.hex_id[2:-2]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class OneWire(OneWireIO):
|
|
35
|
+
def __init__(self, ds2482: DS2482):
|
|
36
|
+
self.ds2482 = ds2482
|
|
37
|
+
|
|
38
|
+
def deinit(self):
|
|
39
|
+
"""
|
|
40
|
+
Deinitialize the OneWire bus and release any hardware resources for reuse.
|
|
41
|
+
"""
|
|
42
|
+
self.ds2482.device_reset()
|
|
43
|
+
|
|
44
|
+
def reset(self):
|
|
45
|
+
"""
|
|
46
|
+
Reset the OneWire bus and read presence
|
|
47
|
+
|
|
48
|
+
:return: False when at least one device is present
|
|
49
|
+
"""
|
|
50
|
+
return self.ds2482.reset()
|
|
51
|
+
|
|
52
|
+
def read_bit(self):
|
|
53
|
+
"""
|
|
54
|
+
Read in a bit
|
|
55
|
+
"""
|
|
56
|
+
return self.ds2482.single_bit()
|
|
57
|
+
|
|
58
|
+
def write_bit(self, value):
|
|
59
|
+
"""
|
|
60
|
+
Write out a bit based on value.
|
|
61
|
+
"""
|
|
62
|
+
self.ds2482.single_bit(value)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class OneWireBus(adafruit_onewire.bus.OneWireBus):
|
|
66
|
+
def __init__(self, ds2482: DS2482):
|
|
67
|
+
self._ow = OneWire(ds2482)
|
|
68
|
+
self._readbit = self._ow.read_bit
|
|
69
|
+
self._writebit = self._ow.write_bit
|
|
70
|
+
self._maximum_devices = adafruit_onewire.bus._MAX_DEV
|
|
71
|
+
|
|
72
|
+
def scan(self) -> List[OneWireAddress]:
|
|
73
|
+
"""Scan for devices on the bus and return a list of addresses."""
|
|
74
|
+
devices = []
|
|
75
|
+
diff = 65
|
|
76
|
+
rom = None
|
|
77
|
+
count = 0
|
|
78
|
+
for _ in range(0xFF):
|
|
79
|
+
rom, diff = self._search_rom(rom, diff)
|
|
80
|
+
if rom:
|
|
81
|
+
count += 1
|
|
82
|
+
if count > self.maximum_devices:
|
|
83
|
+
raise RuntimeError(
|
|
84
|
+
"Maximum device count of {} exceeded.".format(
|
|
85
|
+
self.maximum_devices
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
devices.append(OneWireAddress(rom))
|
|
89
|
+
if diff == 0:
|
|
90
|
+
break
|
|
91
|
+
return devices
|