boneIO 0.1.0.dev8__tar.gz → 0.1.0.dev11__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.dev8 → boneio-0.1.0.dev11}/PKG-INFO +2 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/bonecli.py +1 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/const.py +3 -0
- boneio-0.1.0.dev11/boneio/helper/__init__.py +23 -0
- boneio-0.1.0.dev11/boneio/helper/ha_discovery.py +64 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/helper/stats.py +17 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/input/gpio.py +2 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/manager.py +86 -46
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/oled.py +1 -1
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/relay/basic.py +9 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/schema.yaml +18 -1
- boneio-0.1.0.dev11/boneio/version.py +2 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/PKG-INFO +2 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/SOURCES.txt +1 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/requires.txt +1 -1
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/requirements.txt +1 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/setup.py +1 -1
- boneio-0.1.0.dev8/boneio/config.example.yaml +0 -38
- boneio-0.1.0.dev8/boneio/config.yaml +0 -20
- boneio-0.1.0.dev8/boneio/helper/__init__.py +0 -14
- boneio-0.1.0.dev8/boneio/version.py +0 -2
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/MANIFEST.in +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/README.md +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/__init__.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/fonts/danube__.ttf +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/helper/gpio.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/helper/oled.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/helper/yaml.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/input/__init__.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/mqtt_client.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/relay/__init__.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/relay/gpio.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio/relay/mcp.py +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/dependency_links.txt +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/entry_points.txt +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/boneio.egg-info/top_level.txt +0 -0
- {boneio-0.1.0.dev8 → boneio-0.1.0.dev11}/setup.cfg +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.dev11
|
|
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.dev11.zip
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.7
|
|
@@ -138,6 +138,7 @@ async def run(ctx, debug: int, config: str, mqttpassword: str = ""):
|
|
|
138
138
|
ha_discovery=_config[MQTT][HA_DISCOVERY][ENABLED],
|
|
139
139
|
ha_discovery_prefix=_config[MQTT][HA_DISCOVERY][TOPIC_PREFIX],
|
|
140
140
|
mcp23017=_config[MCP23017],
|
|
141
|
+
lm75=_config.get("lm75"),
|
|
141
142
|
oled=_config.get(OLED),
|
|
142
143
|
)
|
|
143
144
|
tasks = set()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Helper dir for BoneIO."""
|
|
2
|
+
from .gpio import edge_detect, setup_input
|
|
3
|
+
from .oled import make_font
|
|
4
|
+
from .stats import HostData, host_stats
|
|
5
|
+
from .yaml import CustomValidator, load_yaml_file
|
|
6
|
+
from .ha_discovery import (
|
|
7
|
+
ha_relay_availibilty_message,
|
|
8
|
+
ha_sensor_availibilty_message,
|
|
9
|
+
ha_sensor_temp_availibilty_message,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"CustomValidator",
|
|
14
|
+
"load_yaml_file",
|
|
15
|
+
"HostData",
|
|
16
|
+
"host_stats",
|
|
17
|
+
"setup_input",
|
|
18
|
+
"edge_detect",
|
|
19
|
+
"make_font",
|
|
20
|
+
"ha_relay_availibilty_message",
|
|
21
|
+
"ha_sensor_availibilty_message",
|
|
22
|
+
"ha_sensor_temp_availibilty_message",
|
|
23
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from ..version import __version__
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from ..const import INPUT, OFF, ON, RELAY, STATE, SENSOR
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def ha_relay_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
8
|
+
"""Create availability topic for HA."""
|
|
9
|
+
return {
|
|
10
|
+
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
11
|
+
"command_topic": f"{topic}/relay/{id}/set",
|
|
12
|
+
"device": {
|
|
13
|
+
"identifiers": [topic],
|
|
14
|
+
"manufacturer": "BoneIO",
|
|
15
|
+
"model": "BoneIO Relay Board",
|
|
16
|
+
"name": f"BoneIO {topic}",
|
|
17
|
+
"sw_version": __version__,
|
|
18
|
+
},
|
|
19
|
+
"name": name,
|
|
20
|
+
"payload_off": OFF,
|
|
21
|
+
"payload_on": ON,
|
|
22
|
+
"state_topic": f"{topic}/{RELAY}/{id}",
|
|
23
|
+
"unique_id": f"{topic}{RELAY}{id}",
|
|
24
|
+
"value_template": "{{ value_json.state }}",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def ha_sensor_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
29
|
+
"""Create availability topic for HA."""
|
|
30
|
+
return {
|
|
31
|
+
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
32
|
+
"device": {
|
|
33
|
+
"identifiers": [topic],
|
|
34
|
+
"manufacturer": "BoneIO",
|
|
35
|
+
"model": "BoneIO Relay Board",
|
|
36
|
+
"name": f"BoneIO {topic}",
|
|
37
|
+
"sw_version": __version__,
|
|
38
|
+
},
|
|
39
|
+
"icon": "mdi:gesture-double-tap",
|
|
40
|
+
"name": name,
|
|
41
|
+
"state_topic": f"{topic}/{INPUT}/{id}",
|
|
42
|
+
"unique_id": f"{topic}{INPUT}{id}",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def ha_sensor_temp_availibilty_message(id: str, name: str, topic: str = "boneio"):
|
|
47
|
+
"""Create availability topic for HA."""
|
|
48
|
+
return {
|
|
49
|
+
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
50
|
+
"device": {
|
|
51
|
+
"identifiers": [topic],
|
|
52
|
+
"manufacturer": "BoneIO",
|
|
53
|
+
"model": "BoneIO Relay Board",
|
|
54
|
+
"name": f"BoneIO {topic}",
|
|
55
|
+
"sw_version": __version__,
|
|
56
|
+
},
|
|
57
|
+
"name": name,
|
|
58
|
+
"state_topic": f"{topic}/{SENSOR}/{id}",
|
|
59
|
+
"unique_id": f"{topic}{SENSOR}{id}",
|
|
60
|
+
"device_class": "temperature",
|
|
61
|
+
"state_class": "measurement",
|
|
62
|
+
"unit_of_measurement": "°C",
|
|
63
|
+
"value_template": "{{ value_json.state }}",
|
|
64
|
+
}
|
|
@@ -7,7 +7,19 @@ from typing import Callable
|
|
|
7
7
|
|
|
8
8
|
import psutil
|
|
9
9
|
|
|
10
|
-
from ..const import
|
|
10
|
+
from ..const import (
|
|
11
|
+
CPU,
|
|
12
|
+
DISK,
|
|
13
|
+
GIGABYTE,
|
|
14
|
+
HOST,
|
|
15
|
+
MEGABYTE,
|
|
16
|
+
MEMORY,
|
|
17
|
+
NETWORK,
|
|
18
|
+
SWAP,
|
|
19
|
+
TEMPERATURE,
|
|
20
|
+
UPTIME,
|
|
21
|
+
)
|
|
22
|
+
from ..sensor.lm75 import LM75
|
|
11
23
|
|
|
12
24
|
intervals = (("d", 86400), ("h", 3600), ("m", 60))
|
|
13
25
|
|
|
@@ -120,10 +132,11 @@ class HostData:
|
|
|
120
132
|
|
|
121
133
|
data = {UPTIME: {}, NETWORK: {}, CPU: {}, DISK: {}, MEMORY: {}, SWAP: {}}
|
|
122
134
|
|
|
123
|
-
def __init__(self, output: dict, callback: Callable) -> None:
|
|
135
|
+
def __init__(self, output: dict, callback: Callable, lm75: LM75) -> None:
|
|
124
136
|
"""Initialize HostData."""
|
|
125
137
|
self._hostname = socket.gethostname()
|
|
126
138
|
self.data[UPTIME] = {HOST: self._hostname, UPTIME: 0}
|
|
139
|
+
self._lm75 = lm75
|
|
127
140
|
self._output = output
|
|
128
141
|
self._callback = callback
|
|
129
142
|
self._loop = asyncio.get_running_loop()
|
|
@@ -136,6 +149,8 @@ class HostData:
|
|
|
136
149
|
def write_uptime(self, uptime: str) -> None:
|
|
137
150
|
"""Write uptime."""
|
|
138
151
|
self.data[UPTIME][UPTIME] = uptime
|
|
152
|
+
if self._lm75:
|
|
153
|
+
self.data[UPTIME][self._lm75.name] = self._lm75.state
|
|
139
154
|
self._loop.call_soon_threadsafe(partial(self._callback, UPTIME))
|
|
140
155
|
|
|
141
156
|
def get(self, type: str) -> dict:
|
|
@@ -4,7 +4,7 @@ import logging
|
|
|
4
4
|
import subprocess
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from functools import partial
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Callable
|
|
8
8
|
|
|
9
9
|
from ..const import (
|
|
10
10
|
CONFIG_PIN,
|
|
@@ -37,7 +37,7 @@ class GpioInputButton:
|
|
|
37
37
|
"""Represent Gpio input switch."""
|
|
38
38
|
|
|
39
39
|
def __init__(
|
|
40
|
-
self, pin: str, press_callback: Callable[[ClickTypes, str], None],
|
|
40
|
+
self, pin: str, press_callback: Callable[[ClickTypes, str], None], **kwargs
|
|
41
41
|
) -> None:
|
|
42
42
|
"""Setup GPIO Input Button"""
|
|
43
43
|
self._pin = pin
|
|
@@ -16,6 +16,7 @@ from .const import (
|
|
|
16
16
|
HOMEASSISTANT,
|
|
17
17
|
ID,
|
|
18
18
|
INIT_SLEEP,
|
|
19
|
+
INPUT,
|
|
19
20
|
KIND,
|
|
20
21
|
MCP,
|
|
21
22
|
MCP_ID,
|
|
@@ -28,7 +29,13 @@ from .const import (
|
|
|
28
29
|
STATE,
|
|
29
30
|
ClickTypes,
|
|
30
31
|
)
|
|
31
|
-
from .helper
|
|
32
|
+
from .helper import (
|
|
33
|
+
HostData,
|
|
34
|
+
ha_relay_availibilty_message,
|
|
35
|
+
ha_sensor_availibilty_message,
|
|
36
|
+
ha_sensor_temp_availibilty_message,
|
|
37
|
+
host_stats,
|
|
38
|
+
)
|
|
32
39
|
from .input import GpioInputButton
|
|
33
40
|
from .oled import Oled
|
|
34
41
|
from .relay import GpioRelay, MCPRelay
|
|
@@ -36,27 +43,6 @@ from .relay import GpioRelay, MCPRelay
|
|
|
36
43
|
_LOGGER = logging.getLogger(__name__)
|
|
37
44
|
|
|
38
45
|
|
|
39
|
-
def ha_availibilty_message(topic, relay_id):
|
|
40
|
-
"""Create availability topic for HA."""
|
|
41
|
-
return {
|
|
42
|
-
"availability": [{"topic": f"{topic}/{STATE}"}],
|
|
43
|
-
"command_topic": f"{topic}/relay/{relay_id}/set",
|
|
44
|
-
"device": {
|
|
45
|
-
"identifiers": [topic],
|
|
46
|
-
"manufacturer": "BoneIO",
|
|
47
|
-
"model": "BoneIO Relay Board",
|
|
48
|
-
"name": f"BoneIO {topic}",
|
|
49
|
-
"sw_version": "0.0.1",
|
|
50
|
-
},
|
|
51
|
-
"name": f"Relay {relay_id}",
|
|
52
|
-
"payload_off": OFF,
|
|
53
|
-
"payload_on": ON,
|
|
54
|
-
"state_topic": f"{topic}/{RELAY}/{relay_id}",
|
|
55
|
-
"unique_id": f"{topic}{RELAY}{relay_id}",
|
|
56
|
-
"value_template": "{{ value_json.state }}",
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
46
|
class Manager:
|
|
61
47
|
"""Manager to communicate MQTT with GPIO inputs and outputs."""
|
|
62
48
|
|
|
@@ -66,15 +52,15 @@ class Manager:
|
|
|
66
52
|
topic_prefix: str,
|
|
67
53
|
relay_pins: List,
|
|
68
54
|
input_pins: List,
|
|
55
|
+
lm75: dict = None,
|
|
69
56
|
ha_discovery: bool = True,
|
|
70
57
|
ha_discovery_prefix: str = HOMEASSISTANT,
|
|
71
58
|
mcp23017: Optional[List] = None,
|
|
72
59
|
oled: bool = False,
|
|
73
|
-
web: bool = True,
|
|
74
60
|
) -> None:
|
|
75
61
|
"""Initialize the manager."""
|
|
76
62
|
_LOGGER.info("Initializing manager module.")
|
|
77
|
-
|
|
63
|
+
self._loop = asyncio.get_event_loop()
|
|
78
64
|
self._host_data = None
|
|
79
65
|
|
|
80
66
|
self.send_message = send_message
|
|
@@ -86,8 +72,33 @@ class Manager:
|
|
|
86
72
|
self._grouped_outputs = {}
|
|
87
73
|
self._oled = None
|
|
88
74
|
self._tasks: List[asyncio.Task] = []
|
|
75
|
+
self._lm75 = None
|
|
76
|
+
|
|
77
|
+
def create_lm75_sensor():
|
|
78
|
+
"""Create LM sensor in manager."""
|
|
79
|
+
from .sensor.lm75 import LM75
|
|
80
|
+
|
|
81
|
+
name = lm75.get(ID)
|
|
82
|
+
id = name.replace(" ", "")
|
|
83
|
+
self._lm75 = LM75(
|
|
84
|
+
id=id,
|
|
85
|
+
name=name,
|
|
86
|
+
i2c=self._i2cbusio,
|
|
87
|
+
address=lm75[ADDRESS],
|
|
88
|
+
send_message=self.send_message,
|
|
89
|
+
topic_prefix=topic_prefix,
|
|
90
|
+
)
|
|
91
|
+
self.send_ha_autodiscovery(
|
|
92
|
+
id=id,
|
|
93
|
+
name=name,
|
|
94
|
+
ha_type="sensor",
|
|
95
|
+
prefix=ha_discovery_prefix,
|
|
96
|
+
availibilty_msg_func=ha_sensor_temp_availibilty_message,
|
|
97
|
+
)
|
|
98
|
+
self._tasks.append(asyncio.create_task(self._lm75.send_state()))
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
def create_mcp23017():
|
|
101
|
+
"""Create MCP23017."""
|
|
91
102
|
for mcp in mcp23017:
|
|
92
103
|
id = mcp[ID] or mcp[ADDRESS]
|
|
93
104
|
self._mcp[id] = MCP23017(i2c=self._i2cbusio, address=mcp[ADDRESS])
|
|
@@ -98,18 +109,24 @@ class Manager:
|
|
|
98
109
|
time.sleep(sleep_time)
|
|
99
110
|
self._grouped_outputs[id] = {}
|
|
100
111
|
|
|
112
|
+
if lm75:
|
|
113
|
+
create_lm75_sensor()
|
|
114
|
+
|
|
115
|
+
if mcp23017:
|
|
116
|
+
create_mcp23017()
|
|
117
|
+
|
|
101
118
|
def configure_relay(gpio: dict) -> Any:
|
|
102
119
|
"""Configure kind of relay. Most common MCP."""
|
|
120
|
+
relay_id = gpio[ID].replace(" ", "")
|
|
103
121
|
if gpio[KIND] == MCP:
|
|
104
122
|
mcp_id = gpio.get(MCP_ID, "")
|
|
105
123
|
mcp = self._mcp.get(mcp_id)
|
|
106
124
|
if not mcp:
|
|
107
125
|
_LOGGER.error("No such MCP configured!")
|
|
108
126
|
return
|
|
109
|
-
relay_id = gpio[ID]
|
|
110
127
|
mcp_relay = MCPRelay(
|
|
111
128
|
pin=int(gpio[PIN]),
|
|
112
|
-
id=
|
|
129
|
+
id=gpio[ID],
|
|
113
130
|
send_message=self.send_message,
|
|
114
131
|
topic_prefix=topic_prefix,
|
|
115
132
|
mcp=mcp,
|
|
@@ -129,40 +146,54 @@ class Manager:
|
|
|
129
146
|
topic_prefix=topic_prefix,
|
|
130
147
|
callback=lambda: self._host_data_callback(GPIO),
|
|
131
148
|
)
|
|
132
|
-
self._grouped_outputs[GPIO][
|
|
149
|
+
self._grouped_outputs[GPIO][relay_id] = gpio_relay
|
|
133
150
|
return gpio_relay
|
|
134
151
|
|
|
135
|
-
self.output = {
|
|
152
|
+
self.output = {
|
|
153
|
+
gpio[ID].replace(" ", ""): configure_relay(gpio) for gpio in relay_pins
|
|
154
|
+
}
|
|
136
155
|
for out in self.output.values():
|
|
137
156
|
if ha_discovery:
|
|
138
|
-
_LOGGER.debug("Sending HA discovery.")
|
|
139
157
|
self.send_ha_autodiscovery(
|
|
140
|
-
|
|
158
|
+
id=out.id,
|
|
159
|
+
name=out.name,
|
|
160
|
+
ha_type=out.ha_type,
|
|
161
|
+
prefix=ha_discovery_prefix,
|
|
162
|
+
availibilty_msg_func=ha_relay_availibilty_message,
|
|
141
163
|
)
|
|
142
|
-
|
|
143
|
-
|
|
164
|
+
self._loop.call_soon_threadsafe(
|
|
165
|
+
self._loop.call_later,
|
|
144
166
|
0.5,
|
|
145
167
|
out.send_state,
|
|
146
168
|
)
|
|
147
169
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
170
|
+
def configure_button(gpio):
|
|
171
|
+
pin = gpio[PIN]
|
|
172
|
+
button = GpioInputButton(
|
|
173
|
+
pin=pin,
|
|
151
174
|
press_callback=lambda x, i: self.press_callback(x, i, gpio[ACTIONS]),
|
|
152
175
|
rest_pin=gpio,
|
|
153
176
|
)
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
self.send_ha_autodiscovery(
|
|
178
|
+
id=pin,
|
|
179
|
+
name=gpio.get(ID, pin),
|
|
180
|
+
ha_type="sensor",
|
|
181
|
+
prefix=ha_discovery_prefix,
|
|
182
|
+
availibilty_msg_func=ha_sensor_availibilty_message,
|
|
183
|
+
)
|
|
184
|
+
return button
|
|
185
|
+
|
|
186
|
+
self.buttons = [configure_button(gpio=gpio) for gpio in self._input_pins]
|
|
156
187
|
|
|
157
|
-
if oled
|
|
188
|
+
if oled:
|
|
158
189
|
self._host_data = HostData(
|
|
159
|
-
output=self._grouped_outputs,
|
|
190
|
+
output=self._grouped_outputs,
|
|
191
|
+
lm75=self._lm75,
|
|
192
|
+
callback=self._host_data_callback,
|
|
160
193
|
)
|
|
161
194
|
for f in host_stats.values():
|
|
162
195
|
self._tasks.append(asyncio.create_task(f(self._host_data)))
|
|
163
196
|
_LOGGER.debug("Gathering host data enabled.")
|
|
164
|
-
|
|
165
|
-
if oled:
|
|
166
197
|
self._oled = Oled(
|
|
167
198
|
host_data=self._host_data, output_groups=list(self._grouped_outputs)
|
|
168
199
|
)
|
|
@@ -180,7 +211,8 @@ class Manager:
|
|
|
180
211
|
def press_callback(self, x: ClickTypes, inpin: str, actions: dict) -> None:
|
|
181
212
|
"""Press callback to use in input gpio.
|
|
182
213
|
If relay input map is provided also toggle action on relay."""
|
|
183
|
-
|
|
214
|
+
topic = f"{self._topic_prefix}/{INPUT}/{inpin}"
|
|
215
|
+
self.send_message(topic=topic, payload=x)
|
|
184
216
|
action = actions.get(x)
|
|
185
217
|
if action:
|
|
186
218
|
if action[ACTION] == OUTPUT:
|
|
@@ -188,13 +220,21 @@ class Manager:
|
|
|
188
220
|
output_gpio = self.output.get(action[PIN])
|
|
189
221
|
if output_gpio:
|
|
190
222
|
output_gpio.toggle()
|
|
223
|
+
# This is similar how Z2M is clearing click sensor.
|
|
224
|
+
# self._loop.call_later(1, self.send_message, topic, "")
|
|
191
225
|
|
|
192
226
|
def send_ha_autodiscovery(
|
|
193
|
-
self,
|
|
227
|
+
self,
|
|
228
|
+
id: str,
|
|
229
|
+
name: str,
|
|
230
|
+
prefix: str,
|
|
231
|
+
availibilty_msg_func: Callable,
|
|
232
|
+
ha_type: str = "switch",
|
|
194
233
|
) -> None:
|
|
195
234
|
"""Send HA autodiscovery information for each relay."""
|
|
196
|
-
msg =
|
|
197
|
-
topic = f"{prefix}/{ha_type}/{self._topic_prefix}/{
|
|
235
|
+
msg = availibilty_msg_func(topic=self._topic_prefix, id=id, name=name)
|
|
236
|
+
topic = f"{prefix}/{ha_type}/{self._topic_prefix}/{id}/config"
|
|
237
|
+
_LOGGER.debug("Sending HA discovery for %s, %s.", ha_type, name)
|
|
198
238
|
self.send_message(topic=topic, payload=msg)
|
|
199
239
|
|
|
200
240
|
def receive_message(self, topic: str, message: str) -> None:
|
|
@@ -22,7 +22,7 @@ danube = make_font("danube__.ttf", 15, local=True)
|
|
|
22
22
|
screen_order = [UPTIME, NETWORK, CPU, DISK, MEMORY, SWAP]
|
|
23
23
|
|
|
24
24
|
STANDARD_ROWS = [17, 32, 47]
|
|
25
|
-
UPTIME_ROWS = list(range(25,
|
|
25
|
+
UPTIME_ROWS = list(range(25, 50, 10))
|
|
26
26
|
OUTPUT_ROWS = list(range(14, 60, 6))
|
|
27
27
|
OUTPUT_COLS = range(0, 101, 50)
|
|
28
28
|
|
|
@@ -21,7 +21,8 @@ class BasicRelay:
|
|
|
21
21
|
ha_type=SWITCH,
|
|
22
22
|
) -> None:
|
|
23
23
|
"""Initialize Basic relay."""
|
|
24
|
-
self._id = id
|
|
24
|
+
self._id = id.replace(" ", "")
|
|
25
|
+
self._name = id
|
|
25
26
|
self._ha_type = ha_type
|
|
26
27
|
self._send_message = send_message
|
|
27
28
|
self._relay_topic = f"{topic_prefix}/{RELAY}/"
|
|
@@ -37,9 +38,15 @@ class BasicRelay:
|
|
|
37
38
|
|
|
38
39
|
@property
|
|
39
40
|
def id(self) -> bool:
|
|
40
|
-
"""Id of the relay.
|
|
41
|
+
"""Id of the relay.
|
|
42
|
+
Has to be trimmed out of spaces because of MQTT handling in HA."""
|
|
41
43
|
return self._id or self._pin
|
|
42
44
|
|
|
45
|
+
@property
|
|
46
|
+
def name(self) -> bool:
|
|
47
|
+
"""Not trimmed id."""
|
|
48
|
+
return self._name or self._pin
|
|
49
|
+
|
|
43
50
|
@property
|
|
44
51
|
def state(self) -> bool:
|
|
45
52
|
"""Is relay active."""
|
|
@@ -52,6 +52,22 @@ oled:
|
|
|
52
52
|
type: boolean
|
|
53
53
|
coerce: to_bool
|
|
54
54
|
|
|
55
|
+
lm75:
|
|
56
|
+
type: dict
|
|
57
|
+
required: False
|
|
58
|
+
schema:
|
|
59
|
+
id:
|
|
60
|
+
type: string
|
|
61
|
+
required: False
|
|
62
|
+
meta:
|
|
63
|
+
label: Id of I2C to use in pin config
|
|
64
|
+
address:
|
|
65
|
+
type: string
|
|
66
|
+
required: True
|
|
67
|
+
default: 0x48
|
|
68
|
+
meta:
|
|
69
|
+
label: GPIO of I2C SDA
|
|
70
|
+
|
|
55
71
|
mcp23017:
|
|
56
72
|
type: list
|
|
57
73
|
required: False
|
|
@@ -62,7 +78,8 @@ mcp23017:
|
|
|
62
78
|
schema:
|
|
63
79
|
id:
|
|
64
80
|
type: string
|
|
65
|
-
required:
|
|
81
|
+
required: True
|
|
82
|
+
default: lm75
|
|
66
83
|
meta:
|
|
67
84
|
label: Id of I2C to use in pin config
|
|
68
85
|
address:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev11
|
|
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.dev11.zip
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.7
|
|
@@ -4,8 +4,6 @@ requirements.txt
|
|
|
4
4
|
setup.py
|
|
5
5
|
boneio/__init__.py
|
|
6
6
|
boneio/bonecli.py
|
|
7
|
-
boneio/config.example.yaml
|
|
8
|
-
boneio/config.yaml
|
|
9
7
|
boneio/const.py
|
|
10
8
|
boneio/manager.py
|
|
11
9
|
boneio/mqtt_client.py
|
|
@@ -21,6 +19,7 @@ boneio.egg-info/top_level.txt
|
|
|
21
19
|
boneio/fonts/danube__.ttf
|
|
22
20
|
boneio/helper/__init__.py
|
|
23
21
|
boneio/helper/gpio.py
|
|
22
|
+
boneio/helper/ha_discovery.py
|
|
24
23
|
boneio/helper/oled.py
|
|
25
24
|
boneio/helper/stats.py
|
|
26
25
|
boneio/helper/yaml.py
|
|
@@ -3,6 +3,7 @@ Adafruit-Blinka==6.15.0
|
|
|
3
3
|
adafruit-circuitpython-busdevice==5.1.1
|
|
4
4
|
adafruit-circuitpython-framebuf==1.4.8
|
|
5
5
|
adafruit-circuitpython-mcp230xx==2.5.1
|
|
6
|
+
adafruit-circuitpython-pct2075==1.1.11
|
|
6
7
|
Adafruit-PlatformDetect==3.17.2
|
|
7
8
|
Adafruit-PureIO==1.1.9
|
|
8
9
|
asyncio-mqtt==0.10.0
|
|
@@ -32,7 +32,7 @@ setup(
|
|
|
32
32
|
"Adafruit-BBIO==1.2.0",
|
|
33
33
|
"Adafruit-Blinka==6.15.0",
|
|
34
34
|
"adafruit-circuitpython-mcp230xx==2.5.1",
|
|
35
|
-
"Adafruit-PlatformDetect==3.17.2",
|
|
35
|
+
"adafruit-circuitpython-pct2075==1.1.11" "Adafruit-PlatformDetect==3.17.2",
|
|
36
36
|
"Adafruit-PureIO==1.1.9",
|
|
37
37
|
"asyncio-mqtt==0.10.0",
|
|
38
38
|
"Cerberus==1.3.4",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
mqtt:
|
|
2
|
-
host: mqtt.hass
|
|
3
|
-
username: mqtt
|
|
4
|
-
password: pass
|
|
5
|
-
topic_prefix: boneiohome
|
|
6
|
-
ha_discovery:
|
|
7
|
-
enabled: yes
|
|
8
|
-
|
|
9
|
-
i2c:
|
|
10
|
-
id: myb
|
|
11
|
-
sda: P9_18
|
|
12
|
-
scl: P9_17
|
|
13
|
-
|
|
14
|
-
oled:
|
|
15
|
-
|
|
16
|
-
mcp23017:
|
|
17
|
-
- id: mcp1
|
|
18
|
-
address: 0x20
|
|
19
|
-
|
|
20
|
-
gpio_input:
|
|
21
|
-
- id: "one"
|
|
22
|
-
pin: P8_12
|
|
23
|
-
- id: "two"
|
|
24
|
-
pin: P8_7
|
|
25
|
-
actions:
|
|
26
|
-
single:
|
|
27
|
-
action: output
|
|
28
|
-
pin: myoutput
|
|
29
|
-
|
|
30
|
-
output: !include output.yaml
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
##OUTPUT.YAML
|
|
34
|
-
- id: myoutput
|
|
35
|
-
kind: mcp
|
|
36
|
-
mcp_id: mcp1
|
|
37
|
-
pin: 0
|
|
38
|
-
ha_type: light
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
mqtt:
|
|
2
|
-
host: mqtt.hass
|
|
3
|
-
username: mqtt
|
|
4
|
-
password: pass
|
|
5
|
-
# ha_discovery:
|
|
6
|
-
# enabled: True
|
|
7
|
-
|
|
8
|
-
# i2c:
|
|
9
|
-
# - id: myb
|
|
10
|
-
# sda: "P9_18"
|
|
11
|
-
# scl: "P9_17"
|
|
12
|
-
|
|
13
|
-
gpio_input:
|
|
14
|
-
- id: "one"
|
|
15
|
-
pin: "P8_3"
|
|
16
|
-
|
|
17
|
-
output:
|
|
18
|
-
- id: myinput
|
|
19
|
-
kind: gpio
|
|
20
|
-
pin: P9_17
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"""Helper dir for BoneIO."""
|
|
2
|
-
from .gpio import edge_detect, setup_input
|
|
3
|
-
from .oled import make_font
|
|
4
|
-
from .stats import HostData
|
|
5
|
-
from .yaml import CustomValidator, load_yaml_file
|
|
6
|
-
|
|
7
|
-
__all__ = [
|
|
8
|
-
"CustomValidator",
|
|
9
|
-
"load_yaml_file",
|
|
10
|
-
"HostData",
|
|
11
|
-
"setup_input",
|
|
12
|
-
"edge_detect",
|
|
13
|
-
"make_font",
|
|
14
|
-
]
|
|
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
|