boneIO 0.1.0.dev15__tar.gz → 0.1.0.dev16__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.1.0.dev15 → boneio-0.1.0.dev16}/PKG-INFO +2 -2
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/bonecli.py +2 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/const.py +2 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/__init__.py +8 -1
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/ha_discovery.py +23 -3
- boneio-0.1.0.dev16/boneio/helper/mqtt.py +30 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/stats.py +6 -6
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/manager.py +42 -9
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/oled.py +14 -3
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/relay/basic.py +5 -13
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/schema.yaml +31 -0
- boneio-0.1.0.dev16/boneio/sensor/__init__.py +6 -0
- boneio-0.1.0.dev16/boneio/sensor/adc.py +38 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/sensor/lm75.py +4 -20
- boneio-0.1.0.dev16/boneio/version.py +2 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/PKG-INFO +2 -2
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/SOURCES.txt +2 -0
- boneio-0.1.0.dev15/boneio/sensor/__init__.py +0 -5
- boneio-0.1.0.dev15/boneio/version.py +0 -2
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/MANIFEST.in +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/README.md +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/__init__.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/fonts/danube__.ttf +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/exceptions.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/gpio.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/oled.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/helper/yaml.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/input/__init__.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/input/gpio.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/mqtt_client.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/relay/__init__.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/relay/gpio.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/relay/mcp.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio/sensor/gpio.py +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/dependency_links.txt +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/entry_points.txt +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/requires.txt +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/boneio.egg-info/top_level.txt +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/requirements.txt +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/setup.cfg +0 -0
- {boneio-0.1.0.dev15 → boneio-0.1.0.dev16}/setup.py +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev16
|
|
4
4
|
Summary: Python Helper for BoneIO
|
|
5
5
|
Home-page: https://github.com/maciejk1984/boneIO
|
|
6
6
|
License: GNU General Public License v3.0
|
|
7
|
-
Download-URL: https://github.com/maciejk1984/boneIO/archive/0.1.0.
|
|
7
|
+
Download-URL: https://github.com/maciejk1984/boneIO/archive/0.1.0.dev16.zip
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.7
|
|
@@ -20,6 +20,7 @@ from boneio.const import (
|
|
|
20
20
|
TOPIC_PREFIX,
|
|
21
21
|
USERNAME,
|
|
22
22
|
LM75,
|
|
23
|
+
ADC,
|
|
23
24
|
)
|
|
24
25
|
from boneio.helper import CustomValidator, load_yaml_file
|
|
25
26
|
from boneio.manager import Manager
|
|
@@ -141,6 +142,7 @@ async def run(ctx, debug: int, config: str, mqttpassword: str = ""):
|
|
|
141
142
|
mcp23017=_config.get(MCP23017, []),
|
|
142
143
|
lm75=_config.get(LM75),
|
|
143
144
|
oled=_config.get(OLED),
|
|
145
|
+
adc_list=_config.get(ADC, []),
|
|
144
146
|
)
|
|
145
147
|
tasks = set()
|
|
146
148
|
tasks.update(manager.get_tasks())
|
|
@@ -9,16 +9,20 @@ from boneio.helper.gpio import (
|
|
|
9
9
|
configure_pin,
|
|
10
10
|
)
|
|
11
11
|
from boneio.helper.oled import make_font
|
|
12
|
+
from boneio.helper.mqtt import BasicMqtt
|
|
12
13
|
from boneio.helper.stats import HostData, host_stats
|
|
13
14
|
from boneio.helper.yaml import CustomValidator, load_yaml_file
|
|
14
15
|
from boneio.helper.ha_discovery import (
|
|
15
16
|
ha_relay_availibilty_message,
|
|
16
|
-
ha_sensor_availibilty_message,
|
|
17
17
|
ha_sensor_temp_availibilty_message,
|
|
18
18
|
ha_binary_sensor_availibilty_message,
|
|
19
|
+
ha_input_availibilty_message,
|
|
20
|
+
ha_sensor_availibilty_message,
|
|
21
|
+
ha_adc_sensor_availibilty_message,
|
|
19
22
|
)
|
|
20
23
|
from boneio.helper.exceptions import GPIOInputException, I2CError
|
|
21
24
|
|
|
25
|
+
|
|
22
26
|
__all__ = [
|
|
23
27
|
"CustomValidator",
|
|
24
28
|
"load_yaml_file",
|
|
@@ -32,10 +36,13 @@ __all__ = [
|
|
|
32
36
|
"make_font",
|
|
33
37
|
"ha_relay_availibilty_message",
|
|
34
38
|
"ha_sensor_availibilty_message",
|
|
39
|
+
"ha_adc_sensor_availibilty_message",
|
|
35
40
|
"ha_sensor_temp_availibilty_message",
|
|
36
41
|
"ha_binary_sensor_availibilty_message",
|
|
42
|
+
"ha_input_availibilty_message",
|
|
37
43
|
"GPIOInputException",
|
|
38
44
|
"I2CError",
|
|
39
45
|
"GpioBaseClass",
|
|
40
46
|
"configure_pin",
|
|
47
|
+
"BasicMqtt",
|
|
41
48
|
]
|
|
@@ -25,7 +25,9 @@ def ha_relay_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def
|
|
28
|
+
def ha_availibilty_message(
|
|
29
|
+
id: str, name: str, topic: str = "boneio", sensor_type: str = INPUT
|
|
30
|
+
):
|
|
29
31
|
"""Create availability topic for HA."""
|
|
30
32
|
return {
|
|
31
33
|
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
@@ -38,11 +40,29 @@ def ha_sensor_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
|
38
40
|
},
|
|
39
41
|
"icon": "mdi:gesture-double-tap",
|
|
40
42
|
"name": name,
|
|
41
|
-
"state_topic": f"{topic}/{
|
|
42
|
-
"unique_id": f"{topic}{
|
|
43
|
+
"state_topic": f"{topic}/{sensor_type}/{id}",
|
|
44
|
+
"unique_id": f"{topic}{sensor_type}{id}",
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
|
|
48
|
+
def ha_input_availibilty_message(**kwargs):
|
|
49
|
+
return ha_availibilty_message(sensor_type=INPUT, **kwargs)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def ha_adc_sensor_availibilty_message(**kwargs):
|
|
53
|
+
msg = ha_availibilty_message(sensor_type=SENSOR, **kwargs)
|
|
54
|
+
msg["unit_of_measurement"] = "V"
|
|
55
|
+
msg["device_class"] = "voltage"
|
|
56
|
+
msg["state_class"] = "measurement"
|
|
57
|
+
return msg
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def ha_sensor_availibilty_message(unit_of_measurement: str = None, **kwargs):
|
|
61
|
+
msg = ha_availibilty_message(sensor_type=SENSOR, **kwargs)
|
|
62
|
+
if not unit_of_measurement:
|
|
63
|
+
return msg
|
|
64
|
+
|
|
65
|
+
|
|
46
66
|
def ha_binary_sensor_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
47
67
|
"""Create availability topic for HA."""
|
|
48
68
|
return {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Class to help initialize classes which uses mqtt send."""
|
|
2
|
+
from typing import Callable, Union
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BasicMqtt:
|
|
6
|
+
"""Basic MQTT class."""
|
|
7
|
+
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
id: str,
|
|
11
|
+
topic_prefix: str,
|
|
12
|
+
name: str,
|
|
13
|
+
send_message: Callable[[str, Union[str, dict]], None],
|
|
14
|
+
topic_type: str,
|
|
15
|
+
):
|
|
16
|
+
"""Initialize module."""
|
|
17
|
+
self._id = id.replace(" ", "")
|
|
18
|
+
self._name = name
|
|
19
|
+
self._send_message = send_message
|
|
20
|
+
self._send_topic = f"{topic_prefix}/{topic_type}/{self.id}"
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def id(self) -> bool:
|
|
24
|
+
"""Id of the module."""
|
|
25
|
+
return self._id
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def name(self):
|
|
29
|
+
"""Return name of the sensor."""
|
|
30
|
+
return self._name
|
|
@@ -85,9 +85,9 @@ async def get_memory_info(host_data):
|
|
|
85
85
|
host_data.write(
|
|
86
86
|
MEMORY,
|
|
87
87
|
{
|
|
88
|
-
"total": f"{floor(vm.total / MEGABYTE)}
|
|
89
|
-
"used": f"{floor(vm.used / MEGABYTE)}
|
|
90
|
-
"free": f"{floor(vm.available / MEGABYTE)}
|
|
88
|
+
"total": f"{floor(vm.total / MEGABYTE)}MB",
|
|
89
|
+
"used": f"{floor(vm.used / MEGABYTE)}MB",
|
|
90
|
+
"free": f"{floor(vm.available / MEGABYTE)}MB",
|
|
91
91
|
},
|
|
92
92
|
)
|
|
93
93
|
await asyncio.sleep(10)
|
|
@@ -100,9 +100,9 @@ async def get_swap_info(host_data):
|
|
|
100
100
|
host_data.write(
|
|
101
101
|
SWAP,
|
|
102
102
|
{
|
|
103
|
-
"total": f"{floor(swap.total / MEGABYTE)}
|
|
104
|
-
"used": f"{floor(swap.used / MEGABYTE)}
|
|
105
|
-
"free": f"{floor(swap.free / MEGABYTE)}
|
|
103
|
+
"total": f"{floor(swap.total / MEGABYTE)}MB",
|
|
104
|
+
"used": f"{floor(swap.used / MEGABYTE)}MB",
|
|
105
|
+
"free": f"{floor(swap.free / MEGABYTE)}MB",
|
|
106
106
|
},
|
|
107
107
|
)
|
|
108
108
|
await asyncio.sleep(10)
|
|
@@ -33,11 +33,13 @@ from boneio.const import (
|
|
|
33
33
|
SHOW_HA,
|
|
34
34
|
BINARY_SENSOR,
|
|
35
35
|
INPUT_SENSOR,
|
|
36
|
+
UPDATE_INTERVAL,
|
|
36
37
|
)
|
|
37
38
|
from boneio.helper import (
|
|
38
39
|
HostData,
|
|
39
40
|
ha_relay_availibilty_message,
|
|
40
|
-
|
|
41
|
+
ha_input_availibilty_message,
|
|
42
|
+
ha_adc_sensor_availibilty_message,
|
|
41
43
|
ha_sensor_temp_availibilty_message,
|
|
42
44
|
ha_binary_sensor_availibilty_message,
|
|
43
45
|
host_stats,
|
|
@@ -66,6 +68,7 @@ class Manager:
|
|
|
66
68
|
ha_discovery_prefix: str = HOMEASSISTANT,
|
|
67
69
|
mcp23017: Optional[List] = None,
|
|
68
70
|
oled: bool = False,
|
|
71
|
+
adc_list: Optional[List] = None,
|
|
69
72
|
) -> None:
|
|
70
73
|
"""Initialize the manager."""
|
|
71
74
|
_LOGGER.info("Initializing manager module.")
|
|
@@ -126,12 +129,48 @@ class Manager:
|
|
|
126
129
|
_LOGGER.error("Can't connect to MCP %s. %s", id, err)
|
|
127
130
|
pass
|
|
128
131
|
|
|
132
|
+
def create_adc():
|
|
133
|
+
from boneio.sensor import initialize_adc, GpioADCSensor
|
|
134
|
+
|
|
135
|
+
initialize_adc()
|
|
136
|
+
|
|
137
|
+
## TODO: find what exception can ADC gpio throw.
|
|
138
|
+
for gpio in adc_list:
|
|
139
|
+
name = gpio.get(ID)
|
|
140
|
+
id = name.replace(" ", "")
|
|
141
|
+
pin = gpio[PIN]
|
|
142
|
+
try:
|
|
143
|
+
adc = GpioADCSensor(
|
|
144
|
+
id=id,
|
|
145
|
+
pin=pin,
|
|
146
|
+
name=name,
|
|
147
|
+
send_message=self.send_message,
|
|
148
|
+
topic_prefix=topic_prefix,
|
|
149
|
+
update_interval=gpio.get(UPDATE_INTERVAL, 60),
|
|
150
|
+
)
|
|
151
|
+
self.send_ha_autodiscovery(
|
|
152
|
+
id=id,
|
|
153
|
+
name=name,
|
|
154
|
+
ha_type=SENSOR,
|
|
155
|
+
prefix=ha_discovery_prefix,
|
|
156
|
+
availibilty_msg_func=ha_adc_sensor_availibilty_message,
|
|
157
|
+
)
|
|
158
|
+
self._tasks.append(asyncio.create_task(adc.send_state()))
|
|
159
|
+
except I2CError as err:
|
|
160
|
+
_LOGGER.error("Can't configure ADC sensor %s. %s", id, err)
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
return True
|
|
164
|
+
|
|
129
165
|
if lm75:
|
|
130
166
|
create_lm75_sensor()
|
|
131
167
|
|
|
132
168
|
if mcp23017:
|
|
133
169
|
create_mcp23017()
|
|
134
170
|
|
|
171
|
+
if adc_list:
|
|
172
|
+
create_adc()
|
|
173
|
+
|
|
135
174
|
def configure_relay(gpio: dict) -> Any:
|
|
136
175
|
"""Configure kind of relay. Most common MCP."""
|
|
137
176
|
relay_id = gpio[ID].replace(" ", "")
|
|
@@ -212,15 +251,9 @@ class Manager:
|
|
|
212
251
|
),
|
|
213
252
|
rest_pin=gpio,
|
|
214
253
|
)
|
|
215
|
-
availibilty_msg_func =
|
|
254
|
+
availibilty_msg_func = ha_input_availibilty_message
|
|
216
255
|
ha_type = SENSOR
|
|
217
256
|
if gpio.get(SHOW_HA, True):
|
|
218
|
-
print(
|
|
219
|
-
"INPUT sending disco",
|
|
220
|
-
ha_type,
|
|
221
|
-
ha_discovery_prefix,
|
|
222
|
-
availibilty_msg_func,
|
|
223
|
-
)
|
|
224
257
|
self.send_ha_autodiscovery(
|
|
225
258
|
id=pin,
|
|
226
259
|
name=gpio.get(ID, pin),
|
|
@@ -250,7 +283,7 @@ class Manager:
|
|
|
250
283
|
self._oled = Oled(
|
|
251
284
|
host_data=self._host_data, output_groups=list(self._grouped_outputs)
|
|
252
285
|
)
|
|
253
|
-
except GPIOInputException as err:
|
|
286
|
+
except (GPIOInputException, I2CError) as err:
|
|
254
287
|
_LOGGER.error("Can't configure OLED display. %s", err)
|
|
255
288
|
|
|
256
289
|
self.send_message(topic=f"{topic_prefix}/{STATE}", payload=ONLINE)
|
|
@@ -5,10 +5,18 @@ from typing import List
|
|
|
5
5
|
from luma.core.interface.serial import i2c
|
|
6
6
|
from luma.core.render import canvas
|
|
7
7
|
from luma.oled.device import sh1106
|
|
8
|
+
from luma.core.error import DeviceNotFoundError
|
|
8
9
|
from PIL import ImageDraw
|
|
9
10
|
|
|
10
11
|
from boneio.const import CPU, DISK, MEMORY, NETWORK, OLED_PIN, SWAP, UPTIME, WHITE
|
|
11
|
-
from boneio.helper import
|
|
12
|
+
from boneio.helper import (
|
|
13
|
+
HostData,
|
|
14
|
+
configure_pin,
|
|
15
|
+
edge_detect,
|
|
16
|
+
make_font,
|
|
17
|
+
setup_input,
|
|
18
|
+
I2CError,
|
|
19
|
+
)
|
|
12
20
|
|
|
13
21
|
_LOGGER = logging.getLogger(__name__)
|
|
14
22
|
|
|
@@ -38,8 +46,11 @@ class Oled:
|
|
|
38
46
|
configure_pin(OLED_PIN)
|
|
39
47
|
setup_input(OLED_PIN)
|
|
40
48
|
edge_detect(pin=OLED_PIN, callback=self._handle_press, bounce=50)
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
try:
|
|
50
|
+
serial = i2c(port=2, address=0x3C)
|
|
51
|
+
self._device = sh1106(serial)
|
|
52
|
+
except DeviceNotFoundError as err:
|
|
53
|
+
raise I2CError(err)
|
|
43
54
|
_LOGGER.debug("Configuring OLED screen.")
|
|
44
55
|
|
|
45
56
|
def _draw_standard(self, data: dict, draw: ImageDraw) -> None:
|
|
@@ -2,31 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
|
-
from typing import Callable
|
|
5
|
+
from typing import Callable
|
|
6
6
|
|
|
7
7
|
from boneio.const import OFF, ON, RELAY, STATE, SWITCH
|
|
8
|
+
from boneio.helper import BasicMqtt
|
|
8
9
|
|
|
9
10
|
_LOGGER = logging.getLogger(__name__)
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
class BasicRelay:
|
|
13
|
+
class BasicRelay(BasicMqtt):
|
|
13
14
|
"""Basic relay class."""
|
|
14
15
|
|
|
15
16
|
def __init__(
|
|
16
|
-
self,
|
|
17
|
-
send_message: Callable[[str, Union[str, dict]], None],
|
|
18
|
-
callback: Callable,
|
|
19
|
-
topic_prefix: str,
|
|
20
|
-
id: str = None,
|
|
21
|
-
ha_type=SWITCH,
|
|
17
|
+
self, callback: Callable, id: str = None, ha_type=SWITCH, **kwargs
|
|
22
18
|
) -> None:
|
|
23
19
|
"""Initialize Basic relay."""
|
|
24
|
-
|
|
25
|
-
self._name = id
|
|
20
|
+
super().__init__(id=id, name=id, topic_type=RELAY, **kwargs)
|
|
26
21
|
self._ha_type = ha_type
|
|
27
|
-
self._send_message = send_message
|
|
28
|
-
self._relay_topic = f"{topic_prefix}/{RELAY}/"
|
|
29
|
-
self._send_topic = f"{self._relay_topic}{self.id}"
|
|
30
22
|
self._state = False
|
|
31
23
|
self._callback = callback
|
|
32
24
|
self._loop = asyncio.get_running_loop()
|
|
@@ -225,3 +225,34 @@ input:
|
|
|
225
225
|
type: string
|
|
226
226
|
message:
|
|
227
227
|
type: string
|
|
228
|
+
|
|
229
|
+
adc:
|
|
230
|
+
type: list
|
|
231
|
+
meta:
|
|
232
|
+
label: GPIO ADC section
|
|
233
|
+
schema:
|
|
234
|
+
type: dict
|
|
235
|
+
schema:
|
|
236
|
+
id:
|
|
237
|
+
type: string
|
|
238
|
+
required: False
|
|
239
|
+
meta:
|
|
240
|
+
label: Id to use in HA if needed. Default to pin number.
|
|
241
|
+
pin:
|
|
242
|
+
type: string
|
|
243
|
+
required: True
|
|
244
|
+
allowed: ['P9_33', 'P9_35', 'P9_36', 'P9_37', 'P9_38', 'P9_39', 'P9_40']
|
|
245
|
+
meta:
|
|
246
|
+
label: PIN to use.
|
|
247
|
+
update_interval:
|
|
248
|
+
type: integer
|
|
249
|
+
required: True
|
|
250
|
+
default: 60
|
|
251
|
+
meta:
|
|
252
|
+
label: Update interval in seconds.
|
|
253
|
+
show_in_ha:
|
|
254
|
+
type: boolean
|
|
255
|
+
required: True
|
|
256
|
+
default: True
|
|
257
|
+
meta:
|
|
258
|
+
label: If you want you can disable discovering this input in HA.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""ADC GPIO BBB sensor."""
|
|
2
|
+
import logging
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
from boneio.const import SENSOR
|
|
6
|
+
from boneio.helper import BasicMqtt
|
|
7
|
+
import Adafruit_BBIO.ADC as ADC
|
|
8
|
+
|
|
9
|
+
_LOGGER = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def initialize_adc():
|
|
13
|
+
ADC.setup()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GpioADCSensor(BasicMqtt):
|
|
17
|
+
"""Represent Gpio ADC sensor."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, pin: str, update_interval: int = 60, **kwargs) -> None:
|
|
20
|
+
"""Setup GPIO ADC Sensor"""
|
|
21
|
+
super().__init__(topic_type=SENSOR, **kwargs)
|
|
22
|
+
self._pin = pin
|
|
23
|
+
self._update_interval = update_interval
|
|
24
|
+
_LOGGER.debug("Configured sensor pin %s", self._pin)
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def state(self):
|
|
28
|
+
"""Give rounded value of temperature."""
|
|
29
|
+
return round(ADC.read(self._pin) * 1.8, 2)
|
|
30
|
+
|
|
31
|
+
async def send_state(self):
|
|
32
|
+
"""Fetch temperature periodically and send to MQTT."""
|
|
33
|
+
while True:
|
|
34
|
+
self._send_message(
|
|
35
|
+
topic=self._send_topic,
|
|
36
|
+
payload=self.state,
|
|
37
|
+
)
|
|
38
|
+
await asyncio.sleep(self._update_interval)
|
|
@@ -2,39 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
from adafruit_pct2075 import PCT2075
|
|
5
|
-
from typing import Callable, Union
|
|
6
5
|
from boneio.const import STATE, SENSOR, LM75
|
|
7
6
|
|
|
8
7
|
from boneio.helper.exceptions import I2CError
|
|
8
|
+
from boneio.helper import BasicMqtt
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class LM75Sensor:
|
|
11
|
+
class LM75Sensor(BasicMqtt):
|
|
12
12
|
"""Represent LM75 sensor in BoneIO."""
|
|
13
13
|
|
|
14
|
-
def __init__(
|
|
15
|
-
self,
|
|
16
|
-
i2c,
|
|
17
|
-
address,
|
|
18
|
-
topic_prefix: str,
|
|
19
|
-
name: str,
|
|
20
|
-
send_message: Callable[[str, Union[str, dict]], None],
|
|
21
|
-
id: str = LM75,
|
|
22
|
-
):
|
|
14
|
+
def __init__(self, i2c, address, id: str = LM75, **kwargs):
|
|
23
15
|
"""Initialize LM75 class."""
|
|
24
|
-
|
|
25
|
-
self._name = name
|
|
26
|
-
self._send_message = send_message
|
|
27
|
-
self._send_topic = f"{topic_prefix}/{SENSOR}/{self._id}"
|
|
16
|
+
super().__init__(id=id, topic_type=SENSOR, **kwargs)
|
|
28
17
|
try:
|
|
29
18
|
self._pct = PCT2075(i2c_bus=i2c, address=address)
|
|
30
19
|
except ValueError as err:
|
|
31
20
|
raise I2CError(err)
|
|
32
21
|
|
|
33
|
-
@property
|
|
34
|
-
def name(self):
|
|
35
|
-
"""Return name of the sensor."""
|
|
36
|
-
return self._name
|
|
37
|
-
|
|
38
22
|
@property
|
|
39
23
|
def state(self):
|
|
40
24
|
"""Give rounded value of temperature."""
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev16
|
|
4
4
|
Summary: Python Helper for BoneIO
|
|
5
5
|
Home-page: https://github.com/maciejk1984/boneIO
|
|
6
6
|
License: GNU General Public License v3.0
|
|
7
|
-
Download-URL: https://github.com/maciejk1984/boneIO/archive/0.1.0.
|
|
7
|
+
Download-URL: https://github.com/maciejk1984/boneIO/archive/0.1.0.dev16.zip
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.7
|
|
@@ -21,6 +21,7 @@ boneio/helper/__init__.py
|
|
|
21
21
|
boneio/helper/exceptions.py
|
|
22
22
|
boneio/helper/gpio.py
|
|
23
23
|
boneio/helper/ha_discovery.py
|
|
24
|
+
boneio/helper/mqtt.py
|
|
24
25
|
boneio/helper/oled.py
|
|
25
26
|
boneio/helper/stats.py
|
|
26
27
|
boneio/helper/yaml.py
|
|
@@ -31,5 +32,6 @@ boneio/relay/basic.py
|
|
|
31
32
|
boneio/relay/gpio.py
|
|
32
33
|
boneio/relay/mcp.py
|
|
33
34
|
boneio/sensor/__init__.py
|
|
35
|
+
boneio/sensor/adc.py
|
|
34
36
|
boneio/sensor/gpio.py
|
|
35
37
|
boneio/sensor/lm75.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|