boneIO 0.5.0__tar.gz → 0.5.0dev2__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.

Files changed (75) hide show
  1. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/PKG-INFO +1 -1
  2. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/bonecli.py +0 -3
  3. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/filter.py +1 -5
  4. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/gpio.py +3 -2
  5. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/ha_discovery.py +3 -5
  6. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/loader.py +0 -3
  7. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/stats.py +3 -19
  8. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/yaml_util.py +1 -2
  9. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/manager.py +9 -28
  10. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/modbus.py +1 -1
  11. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/oled.py +6 -19
  12. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/schema.yaml +39 -61
  13. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/gpio.py +10 -10
  14. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/modbus/__init__.py +27 -31
  15. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/temp/__init__.py +1 -6
  16. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/temp/dallas.py +2 -1
  17. boneIO-0.5.0.dev2/boneio/version.py +2 -0
  18. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/pyproject.toml +1 -1
  19. boneIO-0.5.0/boneio/schema/id.yaml +0 -4
  20. boneIO-0.5.0/boneio/schema/temp_unit.yaml +0 -4
  21. boneIO-0.5.0/boneio/sensor/modbus/pt100.json +0 -21
  22. boneIO-0.5.0/boneio/version.py +0 -2
  23. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/LICENSE +0 -0
  24. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/README.md +0 -0
  25. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/__init__.py +0 -0
  26. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/const.py +0 -0
  27. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/cover.py +0 -0
  28. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/__init__.py +0 -0
  29. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/adc.yaml +0 -0
  30. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/config.yaml +0 -0
  31. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/cover.yaml +0 -0
  32. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/input.yaml +0 -0
  33. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/output24x16A.yaml +0 -0
  34. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/example_config/output32x5A.yaml +0 -0
  35. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/fonts/danube__.ttf +0 -0
  36. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/__init__.py +0 -0
  37. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/async_updater.py +0 -0
  38. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/config.py +0 -0
  39. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/events.py +0 -0
  40. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/exceptions.py +0 -0
  41. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/logger.py +0 -0
  42. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/mqtt.py +0 -0
  43. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/oled.py +0 -0
  44. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/onewire/W1ThermSensor.py +0 -0
  45. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/onewire/__init__.py +0 -0
  46. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/onewire/ds2482.py +0 -0
  47. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/onewire/onewire.py +0 -0
  48. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/queue.py +0 -0
  49. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/state_manager.py +0 -0
  50. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/timeperiod.py +0 -0
  51. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/helper/util.py +0 -0
  52. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/input/__init__.py +0 -0
  53. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/input/gpio.py +0 -0
  54. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/mqtt_client.py +0 -0
  55. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/relay/__init__.py +0 -0
  56. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/relay/basic.py +0 -0
  57. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/relay/gpio.py +0 -0
  58. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/relay/mcp.py +0 -0
  59. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/runner.py +0 -0
  60. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/actions.yaml +0 -0
  61. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/actions_sensor.yaml +0 -0
  62. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/actions_switch.yaml +0 -0
  63. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/filters.yaml +0 -0
  64. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/filters_adc.yaml +0 -0
  65. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/schema/update_interval.yaml +0 -0
  66. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/__init__.py +0 -0
  67. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/adc.py +0 -0
  68. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/modbus/sdm120.json +0 -0
  69. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/modbus/sdm630.json +0 -0
  70. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/modbus/sofar.json +0 -0
  71. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/temp/lm75.py +0 -0
  72. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/boneio/sensor/temp/mcp9808.py +0 -0
  73. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/tests/32_5_config.yaml +0 -0
  74. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/tests/bandit.yaml +0 -0
  75. {boneIO-0.5.0 → boneIO-0.5.0.dev2}/tests/relay_32_5.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneIO
3
- Version: 0.5.0
3
+ Version: 0.5.0dev2
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>
@@ -3,9 +3,6 @@ import argparse
3
3
  import asyncio
4
4
  import logging
5
5
  import sys
6
- import os
7
-
8
- os.environ["W1THERMSENSOR_NO_KERNEL_MODULE"] = "1"
9
6
 
10
7
  from colorlog import ColoredFormatter
11
8
  from yaml import MarkedYAMLError
@@ -1,8 +1,5 @@
1
1
  """Filter class to adjust sensor values."""
2
2
  from __future__ import annotations
3
- import logging
4
-
5
- _LOGGER = logging.getLogger(__name__)
6
3
 
7
4
 
8
5
  FILTERS = {
@@ -22,8 +19,7 @@ class Filter:
22
19
  for filter in self._filters:
23
20
  for k, v in filter.items():
24
21
  if k not in FILTERS:
25
- _LOGGER.warn("Filter %s doesn't exists. Fix it in config.", k)
26
- continue
22
+ break
27
23
  value = FILTERS[k](value, v)
28
24
  if value is None:
29
25
  return None
@@ -90,8 +90,9 @@ class GpioBaseClass:
90
90
  ) -> None:
91
91
  """Setup GPIO Input Button"""
92
92
  self._pin = pin
93
- gpio_mode = kwargs.get(GPIO_MODE, GPIO_STR)
94
- self._bounce_time = kwargs.get("bounce_time", TimePeriod(milliseconds=10))
93
+ gpio = kwargs.get("rest_pin", {GPIO_MODE: GPIO_STR})
94
+ gpio_mode = gpio.get(GPIO_MODE, GPIO_STR)
95
+ self._bounce_time = gpio.get("bounce_time", TimePeriod(milliseconds=10))
95
96
  self._loop = asyncio.get_running_loop()
96
97
  self._press_callback = press_callback
97
98
  setup_input(pin=self._pin, pull_mode=gpio_mode)
@@ -109,9 +109,7 @@ def ha_binary_sensor_availabilty_message(id: str, name: str, topic: str = "boneI
109
109
  }
110
110
 
111
111
 
112
- def ha_sensor_temp_availabilty_message(
113
- id: str, name: str, topic: str = "boneIO", **kwargs
114
- ):
112
+ def ha_sensor_temp_availabilty_message(id: str, name: str, topic: str = "boneIO"):
115
113
  """Create availability topic for HA."""
116
114
  return {
117
115
  "availability": [{"topic": f"{topic}/{STATE}"}],
@@ -127,8 +125,8 @@ def ha_sensor_temp_availabilty_message(
127
125
  "unique_id": f"{topic}{SENSOR}{id}",
128
126
  "device_class": "temperature",
129
127
  "state_class": "measurement",
128
+ "unit_of_measurement": "°C",
130
129
  "value_template": "{{ value_json.state }}",
131
- **kwargs,
132
130
  }
133
131
 
134
132
 
@@ -154,7 +152,7 @@ def modbus_sensor_availabilty_message(
154
152
  },
155
153
  "name": sensor_id,
156
154
  "state_topic": f"{topic}/{device_type}/{id}/{state_topic_base}",
157
- "unique_id": f"{topic}{sensor_id.replace('_', '').lower()}{name.lower()}",
155
+ "unique_id": f"{topic}{sensor_id.replace('_', '').lower()}",
158
156
  **kwargs,
159
157
  }
160
158
 
@@ -125,7 +125,6 @@ def create_temp_sensor(
125
125
  name=name,
126
126
  i2c=i2cbusio,
127
127
  address=config[ADDRESS],
128
- manager=manager,
129
128
  send_message=manager.send_message,
130
129
  topic_prefix=topic_prefix,
131
130
  update_interval=config.get(UPDATE_INTERVAL, TimePeriod(seconds=60)),
@@ -136,7 +135,6 @@ def create_temp_sensor(
136
135
  name=name,
137
136
  ha_type=SENSOR,
138
137
  availability_msg_func=ha_sensor_temp_availabilty_message,
139
- unit_of_measurement=config.get("unit_of_measurement", "°C"),
140
138
  )
141
139
  return temp_sensor
142
140
  except I2CError as err:
@@ -406,6 +404,5 @@ def create_dallas_sensor(
406
404
  name=sensor.name,
407
405
  ha_type=SENSOR,
408
406
  availability_msg_func=ha_sensor_temp_availabilty_message,
409
- unit_of_measurement=config.get("unit_of_measurement", "°C"),
410
407
  )
411
408
  return sensor
@@ -4,8 +4,7 @@ from datetime import datetime
4
4
  import socket
5
5
  import time
6
6
  from math import floor
7
- from typing import Callable, List
8
- from functools import partial
7
+ from typing import Callable
9
8
 
10
9
  import psutil
11
10
 
@@ -119,31 +118,21 @@ class HostSensor(AsyncUpdater):
119
118
  """Host sensor."""
120
119
 
121
120
  def __init__(
122
- self,
123
- update_function: Callable,
124
- manager_callback: Callable,
125
- static_data: dict,
126
- id: str,
127
- type: str,
128
- **kwargs,
121
+ self, update_function: Callable, static_data: dict, id: str, **kwargs
129
122
  ) -> None:
130
123
  self._update_function = update_function
131
124
  self._static_data = static_data
132
125
  self._state = None
133
- self._type = type
134
- self._manager_callback = manager_callback
135
- self._loop = asyncio.get_event_loop()
136
126
  self.id = id
137
127
  super().__init__(**kwargs)
138
128
 
139
129
  async def async_update(self, time: datetime) -> None:
140
130
  self._state = self._update_function()
141
- self._loop.call_soon_threadsafe(partial(self._manager_callback, self._type))
142
131
 
143
132
  @property
144
133
  def state(self) -> dict:
145
134
  if self._static_data:
146
- return {**self._static_data, self._type: self._state}
135
+ return {**self._static_data, **self._state}
147
136
  return self._state
148
137
 
149
138
 
@@ -158,7 +147,6 @@ class HostData:
158
147
  callback: Callable,
159
148
  temp_sensor: Callable[[LM75Sensor, MCP9808Sensor], None],
160
149
  manager: Manager,
161
- enabled_screens: List[str],
162
150
  ) -> None:
163
151
  """Initialize HostData."""
164
152
  self._hostname = socket.gethostname()
@@ -175,15 +163,11 @@ class HostData:
175
163
  },
176
164
  }
177
165
  for k, _v in host_stats.items():
178
- if k not in enabled_screens:
179
- continue
180
166
  self.data[k] = HostSensor(
181
167
  update_function=_v["f"],
182
168
  static_data=_v.get("static"),
183
169
  manager=manager,
184
- manager_callback=callback,
185
170
  id=f"{k}_hoststats",
186
- type=k,
187
171
  update_interval=_v["update_interval"],
188
172
  )
189
173
  self._temp_sensor = temp_sensor
@@ -135,8 +135,6 @@ def load_config_from_string(config_yaml: str):
135
135
  schema = load_yaml_file(schema_file)
136
136
  v = CustomValidator(schema, purge_unknown=True)
137
137
  v.validate(config_yaml)
138
- if v.errors:
139
- _LOGGER.error("There are errors in your config %s", v.errors)
140
138
  doc = v.normalized(v.document, always_return_document=True)
141
139
  # validated = v.validated(document=doc, normalize=True, always_return_document=True)
142
140
  # doc = v.normalized(validated, always_return_document=True)
@@ -255,6 +253,7 @@ class CustomValidator(Validator):
255
253
 
256
254
  def _normalize_coerce_positive_time_period(self, value) -> TimePeriod:
257
255
  """Validate and transform time period with time unit and integer value."""
256
+
258
257
  if isinstance(value, int):
259
258
  raise ConfigurationException(
260
259
  f"Don't know what '{value}' means as it has no time *unit*! Did you mean '{value}s'?"
@@ -2,6 +2,7 @@ import asyncio
2
2
  import logging
3
3
  from collections import deque
4
4
  from typing import Callable, Coroutine, List, Optional, Set, Union
5
+
5
6
  from board import SCL, SDA
6
7
  from busio import I2C
7
8
 
@@ -59,8 +60,6 @@ from boneio.helper.logger import configure_logger
59
60
  from boneio.helper.yaml_util import load_config_from_file
60
61
  from boneio.modbus import Modbus
61
62
 
62
- from w1thermsensor.errors import KernelModuleLoadError
63
-
64
63
  _LOGGER = logging.getLogger(__name__)
65
64
 
66
65
 
@@ -205,11 +204,8 @@ class Manager:
205
204
  if oled.get("enabled", False):
206
205
  from boneio.oled import Oled
207
206
 
208
- screens = oled.get("screens")
209
-
210
207
  self._host_data = HostData(
211
208
  manager=self,
212
- enabled_screens=screens,
213
209
  output=self.grouped_outputs,
214
210
  temp_sensor=self._temp_sensors[0] if self._temp_sensors else None,
215
211
  callback=self._host_data_callback,
@@ -217,7 +213,6 @@ class Manager:
217
213
  try:
218
214
  self._oled = Oled(
219
215
  host_data=self._host_data,
220
- screen_order=screens,
221
216
  output_groups=list(self.grouped_outputs),
222
217
  sleep_timeout=oled.get("screensaver_timeout", 60),
223
218
  )
@@ -254,7 +249,6 @@ class Manager:
254
249
  from boneio.helper.loader import (
255
250
  configure_ds2482,
256
251
  )
257
- from boneio.sensor import DallasSensorDS2482
258
252
 
259
253
  _ds_onewire_bus[_single_ds[ID]] = configure_ds2482(
260
254
  i2cbusio=self._i2cbusio, address=_single_ds[ADDRESS]
@@ -270,35 +264,22 @@ class Manager:
270
264
  _LOGGER.debug("Preparing Dallas bus.")
271
265
  from boneio.helper.loader import configure_dallas
272
266
 
273
- try:
274
- from w1thermsensor.kernel import load_kernel_modules
275
-
276
- load_kernel_modules()
277
- from boneio.sensor.temp.dallas_w1 import DallasSensorW1
278
-
279
- _one_wire_devices.update(
280
- find_onewire_devices(
281
- ow_bus=configure_dallas(),
282
- bus_id=dallas[ID],
283
- bus_type=DALLAS,
284
- )
267
+ _one_wire_devices.update(
268
+ find_onewire_devices(
269
+ ow_bus=configure_dallas(),
270
+ bus_id=dallas[ID],
271
+ bus_type=DALLAS,
285
272
  )
286
- except KernelModuleLoadError as err:
287
- _LOGGER.error("Can't configure Dallas W1 device %s", err)
288
- pass
289
-
273
+ )
290
274
  for sensor in sensors:
291
275
  address = _one_wire_devices.get(sensor[ADDRESS])
292
276
  if not address:
293
277
  continue
294
278
  ds2482_bus_id = sensor.get("bus_id")
295
279
  if ds2482_bus_id and ds2482_bus_id in _ds_onewire_bus:
296
- kwargs = {
297
- "bus": _ds_onewire_bus[ds2482_bus_id],
298
- "cls": DallasSensorDS2482,
299
- }
280
+ kwargs = {"bus": _ds_onewire_bus[ds2482_bus_id]}
300
281
  else:
301
- kwargs = {"cls": DallasSensorW1}
282
+ kwargs = {}
302
283
  _LOGGER.debug("Configuring sensor %s for boneIO", address)
303
284
  self._temp_sensors.append(
304
285
  create_dallas_sensor(
@@ -77,7 +77,7 @@ class Modbus:
77
77
  """Call sync. pymodbus."""
78
78
  async with self._lock:
79
79
  if not self._pymodbus_connect():
80
- _LOGGER.error("Can't connect to Modbus address %s.", address)
80
+ _LOGGER.error("Can't connect to Modbus.")
81
81
  return None
82
82
  kwargs = {"unit": unit, "count": count} if unit else {}
83
83
  try:
@@ -28,7 +28,7 @@ fontSmall = make_font("DejaVuSans.ttf", 9)
28
28
  fontExtraSmall = make_font("DejaVuSans.ttf", 7)
29
29
  danube = make_font("danube__.ttf", 15, local=True)
30
30
 
31
- # screen_order = [UPTIME, NETWORK, CPU, DISK, MEMORY, SWAP]
31
+ screen_order = [UPTIME, NETWORK, CPU, DISK, MEMORY, SWAP]
32
32
 
33
33
  STANDARD_ROWS = [17, 32, 47]
34
34
  UPTIME_ROWS = list(range(22, 60, 10))
@@ -40,32 +40,19 @@ class Oled:
40
40
  """Oled display class."""
41
41
 
42
42
  def __init__(
43
- self,
44
- host_data: HostData,
45
- output_groups: List[str],
46
- sleep_timeout: TimePeriod,
47
- screen_order: List[str],
43
+ self, host_data: HostData, output_groups: List[str], sleep_timeout: TimePeriod
48
44
  ) -> None:
49
45
  """Initialize OLED screen."""
50
46
  self._loop = asyncio.get_running_loop()
51
- self._output_groups = None
52
- try:
53
- _ind_screen = screen_order.index("outputs")
54
- if not output_groups:
55
- _LOGGER.debug("No outputs configured. Omitting in screen.")
56
- screen_order.pop(_ind_screen)
57
- screen_order[_ind_screen:_ind_screen] = output_groups
58
- self._output_groups = output_groups
59
- except ValueError:
60
- pass
61
- self._screen_order = cycle(screen_order)
47
+ self._screen_order = cycle(screen_order + output_groups)
48
+ self._output_groups = output_groups
62
49
  self._current_screen = next(self._screen_order)
63
50
  self._host_data = host_data
64
51
  self._sleep = False
65
52
  self._sleep_handle = None
66
53
  self._sleep_timeout = sleep_timeout
67
54
  setup_input(pin=OLED_PIN, pull_mode="gpio_pu")
68
- edge_detect(pin=OLED_PIN, callback=self._handle_press, bounce=240)
55
+ edge_detect(pin=OLED_PIN, callback=self._handle_press, bounce=120)
69
56
  try:
70
57
  serial = i2c(port=2, address=0x3C)
71
58
  self._device = sh1106(serial)
@@ -125,7 +112,7 @@ class Oled:
125
112
  data = self._host_data.get(self._current_screen)
126
113
  if data:
127
114
  with canvas(self._device) as draw:
128
- if self._output_groups and self._current_screen in self._output_groups:
115
+ if self._current_screen in self._output_groups:
129
116
  self._draw_output(data, draw)
130
117
  elif self._current_screen == UPTIME:
131
118
  self._draw_uptime(data, draw)
@@ -75,18 +75,6 @@ oled:
75
75
  default: False
76
76
  meta:
77
77
  label: Disable builtin screen.
78
- screens:
79
- type: list
80
- required: True
81
- allowed: ["uptime", "network", "cpu", "disk", "memory", "swap", "outputs"]
82
- default:
83
- - uptime
84
- - network
85
- - cpu
86
- - disk
87
- - memory
88
- - swap
89
- - outputs
90
78
  screensaver_timeout:
91
79
  type:
92
80
  - string
@@ -123,9 +111,7 @@ modbus_sensors:
123
111
  meta:
124
112
  label: Id of Modbus sensor
125
113
  address:
126
- type:
127
- - string
128
- - integer
114
+ type: string
129
115
  required: True
130
116
  meta:
131
117
  label: Address of Modbus sensor to use.
@@ -147,50 +133,41 @@ modbus_sensors:
147
133
  meta:
148
134
  label: Update interval.
149
135
  lm75:
150
- type: list
136
+ type: dict
151
137
  required: False
152
- meta:
153
- label: LM75 Sensor list.
154
138
  schema:
155
- type: dict
156
- required: False
157
- schema:
158
- id: !include id.yaml
159
- address:
160
- type:
161
- - string
162
- - integer
163
- required: True
164
- default: 0x48
165
- meta:
166
- label: Address of I2C
167
- update_interval: !include update_interval.yaml
168
- filters: !include filters.yaml
169
- unit_of_measurement: !include temp_unit.yaml
139
+ id:
140
+ type: string
141
+ required: False
142
+ meta:
143
+ label: Id of I2C to use in pin config
144
+ address:
145
+ type: string
146
+ required: True
147
+ default: 0x48
148
+ meta:
149
+ label: Address of I2C
150
+ update_interval: !include update_interval.yaml
151
+ filters: !include filters.yaml
170
152
 
171
153
 
172
154
  mcp9808:
173
- type: list
155
+ type: dict
174
156
  required: False
175
- meta:
176
- label: MCP9808 Sensor list.
177
157
  schema:
178
- type: dict
179
- required: False
180
- schema:
181
- id: !include id.yaml
182
- address:
183
- type:
184
- - string
185
- - integer
186
- required: True
187
- default: 0x18
188
- meta:
189
- label: Address of I2C device
190
- update_interval: !include update_interval.yaml
191
- filters: !include filters.yaml
192
- unit_of_measurement: !include temp_unit.yaml
193
-
158
+ id:
159
+ type: string
160
+ required: False
161
+ meta:
162
+ label: Id of I2C to use in pin config
163
+ address:
164
+ type: string
165
+ required: True
166
+ default: 0x18
167
+ meta:
168
+ label: Address of I2C device
169
+ update_interval: !include update_interval.yaml
170
+ filters: !include filters.yaml
194
171
 
195
172
  mcp23017:
196
173
  type: list
@@ -200,7 +177,11 @@ mcp23017:
200
177
  schema:
201
178
  type: dict
202
179
  schema:
203
- id: !include id.yaml
180
+ id:
181
+ type: string
182
+ required: True
183
+ meta:
184
+ label: Id of I2C to use in pin config
204
185
  address:
205
186
  type: integer
206
187
  required: True
@@ -333,12 +314,6 @@ input:
333
314
  required: True
334
315
  meta:
335
316
  label: Either switch or sensor. If sensor then no clicks are detected, just simple on/off on gpio.
336
- inverted:
337
- type: boolean
338
- default: False
339
- required: True
340
- meta:
341
- label: Check if sensor type is inverted. Only aplicable for sensor kind.
342
317
  actions:
343
318
  required: False
344
319
  type: dict
@@ -445,7 +420,11 @@ ds2482:
445
420
  type: dict
446
421
  required: False
447
422
  schema:
448
- id: !include id.yaml
423
+ id:
424
+ type: string
425
+ required: True
426
+ meta:
427
+ label: Id of I2C to use in pin config
449
428
  address:
450
429
  type: string
451
430
  required: True
@@ -501,4 +480,3 @@ sensor:
501
480
  label: If you want you can disable discovering this input in HA.
502
481
  filters: !include filters.yaml
503
482
  update_interval: !include update_interval.yaml
504
- unit_of_measurement: !include temp_unit.yaml
@@ -14,11 +14,6 @@ class GpioInputSensor(GpioBaseClass):
14
14
  def __init__(self, **kwargs) -> None:
15
15
  """Setup GPIO Input Button"""
16
16
  super().__init__(**kwargs)
17
- self._click_type = (
18
- (PRESSED, RELEASED)
19
- if kwargs.get("inverted", False)
20
- else (PRESSED, RELEASED)
21
- )
22
17
  edge_detect(
23
18
  self._pin,
24
19
  callback=self._handle_press,
@@ -30,8 +25,13 @@ class GpioInputSensor(GpioBaseClass):
30
25
  def _handle_press(self, pin: str) -> None:
31
26
  """Handle the button press callback"""
32
27
  # Ignore if we are in a long press
33
- click_type = self._click_type[0] if self.is_pressed else self._click_type[1]
34
- _LOGGER.debug("%s event on pin %s", click_type, self._pin)
35
- self._loop.call_soon_threadsafe(
36
- partial(self._press_callback, click_type, self._pin)
37
- )
28
+ if self.is_pressed:
29
+ _LOGGER.debug("Pressed event on pin %s", self._pin)
30
+ self._loop.call_soon_threadsafe(
31
+ partial(self._press_callback, PRESSED, self._pin)
32
+ )
33
+ else:
34
+ _LOGGER.debug("Released event on pin %s", self._pin)
35
+ self._loop.call_soon_threadsafe(
36
+ partial(self._press_callback, RELEASED, self._pin)
37
+ )
@@ -123,9 +123,7 @@ class ModbusSensor(BasicMqtt, AsyncUpdater):
123
123
  self, id: str, sdm_name: str, sensor_id: str, **kwargs
124
124
  ) -> None:
125
125
  """Send HA autodiscovery information for each Modbus sensor."""
126
- _LOGGER.debug(
127
- "Sending HA discovery for modbus sensor %s %s.", sdm_name, sensor_id
128
- )
126
+ _LOGGER.debug("Sending HA discovery for sensor %s %s.", sdm_name, sensor_id)
129
127
  topic = (
130
128
  f"{self._config_helper.ha_discovery_prefix}/{SENSOR}/{self._config_helper.topic_prefix}{id}"
131
129
  f"/{id}{sensor_id.replace('_', '').replace(' ', '').lower()}/config"
@@ -143,28 +141,30 @@ class ModbusSensor(BasicMqtt, AsyncUpdater):
143
141
 
144
142
  def _send_discovery_for_all_registers(self, register: int = 0) -> bool:
145
143
  """Send discovery message to HA for each register."""
146
- for data in self._db[REGISTERS_BASE]:
147
- for register in data[REGISTERS]:
148
- value_template = (
149
- f'{{{{ value_json.{register.get("name").replace(" ", "")} | '
150
- f'{register.get("ha_filter", "round(2)")} }}}}'
151
- )
152
- kwargs = {
153
- "unit_of_measurement": register.get("unit_of_measurement"),
154
- "state_class": register.get("state_class"),
155
- "value_template": value_template,
156
- "sensor_id": register.get("name"),
157
- }
158
- device_class = register.get("device_class")
159
- if device_class:
160
- kwargs["device_class"] = device_class
161
- self._send_ha_autodiscovery(
162
- id=self._id,
163
- sdm_name=self._name,
164
- state_topic_base=data[BASE],
165
- **kwargs,
166
- )
167
- return datetime.now()
144
+ if register > 0:
145
+ for data in self._db[REGISTERS_BASE]:
146
+ for register in data[REGISTERS]:
147
+ value_template = (
148
+ f'{{{{ value_json.{register.get("name").replace(" ", "")} | '
149
+ f'{register.get("ha_filter", "round(2)")} }}}}'
150
+ )
151
+ kwargs = {
152
+ "unit_of_measurement": register.get("unit_of_measurement"),
153
+ "state_class": register.get("state_class"),
154
+ "value_template": value_template,
155
+ "sensor_id": register.get("name"),
156
+ }
157
+ device_class = register.get("device_class")
158
+ if device_class:
159
+ kwargs["device_class"] = device_class
160
+ self._send_ha_autodiscovery(
161
+ id=self._id,
162
+ sdm_name=self._name,
163
+ state_topic_base=data[BASE],
164
+ **kwargs,
165
+ )
166
+ return datetime.now()
167
+ return False
168
168
 
169
169
  async def check_availability(self) -> None:
170
170
  """Get first register and check if it's available."""
@@ -182,15 +182,12 @@ class ModbusSensor(BasicMqtt, AsyncUpdater):
182
182
  address=first_register_base[REGISTERS][0][ADDRESS],
183
183
  method=register_method,
184
184
  )
185
- if register is not None:
185
+ if register:
186
186
  self._discovery_sent = self._send_discovery_for_all_registers(
187
187
  register
188
188
  )
189
189
  await asyncio.sleep(2)
190
190
  break
191
- _LOGGER.error(
192
- "Discovery for %s not sent. First register not available.", self._id
193
- )
194
191
 
195
192
  async def async_update(self, time: datetime) -> None:
196
193
  """Fetch state periodically and send to MQTT."""
@@ -222,8 +219,7 @@ class ModbusSensor(BasicMqtt, AsyncUpdater):
222
219
  payload=self._payload_online,
223
220
  )
224
221
  _LOGGER.warn(
225
- "Can't fetch data from modbus device %s. Will sleep for %s seconds",
226
- self.id,
222
+ "Can't fetch data from modbus device. Will sleep for %s seconds",
227
223
  update_interval,
228
224
  )
229
225
  self._discovery_sent = False
@@ -1,7 +1,6 @@
1
1
  """Manage BoneIO onboard temp sensors."""
2
2
 
3
3
  import asyncio
4
- import logging
5
4
  from datetime import datetime
6
5
 
7
6
  from boneio.const import SENSOR, STATE, TEMPERATURE
@@ -9,8 +8,6 @@ from boneio.helper import BasicMqtt, AsyncUpdater
9
8
  from boneio.helper.exceptions import I2CError
10
9
  from boneio.helper.filter import Filter
11
10
 
12
- _LOGGER = logging.getLogger(__name__)
13
-
14
11
 
15
12
  class TempSensor(BasicMqtt, AsyncUpdater, Filter):
16
13
  """Represent Temp sensor in BoneIO."""
@@ -44,10 +41,8 @@ class TempSensor(BasicMqtt, AsyncUpdater, Filter):
44
41
 
45
42
  def update(self, time: datetime) -> None:
46
43
  """Fetch temperature periodically and send to MQTT."""
47
- _temp = self._pct.temperature
48
- _LOGGER.debug("Fetched temperature %s. Applying filters.", _temp)
49
44
  _temp = self._apply_filters(value=self._pct.temperature)
50
- if _temp is None:
45
+ if not _temp:
51
46
  return
52
47
  self._state = _temp
53
48
  self._send_message(
@@ -3,6 +3,7 @@
3
3
  import asyncio
4
4
  import logging
5
5
  from datetime import datetime
6
+ from ast import literal_eval
6
7
 
7
8
  from adafruit_ds18x20 import DS18X20
8
9
  from w1thermsensor import SensorNotReadyError
@@ -65,7 +66,7 @@ class DallasSensorW1(TempSensor, AsyncUpdater):
65
66
  _temp = await self._pct.get_temperature()
66
67
  _LOGGER.debug("Fetched temperature %s. Applying filters.", _temp)
67
68
  _temp = self._apply_filters(value=_temp)
68
- if _temp is None:
69
+ if not _temp:
69
70
  return
70
71
  self._state = _temp
71
72
  self._send_message(
@@ -0,0 +1,2 @@
1
+ # flake8: noqa
2
+ __version__ = "0.5.0dev2"
@@ -27,7 +27,7 @@ dependencies = [
27
27
  "w1thermsensor[async]>=2.0.0",
28
28
  ]
29
29
  requires-python = ">=3.7"
30
- version = "0.5.0"
30
+ version = "0.5.0dev2"
31
31
 
32
32
  [project.license]
33
33
  text = "GNU General Public License v3.0"
@@ -1,4 +0,0 @@
1
- type: string
2
- required: False
3
- meta:
4
- label: Id of I2C to use in pin config
@@ -1,4 +0,0 @@
1
- type: string
2
- required: True
3
- default: °C
4
- allowed: ["°C", "°F"]
@@ -1,21 +0,0 @@
1
- {
2
- "model": "PT100",
3
- "registers_base": [
4
- {
5
- "base": 1,
6
- "length": 1,
7
- "register_type": "holding",
8
- "registers": [
9
- {
10
- "name": "Temperature1 PT100",
11
- "address": 1,
12
- "unit_of_measurement": "°C",
13
- "state_class": "measurement",
14
- "device_class": "temperature",
15
- "return_type": "multiply0_1"
16
- }
17
- ]
18
-
19
- }
20
- ]
21
- }
@@ -1,2 +0,0 @@
1
- # flake8: noqa
2
- __version__ = "0.5.0"
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