boneIO 0.1.2__tar.gz → 0.1.3__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.
Files changed (50) hide show
  1. {boneio-0.1.2/boneio.egg-info → boneio-0.1.3}/PKG-INFO +2 -2
  2. {boneio-0.1.2 → boneio-0.1.3}/boneio/bonecli.py +3 -7
  3. {boneio-0.1.2 → boneio-0.1.3}/boneio/const.py +3 -0
  4. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/__init__.py +10 -1
  5. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/ha_discovery.py +19 -19
  6. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/yaml.py +18 -0
  7. {boneio-0.1.2 → boneio-0.1.3}/boneio/manager.py +24 -16
  8. {boneio-0.1.2 → boneio-0.1.3}/boneio/relay/basic.py +7 -2
  9. {boneio-0.1.2 → boneio-0.1.3}/boneio/relay/mcp.py +5 -5
  10. {boneio-0.1.2 → boneio-0.1.3}/boneio/schema.yaml +3 -3
  11. {boneio-0.1.2 → boneio-0.1.3}/boneio/sensor/sdm630.py +1 -1
  12. boneio-0.1.3/boneio/version.py +2 -0
  13. {boneio-0.1.2 → boneio-0.1.3/boneio.egg-info}/PKG-INFO +2 -2
  14. boneio-0.1.2/boneio/version.py +0 -2
  15. {boneio-0.1.2 → boneio-0.1.3}/LICENSE +0 -0
  16. {boneio-0.1.2 → boneio-0.1.3}/MANIFEST.in +0 -0
  17. {boneio-0.1.2 → boneio-0.1.3}/README.md +0 -0
  18. {boneio-0.1.2 → boneio-0.1.3}/boneio/__init__.py +0 -0
  19. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/__init__.py +0 -0
  20. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/adc.yaml +0 -0
  21. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/config.yaml +0 -0
  22. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/input.yaml +0 -0
  23. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/output24x16A.yaml +0 -0
  24. {boneio-0.1.2 → boneio-0.1.3}/boneio/example_config/output32x5A.yaml +0 -0
  25. {boneio-0.1.2 → boneio-0.1.3}/boneio/fonts/danube__.ttf +0 -0
  26. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/exceptions.py +0 -0
  27. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/gpio.py +0 -0
  28. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/mqtt.py +0 -0
  29. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/oled.py +0 -0
  30. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/queue.py +0 -0
  31. {boneio-0.1.2 → boneio-0.1.3}/boneio/helper/stats.py +0 -0
  32. {boneio-0.1.2 → boneio-0.1.3}/boneio/input/__init__.py +0 -0
  33. {boneio-0.1.2 → boneio-0.1.3}/boneio/input/gpio.py +0 -0
  34. {boneio-0.1.2 → boneio-0.1.3}/boneio/modbus.py +0 -0
  35. {boneio-0.1.2 → boneio-0.1.3}/boneio/mqtt_client.py +0 -0
  36. {boneio-0.1.2 → boneio-0.1.3}/boneio/oled.py +0 -0
  37. {boneio-0.1.2 → boneio-0.1.3}/boneio/relay/__init__.py +0 -0
  38. {boneio-0.1.2 → boneio-0.1.3}/boneio/relay/gpio.py +0 -0
  39. {boneio-0.1.2 → boneio-0.1.3}/boneio/sensor/__init__.py +0 -0
  40. {boneio-0.1.2 → boneio-0.1.3}/boneio/sensor/adc.py +0 -0
  41. {boneio-0.1.2 → boneio-0.1.3}/boneio/sensor/gpio.py +0 -0
  42. {boneio-0.1.2 → boneio-0.1.3}/boneio/sensor/temp/__init__.py +0 -0
  43. {boneio-0.1.2 → boneio-0.1.3}/boneio.egg-info/SOURCES.txt +0 -0
  44. {boneio-0.1.2 → boneio-0.1.3}/boneio.egg-info/dependency_links.txt +0 -0
  45. {boneio-0.1.2 → boneio-0.1.3}/boneio.egg-info/entry_points.txt +0 -0
  46. {boneio-0.1.2 → boneio-0.1.3}/boneio.egg-info/requires.txt +0 -0
  47. {boneio-0.1.2 → boneio-0.1.3}/boneio.egg-info/top_level.txt +0 -0
  48. {boneio-0.1.2 → boneio-0.1.3}/requirements.txt +0 -0
  49. {boneio-0.1.2 → boneio-0.1.3}/setup.cfg +0 -0
  50. {boneio-0.1.2 → boneio-0.1.3}/setup.py +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneio
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Python App for BoneIO
5
5
  Home-page: https://github.com/boneIO-eu/app_bbb
6
6
  License: GNU General Public License v3.0
7
- Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.1.2.zip
7
+ Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.1.3.zip
8
8
  Platform: UNKNOWN
9
9
  Classifier: Programming Language :: Python
10
10
  Classifier: Programming Language :: Python :: 3.7
@@ -26,7 +26,7 @@ from boneio.const import (
26
26
  TOPIC_PREFIX,
27
27
  USERNAME,
28
28
  )
29
- from boneio.helper import CustomValidator, load_yaml_file
29
+ from boneio.helper import load_config_from_file
30
30
  from boneio.manager import Manager
31
31
  from boneio.mqtt_client import MQTTClient
32
32
  from boneio.version import __version__
@@ -124,13 +124,9 @@ async def run(ctx, debug: int, config: str, mqttpassword: str = ""):
124
124
  logging.getLogger("pymodbus.client").setLevel(logging.DEBUG)
125
125
  else:
126
126
  logging.getLogger(PAHO).setLevel(logging.WARN)
127
- schema = load_yaml_file(os.path.join(MAINPATH, "schema.yaml"))
128
- v = CustomValidator(schema, purge_unknown=True)
129
- config_yaml = load_yaml_file(config)
130
- if not config_yaml:
131
- _LOGGER.info("Missing file.")
127
+ _config = load_config_from_file(config_file=config)
128
+ if not _config:
132
129
  return
133
- _config = v.normalized(config_yaml)
134
130
  _LOGGER.info("Connecting to MQTT.")
135
131
  client = MQTTClient(
136
132
  host=_config[MQTT][HOST],
@@ -3,6 +3,8 @@ from datetime import timedelta
3
3
  from Adafruit_BBIO.GPIO import HIGH, LOW, BOTH, FALLING
4
4
  from typing_extensions import Literal
5
5
 
6
+ BONEIO = "boneIO"
7
+
6
8
 
7
9
  # MISCELLANEOUS CONSTS
8
10
  RELAY = "relay"
@@ -46,6 +48,7 @@ SECOND_DELAY_DURATION = 0.3
46
48
  HOMEASSISTANT = "homeassistant"
47
49
  HA_DISCOVERY = "ha_discovery"
48
50
  HA_TYPE = "ha_type"
51
+ OUTPUT_TYPE = "output_type"
49
52
  SHOW_HA = "show_in_ha"
50
53
 
51
54
  # OLED CONST
@@ -11,7 +11,13 @@ from boneio.helper.gpio import (
11
11
  from boneio.helper.oled import make_font
12
12
  from boneio.helper.mqtt import BasicMqtt
13
13
  from boneio.helper.stats import HostData, host_stats
14
- from boneio.helper.yaml import CustomValidator, load_yaml_file
14
+ from boneio.helper.yaml import (
15
+ CustomValidator,
16
+ load_yaml_file,
17
+ schema_file,
18
+ load_config_from_string,
19
+ load_config_from_file,
20
+ )
15
21
  from boneio.helper.ha_discovery import (
16
22
  ha_relay_availabilty_message,
17
23
  ha_sensor_temp_availabilty_message,
@@ -47,4 +53,7 @@ __all__ = [
47
53
  "configure_pin",
48
54
  "BasicMqtt",
49
55
  "UniqueQueue",
56
+ "schema_file",
57
+ "load_config_from_string",
58
+ "load_config_from_file",
50
59
  ]
@@ -4,16 +4,16 @@ from boneio.version import __version__
4
4
  from boneio.const import INPUT, OFF, ON, RELAY, STATE, SENSOR, INPUT_SENSOR
5
5
 
6
6
 
7
- def ha_relay_availabilty_message(id: str, name: str, topic: str = "boneio"):
7
+ def ha_relay_availabilty_message(id: str, name: str, topic: str = "boneIO"):
8
8
  """Create availability topic for HA."""
9
9
  return {
10
10
  "availability": [{"topic": f"{topic}/{STATE}"}],
11
11
  "command_topic": f"{topic}/relay/{id}/set",
12
12
  "device": {
13
13
  "identifiers": [topic],
14
- "manufacturer": "BoneIO",
15
- "model": "BoneIO Relay Board",
16
- "name": f"BoneIO {topic}",
14
+ "manufacturer": "boneIO",
15
+ "model": "boneIO Relay Board",
16
+ "name": f"boneIO {topic}",
17
17
  "sw_version": __version__,
18
18
  },
19
19
  "name": name,
@@ -26,16 +26,16 @@ def ha_relay_availabilty_message(id: str, name: str, topic: str = "boneio"):
26
26
 
27
27
 
28
28
  def ha_availabilty_message(
29
- id: str, name: str, topic: str = "boneio", sensor_type: str = INPUT
29
+ id: str, name: str, topic: str = "boneIO", sensor_type: str = INPUT
30
30
  ):
31
31
  """Create availability topic for HA."""
32
32
  return {
33
33
  "availability": [{"topic": f"{topic}/{STATE}"}],
34
34
  "device": {
35
35
  "identifiers": [topic],
36
- "manufacturer": "BoneIO",
37
- "model": "BoneIO Relay Board",
38
- "name": f"BoneIO {topic}",
36
+ "manufacturer": "boneIO",
37
+ "model": "boneIO Relay Board",
38
+ "name": f"boneIO {topic}",
39
39
  "sw_version": __version__,
40
40
  },
41
41
  "icon": "mdi:gesture-double-tap",
@@ -63,15 +63,15 @@ def ha_sensor_availabilty_message(unit_of_measurement: str = None, **kwargs):
63
63
  return msg
64
64
 
65
65
 
66
- def ha_binary_sensor_availabilty_message(id: str, name: str, topic: str = "boneio"):
66
+ def ha_binary_sensor_availabilty_message(id: str, name: str, topic: str = "boneIO"):
67
67
  """Create availability topic for HA."""
68
68
  return {
69
69
  "availability": [{"topic": f"{topic}/{STATE}"}],
70
70
  "device": {
71
71
  "identifiers": [topic],
72
- "manufacturer": "BoneIO",
73
- "model": "BoneIO Relay Board",
74
- "name": f"BoneIO {topic}",
72
+ "manufacturer": "boneIO",
73
+ "model": "boneIO Relay Board",
74
+ "name": f"boneIO {topic}",
75
75
  "sw_version": __version__,
76
76
  },
77
77
  "payload_on": "pressed",
@@ -82,15 +82,15 @@ def ha_binary_sensor_availabilty_message(id: str, name: str, topic: str = "bonei
82
82
  }
83
83
 
84
84
 
85
- def ha_sensor_temp_availabilty_message(id: str, name: str, topic: str = "boneio"):
85
+ def ha_sensor_temp_availabilty_message(id: str, name: str, topic: str = "boneIO"):
86
86
  """Create availability topic for HA."""
87
87
  return {
88
88
  "availability": [{"topic": f"{topic}/{STATE}"}],
89
89
  "device": {
90
90
  "identifiers": [topic],
91
- "manufacturer": "BoneIO",
92
- "model": "BoneIO Relay Board",
93
- "name": f"BoneIO {topic}",
91
+ "manufacturer": "boneIO",
92
+ "model": "boneIO Relay Board",
93
+ "name": f"boneIO {topic}",
94
94
  "sw_version": __version__,
95
95
  },
96
96
  "name": name,
@@ -115,10 +115,10 @@ def sdm630_availabilty_message(
115
115
  return {
116
116
  "availability": [{"topic": f"{topic}/{id}{STATE}"}],
117
117
  "device": {
118
- "identifiers": [topic, id],
119
- "manufacturer": "BoneIO",
118
+ "identifiers": [id],
119
+ "manufacturer": "boneIO",
120
120
  "model": "SDM630",
121
- "name": f"BoneIO {name.upper()}",
121
+ "name": f"boneIO {name.upper()}",
122
122
  "sw_version": __version__,
123
123
  },
124
124
  "name": sensor_id,
@@ -1,9 +1,13 @@
1
+ import logging
1
2
  from typing import Any
2
3
  import os
3
4
  from cerberus import Validator
4
5
  from boneio.const import ID, OUTPUT
5
6
  from yaml import load, YAMLError, SafeLoader
6
7
 
8
+ schema_file = os.path.join(os.path.dirname(__file__), "../schema.yaml")
9
+ _LOGGER = logging.getLogger(__name__)
10
+
7
11
 
8
12
  class Loader(SafeLoader):
9
13
  """Loader which support for include in yaml files."""
@@ -33,6 +37,20 @@ def load_yaml_file(filename: str) -> Any:
33
37
  raise exception
34
38
 
35
39
 
40
+ def load_config_from_string(config_yaml: str):
41
+ schema = load_yaml_file(schema_file)
42
+ v = CustomValidator(schema, purge_unknown=True)
43
+ return v.normalized(config_yaml)
44
+
45
+
46
+ def load_config_from_file(config_file: str):
47
+ config_yaml = load_yaml_file(config_file)
48
+ if not config_yaml:
49
+ _LOGGER.info("Missing file.")
50
+ return None
51
+ return load_config_from_string(config_yaml)
52
+
53
+
36
54
  class CustomValidator(Validator):
37
55
  """Custom validator of cerberus"""
38
56
 
@@ -12,8 +12,10 @@ from boneio.const import (
12
12
  ACTION,
13
13
  ACTIONS,
14
14
  ADDRESS,
15
+ BONEIO,
15
16
  GPIO,
16
17
  HA_TYPE,
18
+ OUTPUT_TYPE,
17
19
  HOMEASSISTANT,
18
20
  ID,
19
21
  INIT_SLEEP,
@@ -66,10 +68,10 @@ class Manager:
66
68
  def __init__(
67
69
  self,
68
70
  send_message: Callable[[str, Union[str, dict]], None],
69
- topic_prefix: str,
70
- relay_pins: List,
71
- input_pins: List,
71
+ relay_pins: List = [],
72
+ input_pins: List = [],
72
73
  sensors: dict = {},
74
+ topic_prefix: str = BONEIO,
73
75
  modbus: dict = None,
74
76
  ha_discovery: bool = True,
75
77
  ha_discovery_prefix: str = HOMEASSISTANT,
@@ -239,7 +241,7 @@ class Manager:
239
241
  topic_prefix=topic_prefix,
240
242
  mcp=mcp,
241
243
  mcp_id=mcp_id,
242
- ha_type=gpio[HA_TYPE],
244
+ output_type=gpio[OUTPUT_TYPE],
243
245
  callback=lambda: self._host_data_callback(mcp_id),
244
246
  )
245
247
  self._grouped_outputs[mcp_id][relay_id] = mcp_relay
@@ -257,17 +259,18 @@ class Manager:
257
259
  self._grouped_outputs[GPIO][relay_id] = gpio_relay
258
260
  return gpio_relay
259
261
 
260
- self.output = {
262
+ self._output = {
261
263
  gpio[ID].replace(" ", ""): configure_relay(gpio) for gpio in relay_pins
262
264
  }
263
- for out in self.output.values():
264
- self.send_ha_autodiscovery(
265
- id=out.id,
266
- name=out.name,
267
- ha_type=out.ha_type,
268
- ha_discovery_prefix=ha_discovery_prefix,
269
- availabilty_msg_func=ha_relay_availabilty_message,
270
- )
265
+ for out in self._output.values():
266
+ if out.output_type != "none":
267
+ self.send_ha_autodiscovery(
268
+ id=out.id,
269
+ name=out.name,
270
+ ha_type=out.output_type,
271
+ ha_discovery_prefix=ha_discovery_prefix,
272
+ availabilty_msg_func=ha_relay_availabilty_message,
273
+ )
271
274
  self._loop.call_soon_threadsafe(
272
275
  self._loop.call_later,
273
276
  0.5,
@@ -359,7 +362,7 @@ class Manager:
359
362
  if action:
360
363
  if action[ACTION] == OUTPUT:
361
364
  """For now only output type is supported"""
362
- relay = self.output.get(action[PIN].replace(" ", ""))
365
+ relay = self._output.get(action[PIN].replace(" ", ""))
363
366
  if relay:
364
367
  relay.toggle()
365
368
  # This is similar how Z2M is clearing click sensor.
@@ -370,8 +373,8 @@ class Manager:
370
373
  id: str,
371
374
  name: str,
372
375
  ha_discovery_prefix: str,
376
+ ha_type: str,
373
377
  availabilty_msg_func: Callable,
374
- ha_type: str = "switch",
375
378
  topic_prefix: str = None,
376
379
  **kwargs,
377
380
  ) -> None:
@@ -390,9 +393,14 @@ class Manager:
390
393
  extracted_relay = topic.replace(f"{self._topic_prefix}/{RELAY}/", "").replace(
391
394
  "/set", ""
392
395
  )
393
- target_device = self.output.get(extracted_relay)
396
+ target_device = self._output.get(extracted_relay)
394
397
  if target_device:
395
398
  if message == ON:
396
399
  target_device.turn_on()
397
400
  elif message == OFF:
398
401
  target_device.turn_off()
402
+
403
+ @property
404
+ def output(self) -> dict:
405
+ """Get list of output."""
406
+ return self._output
@@ -14,11 +14,11 @@ class BasicRelay(BasicMqtt):
14
14
  """Basic relay class."""
15
15
 
16
16
  def __init__(
17
- self, callback: Callable, id: str = None, ha_type=SWITCH, **kwargs
17
+ self, callback: Callable, id: str = None, output_type=SWITCH, **kwargs
18
18
  ) -> None:
19
19
  """Initialize Basic relay."""
20
20
  super().__init__(id=id, name=id, topic_type=RELAY, **kwargs)
21
- self._ha_type = ha_type
21
+ self._output_type = output_type
22
22
  self._state = False
23
23
  self._callback = callback
24
24
  self._loop = asyncio.get_running_loop()
@@ -28,6 +28,11 @@ class BasicRelay(BasicMqtt):
28
28
  """Check if relay is mcp type."""
29
29
  return False
30
30
 
31
+ @property
32
+ def output_type(self) -> str:
33
+ """HA type."""
34
+ return self._output_type
35
+
31
36
  @property
32
37
  def id(self) -> bool:
33
38
  """Id of the relay.
@@ -25,6 +25,11 @@ class MCPRelay(BasicRelay):
25
25
  """Check if relay is mcp type."""
26
26
  return True
27
27
 
28
+ @property
29
+ def pin_id(self) -> str:
30
+ """Return PIN id."""
31
+ return self._pin_id
32
+
28
33
  @property
29
34
  def mcp_id(self) -> str:
30
35
  """Retrieve parent MCP ID."""
@@ -40,11 +45,6 @@ class MCPRelay(BasicRelay):
40
45
  """PIN of the relay"""
41
46
  return self._pin
42
47
 
43
- @property
44
- def ha_type(self) -> str:
45
- """HA type."""
46
- return self._ha_type
47
-
48
48
  def turn_on(self) -> None:
49
49
  """Call turn on action."""
50
50
  self.pin.value = True
@@ -174,13 +174,13 @@ output:
174
174
  required: True
175
175
  meta:
176
176
  label: PIN to use.
177
- ha_type:
177
+ output_type:
178
178
  type: string
179
179
  required: True
180
- allowed: ['switch', 'light']
180
+ allowed: ['switch', 'light', 'none']
181
181
  default: 'switch'
182
182
  meta:
183
- label: If HA discovery is used device if relay is light or switch.
183
+ label: If HA discovery is used device if relay is light or switch. If None is declared then any state is not published to MQTT (used for cover).
184
184
 
185
185
 
186
186
  input:
@@ -135,7 +135,7 @@ class Sdm630(BasicMqtt):
135
135
  _LOGGER.debug("Sending HA discovery for sensor %s %s.", sdm_name, sensor_id)
136
136
  self._send_message(
137
137
  topic=(
138
- f"{self._ha_discovery_prefix}/{SENSOR}/{self._topic_prefix}"
138
+ f"{self._ha_discovery_prefix}/{SENSOR}/{self._topic_prefix}{id}"
139
139
  f"/{id}{sensor_id.replace('_', '').lower()}/config"
140
140
  ),
141
141
  payload=sdm630_availabilty_message(
@@ -0,0 +1,2 @@
1
+ # flake8: noqa
2
+ __version__ = "0.1.3"
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneio
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Python App for BoneIO
5
5
  Home-page: https://github.com/boneIO-eu/app_bbb
6
6
  License: GNU General Public License v3.0
7
- Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.1.2.zip
7
+ Download-URL: https://github.com/boneIO-eu/app_bbb/archive/0.1.3.zip
8
8
  Platform: UNKNOWN
9
9
  Classifier: Programming Language :: Python
10
10
  Classifier: Programming Language :: Python :: 3.7
@@ -1,2 +0,0 @@
1
- # flake8: noqa
2
- __version__ = "0.1.2"
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