boneIO 0.6.3.dev3__tar.gz → 0.7.0__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 (89) hide show
  1. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/PKG-INFO +1 -1
  2. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/bonecli.py +4 -2
  3. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/const.py +15 -0
  4. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/cover.py +1 -1
  5. boneIO-0.7.0/boneio/example_config/binary_sensor.yaml +21 -0
  6. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/config.yaml +2 -1
  7. boneIO-0.6.3.dev3/boneio/example_config/input.yaml → boneIO-0.7.0/boneio/example_config/event.yaml +2 -20
  8. boneIO-0.7.0/boneio/example_config/output24x16A_v0.3.yaml +143 -0
  9. boneIO-0.7.0/boneio/group/__init__.py +4 -0
  10. boneIO-0.7.0/boneio/group/output.py +64 -0
  11. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/__init__.py +2 -2
  12. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/async_updater.py +1 -1
  13. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/click_timer.py +2 -1
  14. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/config.py +6 -2
  15. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/events.py +16 -0
  16. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/gpio.py +10 -1
  17. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/ha_discovery.py +11 -7
  18. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/loader.py +184 -84
  19. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/mqtt.py +1 -1
  20. boneIO-0.7.0/boneio/helper/pcf8575.py +13 -0
  21. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/state_manager.py +5 -0
  22. boneIO-0.7.0/boneio/input/__init__.py +7 -0
  23. boneIO-0.7.0/boneio/input/gpio.py +73 -0
  24. boneIO-0.6.3.dev3/boneio/input/gpio.py → boneIO-0.7.0/boneio/input/gpio_new.py +32 -34
  25. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/manager.py +210 -52
  26. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/mqtt_client.py +24 -20
  27. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/relay/__init__.py +2 -1
  28. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/relay/basic.py +28 -9
  29. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/relay/mcp.py +9 -15
  30. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/relay/pca.py +6 -13
  31. boneIO-0.7.0/boneio/relay/pcf.py +86 -0
  32. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/runner.py +11 -5
  33. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/actions.yaml +1 -1
  34. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/schema.yaml +153 -13
  35. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/__init__.py +4 -2
  36. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/adc.py +2 -1
  37. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/gpio.py +4 -4
  38. boneIO-0.7.0/boneio/sensor/gpio_new.py +36 -0
  39. boneIO-0.7.0/boneio/version.py +2 -0
  40. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/pyproject.toml +11 -12
  41. boneIO-0.6.3.dev3/boneio/input/__init__.py +0 -5
  42. boneIO-0.6.3.dev3/boneio/version.py +0 -2
  43. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/LICENSE +0 -0
  44. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/README.md +0 -0
  45. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/__init__.py +0 -0
  46. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/__init__.py +0 -0
  47. boneIO-0.6.3.dev3/boneio/example_config/adc.yaml → boneIO-0.7.0/boneio/example_config/adc_v0_4.yaml +6 -6
  48. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/cover.yaml +0 -0
  49. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/led32x4A.yaml +0 -0
  50. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/output24x16A.yaml +0 -0
  51. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/example_config/output32x5A.yaml +0 -0
  52. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/fonts/danube__.ttf +0 -0
  53. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/exceptions.py +0 -0
  54. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/filter.py +0 -0
  55. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/logger.py +0 -0
  56. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/oled.py +0 -0
  57. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/onewire/W1ThermSensor.py +0 -0
  58. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/onewire/__init__.py +0 -0
  59. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/onewire/ds2482.py +0 -0
  60. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/onewire/onewire.py +0 -0
  61. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/queue.py +0 -0
  62. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/stats.py +0 -0
  63. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/timeperiod.py +0 -0
  64. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/util.py +0 -0
  65. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/helper/yaml_util.py +0 -0
  66. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/modbus.py +0 -0
  67. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/oled.py +0 -0
  68. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/relay/gpio.py +0 -0
  69. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/actions_sensor.yaml +0 -0
  70. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/actions_switch.yaml +0 -0
  71. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/filters.yaml +0 -0
  72. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/filters_adc.yaml +0 -0
  73. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/id.yaml +0 -0
  74. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/temp_unit.yaml +0 -0
  75. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/schema/update_interval.yaml +0 -0
  76. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/__init__.py +0 -0
  77. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/dts1964_3f.json +0 -0
  78. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/pt100.json +0 -0
  79. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/r4dcb08.json +0 -0
  80. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/sdm120.json +0 -0
  81. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/sdm630.json +0 -0
  82. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/modbus/sofar.json +0 -0
  83. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/temp/__init__.py +0 -0
  84. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/temp/dallas.py +0 -0
  85. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/temp/lm75.py +0 -0
  86. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/boneio/sensor/temp/mcp9808.py +0 -0
  87. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/tests/32_5_config.yaml +0 -0
  88. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/tests/bandit.yaml +0 -0
  89. {boneIO-0.6.3.dev3 → boneIO-0.7.0}/tests/relay_32_5.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: boneIO
3
- Version: 0.6.3.dev3
3
+ Version: 0.7.0
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>
@@ -15,6 +15,7 @@ from yaml import MarkedYAMLError
15
15
  from boneio.const import ACTION
16
16
  from boneio.helper import load_config_from_file
17
17
  from boneio.helper.exceptions import ConfigurationException, RestartRequestException
18
+ from boneio.helper.events import GracefulExit
18
19
  from boneio.helper.logger import configure_logger
19
20
  from boneio.runner import async_run
20
21
  from boneio.version import __version__
@@ -89,8 +90,9 @@ def run(config: str, debug: int, mqttusername: str = "", mqttpassword: str = "")
89
90
  ),
90
91
  )
91
92
  return 0
92
- except RestartRequestException as err:
93
- _LOGGER.info(err)
93
+ except (RestartRequestException, GracefulExit) as err:
94
+ if err is not None:
95
+ _LOGGER.info(err)
94
96
  return 0
95
97
  except (ConfigurationException, MarkedYAMLError) as err:
96
98
  _LOGGER.error("Failed to load config. %s Exiting.", err)
@@ -104,14 +104,19 @@ TOPIC_PREFIX = "topic_prefix"
104
104
  # I2C, PCA and MCP CONST
105
105
  ADDRESS = "address"
106
106
  MCP23017 = "mcp23017"
107
+ PCF8575 = "pcf8575"
107
108
  PCA9685 = "pca9685"
108
109
  MCP = "mcp"
110
+ PCF = "pcf"
109
111
  MCP_ID = "mcp_id"
110
112
  PCA_ID = "pca_id"
113
+ PCF_ID = "pcf_id"
111
114
  INIT_SLEEP = "init_sleep"
115
+ OUTPUT_GROUP = "output_group"
112
116
 
113
117
  # SENSOR CONST
114
118
  TEMPERATURE = "temperature"
119
+ EVENT_ENTITY = "event"
115
120
  SENSOR = "sensor"
116
121
  BINARY_SENSOR = "binary_sensor"
117
122
  LM75 = "lm75"
@@ -140,6 +145,16 @@ OledDataTypes = Literal[UPTIME, NETWORK, CPU, DISK, MEMORY, SWAP, OUTPUT]
140
145
  Gpio_States = Literal[HIGH, LOW]
141
146
  Gpio_Edges = Literal[BOTH, FALLING]
142
147
  InputTypes = Literal[INPUT, INPUT_SENSOR]
148
+ ExpanderTypes = Literal[MCP23017, PCA9685, PCF8575]
143
149
  DEVICE_CLASS = "device_class"
144
150
  DallasBusTypes = Literal[DS2482, DALLAS]
145
151
  FILTERS = "filters"
152
+
153
+ cover_actions = {
154
+ "OPEN": "open",
155
+ "CLOSE": "close",
156
+ "TOGGLE": "toggle",
157
+ "STOP": "stop",
158
+ "TOGGLE_OPEN": "toggle_open",
159
+ "TOGGLE_CLOSE": "toggle_close",
160
+ }
@@ -109,7 +109,7 @@ class Cover(BasicMqtt):
109
109
  self._stop_cover(on_exit=True)
110
110
 
111
111
  @property
112
- def cover_state(self) -> CLOSED | OPEN:
112
+ def cover_state(self) -> str:
113
113
  """Current state of cover."""
114
114
  return CLOSED if self._closed else OPEN
115
115
 
@@ -0,0 +1,21 @@
1
+ - id: IN_47
2
+ pin: P8_12
3
+ kind: sensor
4
+ detection_type: "old"
5
+ - id: IN_48
6
+ pin: P8_11
7
+ kind: sensor
8
+ detection_type: "new"
9
+ - id: IN_49
10
+ pin: P8_10
11
+ kind: sensor
12
+
13
+ - id: IN_50
14
+ pin: P8_9
15
+ kind: sensor
16
+ - id: IN_51
17
+ pin: P8_8
18
+ kind: sensor
19
+ - id: IN_52
20
+ pin: P8_7
21
+ kind: sensor
@@ -18,7 +18,8 @@ mcp23017:
18
18
  - id: mcp2
19
19
  address: 0x21
20
20
 
21
- input: !include input.yaml
21
+ event: !include event.yaml
22
+ binary_sensor: !include binary_sensor.yaml
22
23
 
23
24
  output: !include output32x5A.yaml
24
25
 
@@ -1,5 +1,6 @@
1
1
  - id: IN_01
2
2
  pin: P8_37
3
+ detection_type: "old"
3
4
  actions:
4
5
  single:
5
6
  - action: output
@@ -9,6 +10,7 @@
9
10
  pin: switch 1
10
11
  - id: IN_02
11
12
  pin: P8_38
13
+ detection_type: "new"
12
14
  actions:
13
15
  single:
14
16
  - action: output
@@ -182,23 +184,3 @@
182
184
  pin: P8_14
183
185
  - id: IN_46
184
186
  pin: P8_13
185
-
186
- - id: IN_47
187
- pin: P8_12
188
- kind: sensor
189
- - id: IN_48
190
- pin: P8_11
191
- kind: sensor
192
- - id: IN_49
193
- pin: P8_10
194
- kind: sensor
195
-
196
- - id: IN_50
197
- pin: P8_9
198
- kind: sensor
199
- - id: IN_51
200
- pin: P8_8
201
- kind: sensor
202
- - id: IN_52
203
- pin: P8_7
204
- kind: sensor
@@ -0,0 +1,143 @@
1
+ - id: OUT_01
2
+ kind: mcp
3
+ mcp_id: mcp1
4
+ pin: 9
5
+ output_type: light
6
+
7
+ - id: OUT_02
8
+ kind: mcp
9
+ mcp_id: mcp1
10
+ pin: 8
11
+ output_type: light
12
+
13
+ - id: OUT_03
14
+ kind: mcp
15
+ mcp_id: mcp2
16
+ pin: 1
17
+ output_type: light
18
+
19
+ - id: OUT_04
20
+ kind: mcp
21
+ mcp_id: mcp2
22
+ pin: 0
23
+ output_type: light
24
+
25
+ - id: OUT_05
26
+ kind: mcp
27
+ mcp_id: mcp1
28
+ pin: 13
29
+ output_type: light
30
+
31
+ - id: OUT_06
32
+ kind: mcp
33
+ mcp_id: mcp1
34
+ pin: 12
35
+ output_type: light
36
+
37
+ - id: OUT_07
38
+ kind: mcp
39
+ mcp_id: mcp1
40
+ pin: 11
41
+ output_type: light
42
+
43
+ - id: OUT_08
44
+ kind: mcp
45
+ mcp_id: mcp1
46
+ pin: 10
47
+ output_type: light
48
+
49
+ - id: OUT_09
50
+ kind: mcp
51
+ mcp_id: mcp2
52
+ pin: 14
53
+ output_type: light
54
+
55
+ - id: OUT_10
56
+ kind: mcp
57
+ mcp_id: mcp2
58
+ pin: 15
59
+ output_type: light
60
+
61
+ - id: OUT_11
62
+ kind: mcp
63
+ mcp_id: mcp2
64
+ pin: 13
65
+ output_type: light
66
+
67
+ - id: OUT_12
68
+ kind: mcp
69
+ mcp_id: mcp2
70
+ pin: 12
71
+ output_type: light
72
+
73
+ - id: OUT_13
74
+ kind: mcp
75
+ mcp_id: mcp1
76
+ pin: 6
77
+ output_type: light
78
+
79
+ - id: OUT_14
80
+ kind: mcp
81
+ mcp_id: mcp1
82
+ pin: 5
83
+ output_type: light
84
+
85
+ - id: OUT_15
86
+ kind: mcp
87
+ mcp_id: mcp1
88
+ pin: 4
89
+ output_type: light
90
+
91
+ - id: OUT_16
92
+ kind: mcp
93
+ mcp_id: mcp1
94
+ pin: 3
95
+ output_type: light
96
+
97
+ - id: OUT_17
98
+ kind: mcp
99
+ mcp_id: mcp1
100
+ pin: 2
101
+ output_type: light
102
+
103
+ - id: OUT_18
104
+ kind: mcp
105
+ mcp_id: mcp1
106
+ pin: 0
107
+ output_type: light
108
+
109
+ - id: OUT_19
110
+ kind: mcp
111
+ mcp_id: mcp1
112
+ pin: 1
113
+ output_type: light
114
+
115
+ - id: OUT_20
116
+ kind: mcp
117
+ mcp_id: mcp1
118
+ pin: 7
119
+ output_type: light
120
+
121
+ - id: OUT_21
122
+ kind: mcp
123
+ mcp_id: mcp2
124
+ pin: 8
125
+ output_type: light
126
+
127
+ - id: OUT_22
128
+ kind: mcp
129
+ mcp_id: mcp2
130
+ pin: 9
131
+ output_type: light
132
+
133
+ - id: OUT_23
134
+ kind: mcp
135
+ mcp_id: mcp2
136
+ pin: 11
137
+ output_type: light
138
+
139
+ - id: OUT_24
140
+ kind: mcp
141
+ mcp_id: mcp2
142
+ pin: 10
143
+ output_type: light
@@ -0,0 +1,4 @@
1
+ """Group classes."""
2
+ from .output import OutputGroup
3
+
4
+ __all__ = ["OutputGroup"]
@@ -0,0 +1,64 @@
1
+ """Cover module."""
2
+ from __future__ import annotations
3
+ import logging
4
+ import asyncio
5
+ from typing import List
6
+
7
+ from boneio.const import COVER, SWITCH, ON, OFF
8
+ from boneio.relay.basic import BasicRelay
9
+
10
+ _LOGGER = logging.getLogger(__name__)
11
+
12
+
13
+ class OutputGroup(BasicRelay):
14
+ """Cover class of boneIO"""
15
+
16
+ def __init__(
17
+ self,
18
+ members: List[BasicRelay],
19
+ output_type: str = SWITCH,
20
+ restored_state: bool = True,
21
+ **kwargs,
22
+ ) -> None:
23
+ """Initialize cover class."""
24
+ self._loop = asyncio.get_event_loop()
25
+ super().__init__(
26
+ **kwargs, output_type=output_type, restored_state=restored_state, topic_type="group"
27
+ )
28
+ self._group_members = [x for x in members if x.output_type != COVER]
29
+ self._timer_handle = None
30
+ for member in self._group_members:
31
+ self._event_bus.add_output_listener(member.id, self.event_listener)
32
+
33
+ async def event_listener(self, relay_id=None) -> None:
34
+ """Listen for events called by children relays."""
35
+ state = OFF
36
+ for x in self._group_members:
37
+ if x.state == ON:
38
+ state = ON
39
+ break
40
+ if state != self._state or not relay_id:
41
+ self._state = state
42
+ self._loop.call_soon_threadsafe(self.send_state)
43
+
44
+ def turn_on(self) -> None:
45
+ """Call turn on action."""
46
+ for x in self._group_members:
47
+ asyncio.create_task(x.async_turn_on())
48
+
49
+ def turn_off(self) -> None:
50
+ """Call turn off action."""
51
+ for x in self._group_members:
52
+ asyncio.create_task(x.async_turn_off())
53
+
54
+ def toggle(self) -> None:
55
+ """Toggle group."""
56
+ _LOGGER.debug("Toggle relay.")
57
+ if self._state == ON:
58
+ self.turn_off()
59
+ else:
60
+ self.turn_on()
61
+
62
+ def send_state(self) -> None:
63
+ """Send state to Mqtt on action."""
64
+ self._send_message(topic=self._send_topic, payload=self.payload(), retain=True)
@@ -15,7 +15,7 @@ from boneio.helper.ha_discovery import (
15
15
  ha_adc_sensor_availabilty_message,
16
16
  ha_binary_sensor_availabilty_message,
17
17
  ha_button_availabilty_message,
18
- ha_input_availabilty_message,
18
+ ha_event_availabilty_message,
19
19
  ha_light_availabilty_message,
20
20
  ha_sensor_availabilty_message,
21
21
  ha_sensor_temp_availabilty_message,
@@ -54,7 +54,7 @@ __all__ = [
54
54
  "ha_sensor_temp_availabilty_message",
55
55
  "ha_binary_sensor_availabilty_message",
56
56
  "ha_button_availabilty_message",
57
- "ha_input_availabilty_message",
57
+ "ha_event_availabilty_message",
58
58
  "ha_led_availabilty_message",
59
59
  "GPIOInputException",
60
60
  "GPIOOutputException",
@@ -15,7 +15,7 @@ class AsyncUpdater:
15
15
  self._update_interval = update_interval or TimePeriod(seconds=60)
16
16
  self.manager.append_task(coro=self._refresh, name=self.id)
17
17
 
18
- async def _refresh(self):
18
+ async def _refresh(self) -> None:
19
19
  while True:
20
20
  if hasattr(self, "async_update"):
21
21
  update_interval = (
@@ -24,9 +24,10 @@ class ClickTimer:
24
24
  self._remove_listener = None
25
25
 
26
26
  async def _start_async_timer(self) -> None:
27
+ start = time.time()
27
28
  await asyncio.sleep(self._delay)
28
29
  self._remove_listener = None
29
- self._action(time.time())
30
+ self._action(round(time.time() - start, 2))
30
31
 
31
32
  def start_timer(self) -> None:
32
33
  """Start timer."""
@@ -4,7 +4,7 @@ Module to provide basic config options.
4
4
  from __future__ import annotations
5
5
  from _collections_abc import dict_values
6
6
  from typing import Union
7
- from boneio.const import BONEIO, HOMEASSISTANT, LIGHT, SENSOR, COVER, BUTTON, SWITCH, BINARY_SENSOR
7
+ from boneio.const import BONEIO, HOMEASSISTANT, LIGHT, SENSOR, COVER, BUTTON, SWITCH, BINARY_SENSOR, EVENT_ENTITY
8
8
 
9
9
 
10
10
  class ConfigHelper:
@@ -24,7 +24,8 @@ class ConfigHelper:
24
24
  BINARY_SENSOR: {},
25
25
  SENSOR: {},
26
26
  COVER: {},
27
- BUTTON: {}
27
+ BUTTON: {},
28
+ EVENT_ENTITY: {}
28
29
  }
29
30
  self.manager_ready: bool = False
30
31
 
@@ -63,6 +64,9 @@ class ConfigHelper:
63
64
  if topic in self._autodiscovery_messages[ha_type]:
64
65
  return True
65
66
  return False
67
+
68
+ def clear_autodiscovery_type(self, ha_type: str):
69
+ self._autodiscovery_messages[ha_type] = {}
66
70
 
67
71
 
68
72
 
@@ -81,6 +81,7 @@ class EventBus:
81
81
  """Initialize handler"""
82
82
  self._loop = loop or asyncio.get_event_loop()
83
83
  self._listeners = {}
84
+ self._output_listeners = {}
84
85
  self._sigterm_listeners = []
85
86
  self._haonline_listeners = []
86
87
  self._timer_handle = _async_create_timer(self._loop, self._run_second_event)
@@ -102,9 +103,11 @@ class EventBus:
102
103
  """Function to call on exit. Should invoke all sigterm listeners."""
103
104
  _LOGGER.debug("Exiting process started.")
104
105
  self._listeners = {}
106
+ self._output_listeners = {}
105
107
  for target in self._sigterm_listeners:
106
108
  target()
107
109
  self._timer_handle()
110
+
108
111
  _LOGGER.info("Shutdown gracefully.")
109
112
  raise GracefulExit(code=0)
110
113
 
@@ -117,6 +120,19 @@ class EventBus:
117
120
  """Add sigterm listener."""
118
121
  self._sigterm_listeners.append(target)
119
122
 
123
+ def add_output_listener(self, name, target):
124
+ """Add output listener."""
125
+ self._output_listeners[name] = ListenerJob(target=target)
126
+ return self._output_listeners[name]
127
+
128
+ def trigger_output_event(self, event):
129
+ asyncio.create_task(self.async_trigger_output_event(event=event))
130
+
131
+ async def async_trigger_output_event(self, event):
132
+ listener = self._output_listeners.get(event)
133
+ if listener:
134
+ await listener.target(event)
135
+
120
136
  def add_haonline_listener(self, target):
121
137
  """Add HA Online listener."""
122
138
  self._haonline_listeners.append(target)
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import asyncio
2
3
  import logging
3
4
 
@@ -104,7 +105,7 @@ class GpioBaseClass:
104
105
  """Base class for initialize GPIO"""
105
106
 
106
107
  def __init__(
107
- self, pin: str, press_callback: Callable[[ClickTypes, str], None], **kwargs
108
+ self, pin: str, press_callback: Callable[[ClickTypes, str, bool | None], None], **kwargs
108
109
  ) -> None:
109
110
  """Setup GPIO Input Button"""
110
111
  self._pin = pin
@@ -114,7 +115,15 @@ class GpioBaseClass:
114
115
  self._press_callback = press_callback
115
116
  setup_input(pin=self._pin, pull_mode=gpio_mode)
116
117
 
118
+ def set_press_callback(self, press_callback: Callable[[ClickTypes, str, bool | None], None]) -> None:
119
+ self._press_callback = press_callback
120
+
117
121
  @property
118
122
  def is_pressed(self) -> bool:
119
123
  """Is button pressed."""
120
124
  return read_input(self._pin)
125
+
126
+ @property
127
+ def pin(self) -> str:
128
+ """Return configured pin."""
129
+ return self._pin
@@ -13,6 +13,9 @@ from boneio.const import (
13
13
  SENSOR,
14
14
  STATE,
15
15
  STOP,
16
+ SINGLE,
17
+ DOUBLE,
18
+ LONG
16
19
  )
17
20
  from boneio.version import __version__
18
21
 
@@ -42,10 +45,10 @@ def ha_availabilty_message(
42
45
  }
43
46
 
44
47
 
45
- def ha_light_availabilty_message(id: str, topic: str = "boneIO", **kwargs):
48
+ def ha_light_availabilty_message(id: str, topic: str = "boneIO", device_type: str = RELAY, **kwargs):
46
49
  """Create LIGHT availability topic for HA."""
47
- msg = ha_availabilty_message(device_type=RELAY, topic=topic, id=id, **kwargs)
48
- msg["command_topic"] = f"{topic}/cmd/{RELAY}/{id}/set"
50
+ msg = ha_availabilty_message(device_type=device_type, topic=topic, id=id, **kwargs)
51
+ msg["command_topic"] = f"{topic}/cmd/{device_type}/{id}/set"
49
52
  msg["payload_off"] = OFF
50
53
  msg["payload_on"] = ON
51
54
  msg["state_value_template"] = "{{ value_json.state }}"
@@ -76,19 +79,20 @@ def ha_button_availabilty_message(
76
79
  return msg
77
80
 
78
81
 
79
- def ha_switch_availabilty_message(id: str, topic: str = "boneIO", **kwargs):
82
+ def ha_switch_availabilty_message(id: str, topic: str = "boneIO", device_type: str = RELAY, **kwargs):
80
83
  """Create SWITCH availability topic for HA."""
81
- msg = ha_availabilty_message(device_type=RELAY, topic=topic, id=id, **kwargs)
82
- msg["command_topic"] = f"{topic}/cmd/relay/{id}/set"
84
+ msg = ha_availabilty_message(device_type=device_type, topic=topic, id=id, **kwargs)
85
+ msg["command_topic"] = f"{topic}/cmd/{device_type}/{id}/set"
83
86
  msg["payload_off"] = OFF
84
87
  msg["payload_on"] = ON
85
88
  msg["value_template"] = "{{ value_json.state }}"
86
89
  return msg
87
90
 
88
91
 
89
- def ha_input_availabilty_message(**kwargs):
92
+ def ha_event_availabilty_message(**kwargs):
90
93
  msg = ha_availabilty_message(device_type=INPUT, **kwargs)
91
94
  msg["icon"] = "mdi:gesture-double-tap"
95
+ msg["event_types"] = [SINGLE, DOUBLE, LONG]
92
96
  return msg
93
97
 
94
98