boneIO 0.3.0.dev7__tar.gz → 0.3.0.dev9__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.3.0.dev7/boneio.egg-info → boneio-0.3.0.dev9}/PKG-INFO +2 -2
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/const.py +4 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/events.py +10 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/exceptions.py +4 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/loader.py +2 -9
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/manager.py +11 -1
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/modbus.py +7 -2
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/schema/schema.yaml +1 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/modbus/__init__.py +13 -8
- boneio-0.3.0.dev9/boneio/version.py +2 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9/boneio.egg-info}/PKG-INFO +2 -2
- boneio-0.3.0.dev7/boneio/version.py +0 -2
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/LICENSE +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/MANIFEST.in +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/README.md +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/bonecli.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/cover.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/adc.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/config.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/cover.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/input.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/output24x16A.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/example_config/output32x5A.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/fonts/danube__.ttf +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/config.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/ds2482/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/ds2482/ds2482.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/ds2482/onewire.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/gpio.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/ha_discovery.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/logger.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/mqtt.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/oled.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/queue.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/state_manager.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/stats.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/timeperiod.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/util.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/helper/yaml_util.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/input/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/input/gpio.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/mqtt_client.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/oled.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/relay/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/relay/basic.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/relay/gpio.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/relay/mcp.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/runner.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/schema/actions.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/schema/actions_sensor.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/schema/actions_switch.yaml +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/adc.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/gpio.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/modbus/sdm120.json +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/modbus/sdm630.json +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/modbus/sofar.json +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/temp/__init__.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/temp/dallas.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/temp/lm75.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio/sensor/temp/mcp9808.py +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio.egg-info/SOURCES.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio.egg-info/dependency_links.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio.egg-info/entry_points.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio.egg-info/requires.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/boneio.egg-info/top_level.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/requirements.txt +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/setup.cfg +0 -0
- {boneio-0.3.0.dev7 → boneio-0.3.0.dev9}/setup.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev9
|
|
4
4
|
Summary: Python App for BoneIO
|
|
5
5
|
Home-page: https://github.com/boneIO-eu/app_bbb
|
|
6
|
-
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.3.0.
|
|
6
|
+
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.3.0.dev9.zip
|
|
7
7
|
License: GNU General Public License v3.0
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
@@ -48,9 +48,13 @@ RESTORE_STATE = "restore_state"
|
|
|
48
48
|
MODEL = "model"
|
|
49
49
|
UARTS = {
|
|
50
50
|
"uart1": {ID: "/dev/ttyS1", TX: "P9.24", RX: "P9.26"},
|
|
51
|
+
"uart2": {ID: "/dev/ttyS2", TX: "P9.21", RX: "P9.22"},
|
|
52
|
+
"uart3": {ID: "/dev/ttyS3", TX: "P9.42", RX: None},
|
|
51
53
|
"uart4": {ID: "/dev/ttyS4", TX: "P9.13", RX: "P9.11"},
|
|
54
|
+
"uart5": {ID: "/dev/ttyS5", TX: "P8.37", RX: "P8.38"},
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
|
|
54
58
|
# HA CONSTS
|
|
55
59
|
HOMEASSISTANT = "homeassistant"
|
|
56
60
|
HA_DISCOVERY = "ha_discovery"
|
|
@@ -79,6 +79,7 @@ class EventBus:
|
|
|
79
79
|
self._loop = loop or asyncio.get_event_loop()
|
|
80
80
|
self._listeners = {}
|
|
81
81
|
self._sigterm_listeners = []
|
|
82
|
+
self._haonline_listeners = []
|
|
82
83
|
self._timer_handle = _async_create_timer(self._loop, self._run_second_event)
|
|
83
84
|
for signame in {"SIGINT", "SIGTERM"}:
|
|
84
85
|
self._loop.add_signal_handler(
|
|
@@ -113,6 +114,15 @@ class EventBus:
|
|
|
113
114
|
"""Add sigterm listener."""
|
|
114
115
|
self._sigterm_listeners.append(target)
|
|
115
116
|
|
|
117
|
+
def add_haonline_listener(self, target):
|
|
118
|
+
"""Add HA Online listener."""
|
|
119
|
+
self._haonline_listeners.append(target)
|
|
120
|
+
|
|
121
|
+
def signal_ha_online(self):
|
|
122
|
+
"""Call events if HA goes online."""
|
|
123
|
+
for target in self._haonline_listeners:
|
|
124
|
+
target()
|
|
125
|
+
|
|
116
126
|
def remove_listener(self, name):
|
|
117
127
|
"""Remove regular listener."""
|
|
118
128
|
if name in self._listeners:
|
|
@@ -127,7 +127,6 @@ def create_temp_sensor(
|
|
|
127
127
|
ha_type=SENSOR,
|
|
128
128
|
availability_msg_func=ha_sensor_temp_availabilty_message,
|
|
129
129
|
)
|
|
130
|
-
manager.append_task(asyncio.create_task(temp_sensor.send_state()))
|
|
131
130
|
return temp_sensor
|
|
132
131
|
except I2CError as err:
|
|
133
132
|
_LOGGER.error("Can't configure Temp sensor. %s", err)
|
|
@@ -157,12 +156,7 @@ def create_mcp23017(
|
|
|
157
156
|
return grouped_outputs
|
|
158
157
|
|
|
159
158
|
|
|
160
|
-
def create_modbus_sensors(
|
|
161
|
-
manager: Manager,
|
|
162
|
-
config_helper: ConfigHelper,
|
|
163
|
-
modbus: Modbus,
|
|
164
|
-
sensors,
|
|
165
|
-
) -> None:
|
|
159
|
+
def create_modbus_sensors(manager: Manager, sensors, **kwargs) -> None:
|
|
166
160
|
"""Create Modbus sensor for each device."""
|
|
167
161
|
from boneio.sensor.modbus import ModbusSensor
|
|
168
162
|
|
|
@@ -171,14 +165,13 @@ def create_modbus_sensors(
|
|
|
171
165
|
id = name.replace(" ", "")
|
|
172
166
|
try:
|
|
173
167
|
sdm = ModbusSensor(
|
|
174
|
-
modbus=modbus,
|
|
175
168
|
address=sensor[ADDRESS],
|
|
176
169
|
id=id,
|
|
177
170
|
name=name,
|
|
178
171
|
model=sensor[MODEL],
|
|
179
172
|
send_message=manager.send_message,
|
|
180
|
-
config_helper=config_helper,
|
|
181
173
|
update_interval=sensor.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
|
|
174
|
+
**kwargs,
|
|
182
175
|
)
|
|
183
176
|
manager.append_task(asyncio.create_task(sdm.send_state()))
|
|
184
177
|
except FileNotFoundError as err:
|
|
@@ -46,6 +46,7 @@ from boneio.helper import (
|
|
|
46
46
|
|
|
47
47
|
from boneio.helper.config import ConfigHelper
|
|
48
48
|
from boneio.helper.events import EventBus
|
|
49
|
+
from boneio.helper.exceptions import ModbusUartException
|
|
49
50
|
from boneio.helper.loader import (
|
|
50
51
|
configure_cover,
|
|
51
52
|
configure_input,
|
|
@@ -107,7 +108,14 @@ class Manager:
|
|
|
107
108
|
self._temp_sensors = []
|
|
108
109
|
self._modbus = None
|
|
109
110
|
if modbus and modbus.get(UART) in UARTS:
|
|
110
|
-
|
|
111
|
+
try:
|
|
112
|
+
self._modbus = Modbus(UARTS[modbus.get(UART)])
|
|
113
|
+
except ModbusUartException:
|
|
114
|
+
_LOGGER.error(
|
|
115
|
+
"This UART %s can't be used for modbus communication.",
|
|
116
|
+
modbus.get(UART),
|
|
117
|
+
)
|
|
118
|
+
self._modbus = None
|
|
111
119
|
|
|
112
120
|
for sensor_type in (LM75, MCP_TEMP_9808):
|
|
113
121
|
if sensors.get(sensor_type):
|
|
@@ -127,6 +135,7 @@ class Manager:
|
|
|
127
135
|
|
|
128
136
|
create_modbus_sensors(
|
|
129
137
|
manager=self,
|
|
138
|
+
event_bus=self._event_bus,
|
|
130
139
|
sensors=sensors.get(MODBUS),
|
|
131
140
|
modbus=self._modbus,
|
|
132
141
|
config_helper=self._config_helper,
|
|
@@ -390,6 +399,7 @@ class Manager:
|
|
|
390
399
|
if topic.startswith(f"{self._config_helper.ha_discovery_prefix}/status"):
|
|
391
400
|
if message == ONLINE:
|
|
392
401
|
self.resend_autodiscovery()
|
|
402
|
+
self._event_bus.signal_ha_online()
|
|
393
403
|
return
|
|
394
404
|
assert topic.startswith(self._config_helper.cmd_topic_prefix)
|
|
395
405
|
topic_parts_raw = topic[len(self._config_helper.cmd_topic_prefix) :].split("/")
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
5
|
from boneio.helper import configure_pin
|
|
6
|
+
from boneio.helper.exceptions import ModbusUartException
|
|
6
7
|
from boneio.const import ID, RX, TX, UART, REGISTERS
|
|
7
8
|
from pymodbus.client.sync import (
|
|
8
9
|
BaseModbusClient,
|
|
@@ -23,9 +24,13 @@ class Modbus:
|
|
|
23
24
|
|
|
24
25
|
def __init__(self, uart: dict[str, Any]) -> None:
|
|
25
26
|
"""Initialize the Modbus hub."""
|
|
27
|
+
rx = uart.get(RX)
|
|
28
|
+
tx = uart.get(TX)
|
|
29
|
+
if not tx or not rx:
|
|
30
|
+
raise ModbusUartException
|
|
26
31
|
|
|
27
|
-
configure_pin(pin=
|
|
28
|
-
configure_pin(pin=
|
|
32
|
+
configure_pin(pin=rx, mode=UART)
|
|
33
|
+
configure_pin(pin=tx, mode=UART)
|
|
29
34
|
self._uart = uart
|
|
30
35
|
|
|
31
36
|
# generic configuration
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from distutils.command.config import config
|
|
2
1
|
import logging
|
|
3
2
|
import asyncio
|
|
4
3
|
from datetime import datetime
|
|
@@ -23,7 +22,7 @@ from boneio.helper.ha_discovery import modbus_sensor_availabilty_message
|
|
|
23
22
|
from boneio.helper.timeperiod import TimePeriod
|
|
24
23
|
from boneio.helper.config import ConfigHelper
|
|
25
24
|
from boneio.modbus import Modbus
|
|
26
|
-
|
|
25
|
+
from boneio.helper.events import EventBus
|
|
27
26
|
|
|
28
27
|
_LOGGER = logging.getLogger(__name__)
|
|
29
28
|
|
|
@@ -98,6 +97,7 @@ class ModbusSensor(BasicMqtt):
|
|
|
98
97
|
address: str,
|
|
99
98
|
model: str,
|
|
100
99
|
config_helper: ConfigHelper,
|
|
100
|
+
event_bus: EventBus,
|
|
101
101
|
id: str = DefaultName,
|
|
102
102
|
update_interval: TimePeriod = TimePeriod(seconds=60),
|
|
103
103
|
**kwargs,
|
|
@@ -116,6 +116,11 @@ class ModbusSensor(BasicMqtt):
|
|
|
116
116
|
self._address = address
|
|
117
117
|
self._discovery_sent = False
|
|
118
118
|
self._update_interval = update_interval
|
|
119
|
+
self._payload_online = OFFLINE
|
|
120
|
+
event_bus.add_haonline_listener(target=self.set_payload_offline)
|
|
121
|
+
|
|
122
|
+
def set_payload_offline(self):
|
|
123
|
+
self._payload_online = OFFLINE
|
|
119
124
|
|
|
120
125
|
def _send_ha_autodiscovery(
|
|
121
126
|
self, id: str, sdm_name: str, sensor_id: str, **kwargs
|
|
@@ -190,7 +195,7 @@ class ModbusSensor(BasicMqtt):
|
|
|
190
195
|
async def send_state(self) -> None:
|
|
191
196
|
"""Fetch state periodically and send to MQTT."""
|
|
192
197
|
update_interval = self._update_interval.total_seconds
|
|
193
|
-
|
|
198
|
+
self.set_payload_offline()
|
|
194
199
|
while True:
|
|
195
200
|
await self.check_availability()
|
|
196
201
|
for data in self._db[REGISTERS_BASE]:
|
|
@@ -200,12 +205,12 @@ class ModbusSensor(BasicMqtt):
|
|
|
200
205
|
count=data[LENGTH],
|
|
201
206
|
method=data.get("register_type", "input"),
|
|
202
207
|
)
|
|
203
|
-
if
|
|
208
|
+
if self._payload_online == OFFLINE and values:
|
|
204
209
|
_LOGGER.info("Sending online payload about device.")
|
|
205
|
-
|
|
210
|
+
self._payload_online = ONLINE
|
|
206
211
|
self._send_message(
|
|
207
212
|
topic=f"{self._config_helper.topic_prefix}/{self._id}{STATE}",
|
|
208
|
-
payload=
|
|
213
|
+
payload=self._payload_online,
|
|
209
214
|
)
|
|
210
215
|
if not values:
|
|
211
216
|
if update_interval < 600:
|
|
@@ -213,10 +218,10 @@ class ModbusSensor(BasicMqtt):
|
|
|
213
218
|
update_interval = update_interval * 1.5
|
|
214
219
|
else:
|
|
215
220
|
# Let's assume device is offline.
|
|
216
|
-
|
|
221
|
+
self.set_payload_offline()
|
|
217
222
|
self._send_message(
|
|
218
223
|
topic=f"{self._config_helper.topic_prefix}/{self._id}{STATE}",
|
|
219
|
-
payload=
|
|
224
|
+
payload=self._payload_online,
|
|
220
225
|
)
|
|
221
226
|
_LOGGER.warn(
|
|
222
227
|
"Can't fetch data from modbus device. Will sleep for %s seconds",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: boneio
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev9
|
|
4
4
|
Summary: Python App for BoneIO
|
|
5
5
|
Home-page: https://github.com/boneIO-eu/app_bbb
|
|
6
|
-
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.3.0.
|
|
6
|
+
Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.3.0.dev9.zip
|
|
7
7
|
License: GNU General Public License v3.0
|
|
8
8
|
Platform: UNKNOWN
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
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
|
|
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
|
|
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
|