boneIO 0.4.0.dev1__py3-none-any.whl → 0.5.0.dev1__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneIO
3
- Version: 0.4.0dev1
3
+ Version: 0.5.0dev1
4
4
  Summary: Python App for BoneIO
5
5
  License: GNU General Public License v3.0
6
6
  Author-email: Paweł Szafer <pszafer@gmail.com>
@@ -12,6 +12,7 @@ Requires-Dist: PyYAML>=6.0
12
12
  Requires-Dist: adafruit-circuitpython-ds18x20>=1.3.12
13
13
  Requires-Dist: adafruit-circuitpython-mcp230xx>=2.5.5
14
14
  Requires-Dist: adafruit-circuitpython-mcp9808>=3.3.14
15
+ Requires-Dist: adafruit-circuitpython-onewire>=2.0.1
15
16
  Requires-Dist: adafruit-circuitpython-pct2075>=1.1.14
16
17
  Requires-Dist: asyncio-mqtt>=0.12.1
17
18
  Requires-Dist: colorlog>=6.6.0
@@ -21,6 +22,7 @@ Requires-Dist: luma.oled>=3.8.1
21
22
  Requires-Dist: psutil>=5.9.1
22
23
  Requires-Dist: pymodbus>=2.5.3
23
24
  Requires-Dist: pyserial-asyncio>=0.6
25
+ Requires-Dist: w1thermsensor[async]>=2.0.0
24
26
  Project-URL: Changelog, https://github.com/boneIO-eu/app_bbb/releases
25
27
  Project-URL: Documentation, https://boneio.eu/docs/intro/
26
28
  Project-URL: Homepage, https://boneio.eu
@@ -1,6 +1,6 @@
1
1
  boneio/__init__.py,sha256=hoLKnu6h1uEsiCHA9Ql2MMDC7VQS0E-s_2cxBS-CTOg,147
2
2
  boneio/bonecli.py,sha256=-X_oGhitJklBpNDiVjYvqR9NEb3sdDTJ10axJRMYluk,3093
3
- boneio/const.py,sha256=TOBOLFoh5gmp54oDiSGnJDZsFx9V63o7i1aq26wk2o0,2718
3
+ boneio/const.py,sha256=fLoV4hv4cHqTV7XX3TRR-8HOFHjnWd-DoStvp8ysbPw,2779
4
4
  boneio/cover.py,sha256=8IChm8ugCRevuGNfotyff3OSO4fQu3yO9WC6CIFEfkI,8299
5
5
  boneio/example_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  boneio/example_config/adc.yaml,sha256=KaNfPuZmrhpiKJVUKC6uQXQ0YRCp0DoXVxYtqsbiSGI,168
@@ -8,30 +8,32 @@ boneio/example_config/config.yaml,sha256=JBUNy-dnsxUzDnvXBf4CLBTcNCuqa1EXyO0HaeM
8
8
  boneio/example_config/cover.yaml,sha256=rs7lv3vIEgAb3q96RKsJL7VMRsEvSNHG848dzZzSKsI,150
9
9
  boneio/example_config/input.yaml,sha256=U5pN5Dyb8XrhqHeXsa3rYE5VFI4Y_BapNJkv9c1ireQ,2883
10
10
  boneio/example_config/output24x16A.yaml,sha256=BTtHToRgz-U_rMMDbmHkM4wQxHakdzInb3zKMkOkj4w,1691
11
- boneio/example_config/output32x5A.yaml,sha256=az3pazwFROwxN5WIEcXp2Pnk734v2bBSYZ6UD56EpDA,2404
11
+ boneio/example_config/output32x5A.yaml,sha256=fwqBfU2rYh4hAkhkm8RzYCaM6CGeuR9hAIAGYrzBfek,2403
12
12
  boneio/fonts/danube__.ttf,sha256=KBRPUcGvmroCjrWC8zK4MulUb9lV8R0lXkOY7lNnQWc,19372
13
- boneio/helper/__init__.py,sha256=ajEPzzs1wbHXckdvKQXXy11DwdXTcCSykaSbzMCgyC0,1815
13
+ boneio/helper/__init__.py,sha256=MlFotbZ3DxwnJ2tT772_NA1tInyd8bs88-0AiFaVpX8,1858
14
+ boneio/helper/async_updater.py,sha256=BVh5mXFxgaZqoekjQbQSCTssfyVIdCQ80LCJny-rOo4,985
14
15
  boneio/helper/config.py,sha256=XeHG7OSMCMmEL43rCbWy6Ij0RcTNlrIpevWZ0UJyrlo,1311
15
- boneio/helper/ds2482/__init__.py,sha256=Zsh_6hLOta9gjognR_ECideMmwtMTYpWN757eybC6gc,311
16
- boneio/helper/ds2482/ds2482.py,sha256=c2t_hdAMtFsHw4Vw41QzO_hEDDNMeb3J71mEwEMUBhM,5169
17
- boneio/helper/ds2482/onewire.py,sha256=Q36Hprd6jsE_Pju0uC42-tZhS1CN8Xl2jOQl2vC9zkg,1111
18
16
  boneio/helper/events.py,sha256=63FEM5bKIDmMHncJG0NLcVHJZ7gIZBEb0TP7xtfyKvs,5579
19
17
  boneio/helper/exceptions.py,sha256=scepzfjzg-Jq6dBmuCDq79R5aUWohK3yDF8tyKi_sM8,561
20
18
  boneio/helper/gpio.py,sha256=uTFSHI6Gg1VZX2agEPd980s5pk3EW0bApGICI3nGVHs,2767
21
19
  boneio/helper/ha_discovery.py,sha256=dWV7s_r3fun4JgKPY0Jrvk8DLatczW-zLoINU36vfLU,5478
22
- boneio/helper/loader.py,sha256=ktfm6cBBWGVTLTdVqUA8vmIyYVEsr-MNZmLbXlceiNE,11172
20
+ boneio/helper/loader.py,sha256=ttQzWburVh3gIMWLwwHmJ_7ftO0v7Chf4NXeXuwntEw,11616
23
21
  boneio/helper/logger.py,sha256=zyF_Vk3o2eSHuXypJhNzK99eZgkWDWybuB5KcJgurDs,1801
24
- boneio/helper/mqtt.py,sha256=q_0K5TOWNZNCvmhpHuFWloRSVyGxdklogx0jYxc5cpg,741
22
+ boneio/helper/mqtt.py,sha256=Aqf6Sx4-3GQsK5GjgJ5QxVMyCTdRcL5Zq_GTIDu7ne0,759
25
23
  boneio/helper/oled.py,sha256=f0XYbaFstUbJ6ISmFe1vQCnmNVMctQWtnStNdROrblc,351
24
+ boneio/helper/onewire/W1ThermSensor.py,sha256=Pu5Fp29pKbxjJqDbFs05Mjg3Vy-9z_DTVoBpSWM_byA,2430
25
+ boneio/helper/onewire/__init__.py,sha256=4djH-uxiq5XhAiFTOxyqjvWVoJe0c8U8iN0BfmH8nSU,448
26
+ boneio/helper/onewire/ds2482.py,sha256=c2t_hdAMtFsHw4Vw41QzO_hEDDNMeb3J71mEwEMUBhM,5169
27
+ boneio/helper/onewire/onewire.py,sha256=tHofTu1l0qG7hH2XoSf-lj8gW7wVKe27j57qQWpVMPg,2497
26
28
  boneio/helper/queue.py,sha256=7fE7d344-BEW8sljN40wmqsbBr4kPLvz4ShBjkT04p8,1066
27
29
  boneio/helper/state_manager.py,sha256=LsMQRrD7WXu5jXFoltYXvzHDeiNDDEx6UWYebFw18gc,1994
28
- boneio/helper/stats.py,sha256=GfP-rboiV8_xylLmdQNo2_C--lHCJdfW1j9KPJcJP7Q,4897
29
- boneio/helper/timeperiod.py,sha256=oSkFemRJL-Ifcq8R4y7zBxG1KeYubi8286bgwxtFgbs,5652
30
+ boneio/helper/stats.py,sha256=546RPPl0N3Dq19UPTDZCeLg6LiLALrKPo6CnugQ5Hrk,5103
31
+ boneio/helper/timeperiod.py,sha256=xpg9oe30Z5WiLDQPq3EBKKScejOnN47NhcpeFvDd3bY,5806
30
32
  boneio/helper/util.py,sha256=QfSoT3H3WnOQAKO5bFRIBCy62HT5NMa9Ek-FmfTW_rw,508
31
33
  boneio/helper/yaml_util.py,sha256=LFT5abDVcC7DYmauIK52PV4icnHS9V5Io4LhGbcUPJU,10696
32
34
  boneio/input/__init__.py,sha256=u9wuehuC_TNizL4tyn7EygZW5LaTFjSnFaZeZr3zZ1U,99
33
35
  boneio/input/gpio.py,sha256=2WK3DR3kGAxHvmsNHZhN-oq8dF75oROxwm_mOZzYYh8,4391
34
- boneio/manager.py,sha256=BciKI1fw1w6GHRwFMar36Dr8IqDOtf4BHHktoQFOpCI,17137
36
+ boneio/manager.py,sha256=NoHDUgRlzdp1pgxDcu-Y6UlO1OVOGISNJffY6zCrsIM,18288
35
37
  boneio/modbus.py,sha256=5hambvcQ8XBRzw65OgcUlUV3xsVdq0Lx9jRj3bEF3SE,4156
36
38
  boneio/mqtt_client.py,sha256=ioOBEmnbjpZjYrD5u8W5CrVsrNFRHDJ93fyk6XcWkeE,6983
37
39
  boneio/oled.py,sha256=I4aH8v9MUFQ6vu2phpJpLa9ZLSFNUJZj-RjhGpfzILI,4836
@@ -39,25 +41,25 @@ boneio/relay/__init__.py,sha256=L_Peoep10-DdeMrEe-5YnnNCS-mxHtavCqtAesTPWFQ,135
39
41
  boneio/relay/basic.py,sha256=zOXf84yTGeArk3ghXt_WI2ul8L0RxyziOTD6U7-nCLM,2629
40
42
  boneio/relay/gpio.py,sha256=s64FBf6zlxciF57xJ6nrvy0t5Rie0uiXlwos0HL3RKM,1163
41
43
  boneio/relay/mcp.py,sha256=DhgqZbFHB6TucL9hJaJiqdVAbkw4Rv5VPHm_khSBIFo,2669
42
- boneio/runner.py,sha256=t5MOCbmNwD4hrGM_IzD9PP88Fd6F4q726w2nJqD-A2g,2163
44
+ boneio/runner.py,sha256=Cp5VzH5ppPFt0_lncj90MLwXIi4BGLGPK0kyZ0rxY5I,2233
43
45
  boneio/schema/actions.yaml,sha256=uTbrg7hET5cFdPS9LiArmkq1FbIekuzvbEyIqJOxruc,970
44
46
  boneio/schema/actions_sensor.yaml,sha256=LhXEsYsg6qs7iHqgQE6n-2jj-o-ZZRusDW_9nWIiZAY,129
45
47
  boneio/schema/actions_switch.yaml,sha256=qyooX0izkgl4wBEh8xUsYFEKMrvhbIAQYxOGTB5AROY,124
46
- boneio/schema/schema.yaml,sha256=0o9P6aWOkMeP9IirErEEwPLjGpn6kxtWIqduTP5dPSI,11179
47
- boneio/sensor/__init__.py,sha256=Lz6oMRxH2P9q7u0hD5DztgGVU0TkxNH6H5OLCElkx5I,419
48
- boneio/sensor/adc.py,sha256=PhhUqRcMgMGD1fEUvKrAn5fkTF_oyWUWnNQew6fO6AQ,1245
48
+ boneio/schema/schema.yaml,sha256=Tp_I_H4zpZehQVT0ejsj_ush9ShHMZwgG9YN0SL7Lho,11682
49
+ boneio/sensor/__init__.py,sha256=VjFBEQQv_U0T2ENkzefuBdzmqNvBTEv4M-gQKScc8o0,431
50
+ boneio/sensor/adc.py,sha256=JBdPJf-gE-9QyHQ_TcbrgAAXu5f64i_WpWnACxjJgSU,1086
49
51
  boneio/sensor/gpio.py,sha256=7IOYxO7F89DaNw6FpD8hk7f543hZeqljyrBRuy2z1yw,1230
50
- boneio/sensor/modbus/__init__.py,sha256=bf697azJSsxfxxPgEilk8mE0wWaUdZ7BDJlfp8vLxlc,8723
52
+ boneio/sensor/modbus/__init__.py,sha256=mChzuWicavaMybA8DkJZCu6BRjSI4hvaJX6_B1Fu_1g,8435
51
53
  boneio/sensor/modbus/sdm120.json,sha256=4sueFfSw7G6a77gdIUhbfJvE-MNVJFOeVbRvHDw5Rvk,4145
52
54
  boneio/sensor/modbus/sdm630.json,sha256=6LbIfXWk_PVRW-OuJwrsFEnRGLVEmEqqGIbj-1FDaiI,10969
53
55
  boneio/sensor/modbus/sofar.json,sha256=A_YztQN_ctyItIm2LH1tfcs-pSyG18I530qleLd2tOw,5592
54
- boneio/sensor/temp/__init__.py,sha256=hKQrmvOR6_WH3YQCfJl2IAsR4CT4OLZMo8Xgswd5NEw,2184
55
- boneio/sensor/temp/dallas.py,sha256=RwZ8wnLNx6xR4m7SKW7GYyJotCVRaUjs4RCwNKQhTvU,1173
56
+ boneio/sensor/temp/__init__.py,sha256=YSwZ5i5dvqo8zO9gKJHqXWgUZDwB3DqkC6o3H3A4mPk,1242
57
+ boneio/sensor/temp/dallas.py,sha256=HF8n56sI5oAZZm9jhBgwjWPeM2HjqPkG8LJO7D9bsDM,2082
56
58
  boneio/sensor/temp/lm75.py,sha256=-mpOv78429plRPBp9s09Ljz1x2Bdxuagalqz40vlAKE,243
57
59
  boneio/sensor/temp/mcp9808.py,sha256=yAh5yJzZLGTqa39xV4fyqsruj7oy3niOZAUV2W6eyCM,271
58
- boneio/version.py,sha256=3w7d6PS_ZJm3grCQUSPESBaIF9TDArfPUt7RNwrsII4,41
59
- boneIO-0.4.0.dev1.dist-info/entry_points.txt,sha256=Igl1SMDEWwMg144bwRz28UOCb80hdxomC99QJ3u6qC0,46
60
- boneIO-0.4.0.dev1.dist-info/WHEEL,sha256=khjdxotGbc8bZApx0GgksEHx3PnpKRv5eEmix1B9fDY,87
61
- boneIO-0.4.0.dev1.dist-info/METADATA,sha256=ZNiU5WHF_oVaIMBHJoJb0on0WSsKwu9vPnWgUBsM6oo,1524
62
- boneIO-0.4.0.dev1.dist-info/license_files/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
63
- boneIO-0.4.0.dev1.dist-info/RECORD,,
60
+ boneio/version.py,sha256=fEpbSNjNipN-A5Qcf9zghnZp3HoaeSRY6MExnh7RMTY,41
61
+ boneIO-0.5.0.dev1.dist-info/entry_points.txt,sha256=Igl1SMDEWwMg144bwRz28UOCb80hdxomC99QJ3u6qC0,46
62
+ boneIO-0.5.0.dev1.dist-info/WHEEL,sha256=g_UdFZqm-k6b0W64OcndB0YT_D2mFFPAYBj7-_YsSPA,87
63
+ boneIO-0.5.0.dev1.dist-info/METADATA,sha256=T2-Ec0PnTfFIlHVJGyo3662BmrFHT02XcePhN7j6ThU,1620
64
+ boneIO-0.5.0.dev1.dist-info/license_files/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
65
+ boneIO-0.5.0.dev1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: pdm-pep517 1.0.0
2
+ Generator: pdm-pep517 1.0.4
3
3
  Root-Is-Purelib: True
4
4
  Tag: py3-none-any
boneio/const.py CHANGED
@@ -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: 8
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: 9
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: 10
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: 11
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: 12
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: 14
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: 15
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: 8
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: 10
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: 11
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: 12
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: 13
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: 14
190
+ pin: 9
192
191
  output_type: light
193
192
 
194
193
  - id: OUT_32
boneio/helper/__init__.py CHANGED
@@ -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, host_stats
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)
boneio/helper/loader.py CHANGED
@@ -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.ds2482 import DS2482, DS2482_ADDRESS, OneWireBus, ds_address
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 DallasSensor
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
- adc = GpioADCSensor(
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
- sdm = ModbusSensor(
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 find_onewire_devices(ow_bus: OneWireBus):
353
- devices = ow_bus.scan()
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
- for device in devices:
356
- _addr: int = ds_address(device.rom)
357
- _LOGGER.debug("Found device with address %s", hex(_addr))
358
- out[_addr] = device
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 create_ds2482_dallas_sensor(
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
- sensor = DallasSensor(
372
- bus=ds2482_bus,
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,
boneio/helper/mqtt.py CHANGED
@@ -12,6 +12,7 @@ class BasicMqtt:
12
12
  name: str,
13
13
  send_message: Callable[[str, Union[str, dict]], None],
14
14
  topic_type: str,
15
+ **kwargs,
15
16
  ):
16
17
  """Initialize module."""
17
18
  self._id = id.replace(" ", "")
@@ -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