Skip to content

Commit

Permalink
Merge pull request #46 from boneIO-eu/dev
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
pszafer authored Sep 18, 2023
2 parents a81aac3 + 146cfa7 commit f13890b
Show file tree
Hide file tree
Showing 42 changed files with 1,820 additions and 834 deletions.
6 changes: 4 additions & 2 deletions boneio/bonecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from boneio.const import ACTION
from boneio.helper import load_config_from_file
from boneio.helper.exceptions import ConfigurationException, RestartRequestException
from boneio.helper.events import GracefulExit
from boneio.helper.logger import configure_logger
from boneio.runner import async_run
from boneio.version import __version__
Expand Down Expand Up @@ -89,8 +90,9 @@ def run(config: str, debug: int, mqttusername: str = "", mqttpassword: str = "")
),
)
return 0
except RestartRequestException as err:
_LOGGER.info(err)
except (RestartRequestException, GracefulExit) as err:
if err is not None:
_LOGGER.info(err)
return 0
except (ConfigurationException, MarkedYAMLError) as err:
_LOGGER.error("Failed to load config. %s Exiting.", err)
Expand Down
15 changes: 15 additions & 0 deletions boneio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@
# I2C, PCA and MCP CONST
ADDRESS = "address"
MCP23017 = "mcp23017"
PCF8575 = "pcf8575"
PCA9685 = "pca9685"
MCP = "mcp"
PCF = "pcf"
MCP_ID = "mcp_id"
PCA_ID = "pca_id"
PCF_ID = "pcf_id"
INIT_SLEEP = "init_sleep"
OUTPUT_GROUP = "output_group"

# SENSOR CONST
TEMPERATURE = "temperature"
EVENT_ENTITY = "event"
SENSOR = "sensor"
BINARY_SENSOR = "binary_sensor"
LM75 = "lm75"
Expand Down Expand Up @@ -140,6 +145,16 @@
Gpio_States = Literal[HIGH, LOW]
Gpio_Edges = Literal[BOTH, FALLING]
InputTypes = Literal[INPUT, INPUT_SENSOR]
ExpanderTypes = Literal[MCP23017, PCA9685, PCF8575]
DEVICE_CLASS = "device_class"
DallasBusTypes = Literal[DS2482, DALLAS]
FILTERS = "filters"

cover_actions = {
"OPEN": "open",
"CLOSE": "close",
"TOGGLE": "toggle",
"STOP": "stop",
"TOGGLE_OPEN": "toggle_open",
"TOGGLE_CLOSE": "toggle_close",
}
2 changes: 1 addition & 1 deletion boneio/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def on_exit(self) -> None:
self._stop_cover(on_exit=True)

@property
def cover_state(self) -> CLOSED | OPEN:
def cover_state(self) -> str:
"""Current state of cover."""
return CLOSED if self._closed else OPEN

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- id: adc1
pin: P9_39
pin: P9_33
- id: adc2
pin: P9_40
pin: P9_36
- id: adc3
pin: P9_37
pin: P9_35
- id: adc4
pin: P9_38
- id: adc5
pin: P9_35
pin: P9_37
- id: adc6
pin: P9_36
pin: P9_40
- id: adc7
pin: P9_33
pin: P9_39
21 changes: 21 additions & 0 deletions boneio/example_config/binary_sensor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- id: IN_47
pin: P8_12
kind: sensor
detection_type: "old"
- id: IN_48
pin: P8_11
kind: sensor
detection_type: "new"
- id: IN_49
pin: P8_10
kind: sensor

- id: IN_50
pin: P8_9
kind: sensor
- id: IN_51
pin: P8_8
kind: sensor
- id: IN_52
pin: P8_7
kind: sensor
3 changes: 2 additions & 1 deletion boneio/example_config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ mcp23017:
- id: mcp2
address: 0x21

input: !include input.yaml
event: !include event.yaml
binary_sensor: !include binary_sensor.yaml

output: !include output32x5A.yaml

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- id: IN_01
pin: P8_37
detection_type: "old"
actions:
single:
- action: output
Expand All @@ -9,6 +10,7 @@
pin: switch 1
- id: IN_02
pin: P8_38
detection_type: "new"
actions:
single:
- action: output
Expand Down Expand Up @@ -182,23 +184,3 @@
pin: P8_14
- id: IN_46
pin: P8_13

- id: IN_47
pin: P8_12
kind: sensor
- id: IN_48
pin: P8_11
kind: sensor
- id: IN_49
pin: P8_10
kind: sensor

- id: IN_50
pin: P8_9
kind: sensor
- id: IN_51
pin: P8_8
kind: sensor
- id: IN_52
pin: P8_7
kind: sensor
143 changes: 143 additions & 0 deletions boneio/example_config/output24x16A_v0.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
- id: OUT_01
kind: mcp
mcp_id: mcp1
pin: 9
output_type: light

- id: OUT_02
kind: mcp
mcp_id: mcp1
pin: 8
output_type: light

- id: OUT_03
kind: mcp
mcp_id: mcp2
pin: 1
output_type: light

- id: OUT_04
kind: mcp
mcp_id: mcp2
pin: 0
output_type: light

- id: OUT_05
kind: mcp
mcp_id: mcp1
pin: 13
output_type: light

- id: OUT_06
kind: mcp
mcp_id: mcp1
pin: 12
output_type: light

- id: OUT_07
kind: mcp
mcp_id: mcp1
pin: 11
output_type: light

- id: OUT_08
kind: mcp
mcp_id: mcp1
pin: 10
output_type: light

- id: OUT_09
kind: mcp
mcp_id: mcp2
pin: 14
output_type: light

- id: OUT_10
kind: mcp
mcp_id: mcp2
pin: 15
output_type: light

- id: OUT_11
kind: mcp
mcp_id: mcp2
pin: 13
output_type: light

- id: OUT_12
kind: mcp
mcp_id: mcp2
pin: 12
output_type: light

- id: OUT_13
kind: mcp
mcp_id: mcp1
pin: 6
output_type: light

- id: OUT_14
kind: mcp
mcp_id: mcp1
pin: 5
output_type: light

- id: OUT_15
kind: mcp
mcp_id: mcp1
pin: 4
output_type: light

- id: OUT_16
kind: mcp
mcp_id: mcp1
pin: 3
output_type: light

- id: OUT_17
kind: mcp
mcp_id: mcp1
pin: 2
output_type: light

- id: OUT_18
kind: mcp
mcp_id: mcp1
pin: 0
output_type: light

- id: OUT_19
kind: mcp
mcp_id: mcp1
pin: 1
output_type: light

- id: OUT_20
kind: mcp
mcp_id: mcp1
pin: 7
output_type: light

- id: OUT_21
kind: mcp
mcp_id: mcp2
pin: 8
output_type: light

- id: OUT_22
kind: mcp
mcp_id: mcp2
pin: 9
output_type: light

- id: OUT_23
kind: mcp
mcp_id: mcp2
pin: 11
output_type: light

- id: OUT_24
kind: mcp
mcp_id: mcp2
pin: 10
output_type: light
4 changes: 4 additions & 0 deletions boneio/group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Group classes."""
from .output import OutputGroup

__all__ = ["OutputGroup"]
64 changes: 64 additions & 0 deletions boneio/group/output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Cover module."""
from __future__ import annotations
import logging
import asyncio
from typing import List

from boneio.const import COVER, SWITCH, ON, OFF
from boneio.relay.basic import BasicRelay

_LOGGER = logging.getLogger(__name__)


class OutputGroup(BasicRelay):
"""Cover class of boneIO"""

def __init__(
self,
members: List[BasicRelay],
output_type: str = SWITCH,
restored_state: bool = True,
**kwargs,
) -> None:
"""Initialize cover class."""
self._loop = asyncio.get_event_loop()
super().__init__(
**kwargs, output_type=output_type, restored_state=restored_state, topic_type="group"
)
self._group_members = [x for x in members if x.output_type != COVER]
self._timer_handle = None
for member in self._group_members:
self._event_bus.add_output_listener(member.id, self.event_listener)

async def event_listener(self, relay_id=None) -> None:
"""Listen for events called by children relays."""
state = OFF
for x in self._group_members:
if x.state == ON:
state = ON
break
if state != self._state or not relay_id:
self._state = state
self._loop.call_soon_threadsafe(self.send_state)

def turn_on(self) -> None:
"""Call turn on action."""
for x in self._group_members:
asyncio.create_task(x.async_turn_on())

def turn_off(self) -> None:
"""Call turn off action."""
for x in self._group_members:
asyncio.create_task(x.async_turn_off())

def toggle(self) -> None:
"""Toggle group."""
_LOGGER.debug("Toggle relay.")
if self._state == ON:
self.turn_off()
else:
self.turn_on()

def send_state(self) -> None:
"""Send state to Mqtt on action."""
self._send_message(topic=self._send_topic, payload=self.payload(), retain=True)
4 changes: 2 additions & 2 deletions boneio/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ha_adc_sensor_availabilty_message,
ha_binary_sensor_availabilty_message,
ha_button_availabilty_message,
ha_input_availabilty_message,
ha_event_availabilty_message,
ha_light_availabilty_message,
ha_sensor_availabilty_message,
ha_sensor_temp_availabilty_message,
Expand Down Expand Up @@ -54,7 +54,7 @@
"ha_sensor_temp_availabilty_message",
"ha_binary_sensor_availabilty_message",
"ha_button_availabilty_message",
"ha_input_availabilty_message",
"ha_event_availabilty_message",
"ha_led_availabilty_message",
"GPIOInputException",
"GPIOOutputException",
Expand Down
2 changes: 1 addition & 1 deletion boneio/helper/async_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, manager: Manager, update_interval: TimePeriod, **kwargs):
self._update_interval = update_interval or TimePeriod(seconds=60)
self.manager.append_task(coro=self._refresh, name=self.id)

async def _refresh(self):
async def _refresh(self) -> None:
while True:
if hasattr(self, "async_update"):
update_interval = (
Expand Down
Loading

0 comments on commit f13890b

Please sign in to comment.