Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.3 to main #49

Merged
merged 30 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3cc1db6
fix adc config
pszafer Sep 23, 2023
697ceac
add mqtt state to main screen
pszafer Sep 26, 2023
94f43b9
add INA219 support
pszafer Sep 27, 2023
6818154
strip accents in mqtt topic
pszafer Oct 3, 2023
6f99302
shorten outputs name in oled
pszafer Oct 3, 2023
b4226e9
remove restoring state for output group
pszafer Oct 3, 2023
a565276
fix momentary actions handling
pszafer Oct 3, 2023
eaab233
add INA219 support
pszafer Oct 3, 2023
83203dc
nicer python read register methods
pszafer Oct 12, 2023
68e89b1
add INA219 support
pszafer Oct 20, 2023
83e6748
cancel momentary action on change state
pszafer Oct 20, 2023
d68ceb9
add ina219 to oled
pszafer Oct 20, 2023
de9cd66
fix boneio restart by systemd
pszafer Oct 20, 2023
fff085e
modbus clean up
pszafer Oct 20, 2023
9e9427c
Update install_script.py
dziobson Nov 23, 2023
549e8b6
Merge pull request #48 from dziobson/patch-3
pszafer Nov 23, 2023
fba6c77
add delay property to click timer
pszafer Dec 3, 2023
44a8e53
new asyncio calling part1
pszafer Dec 3, 2023
12af2ad
change bounce time to be stored in seconds from the beginning
pszafer Dec 3, 2023
687ba53
fix group switches toggling
pszafer Dec 3, 2023
5d38359
change how actions are triggered
pszafer Dec 3, 2023
e3c15b9
add create_unawaited_task_threadsafe
pszafer Dec 3, 2023
66642d6
add async_turn on/off and fix callback of relays
pszafer Dec 3, 2023
641ecd9
redesign new gpio event button
pszafer Dec 3, 2023
669581e
dump json in executor for faster response
pszafer Dec 3, 2023
f29b363
new async actions in const
pszafer Dec 3, 2023
adc661a
make press_callback and receive_message async
pszafer Dec 3, 2023
fb7d88c
add event_all example
pszafer Dec 3, 2023
b12f3f5
v0.8.0 prepare
pszafer Dec 3, 2023
706e5db
new config to install_script
pszafer Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boneio/bonecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def main() -> int:
mqttpassword=args.mqttpassword,
debug=debug,
)

_LOGGER.info("Exiting with exit code %s", exit_code)
return exit_code


Expand Down
4 changes: 3 additions & 1 deletion boneio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"uart5": {ID: "/dev/ttyS5", TX: "P8.37", RX: "P8.38"},
}

relay_actions = {ON: "turn_on", OFF: "turn_off", TOGGLE: "toggle"}
relay_actions = {ON: "async_turn_on", OFF: "async_turn_off", TOGGLE: "async_toggle"}

# HA CONSTS
HOMEASSISTANT = "homeassistant"
Expand Down Expand Up @@ -158,3 +158,5 @@
"TOGGLE_OPEN": "toggle_open",
"TOGGLE_CLOSE": "toggle_close",
}

INA219 = "ina219"
File renamed without changes.
2 changes: 1 addition & 1 deletion boneio/example_config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ binary_sensor: !include binary_sensor.yaml

output: !include output32x5A.yaml

adc: !include adc.yaml
# adc: !include adc.yaml Uncomment only if needed.
186 changes: 186 additions & 0 deletions boneio/example_config/event_all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
- id: IN_01
pin: P8_37
detection_type: "old"
actions:
single:
- action: output
pin: light 1
double:
- action: output
pin: switch 1
- id: IN_02
pin: P8_38
detection_type: "new"
actions:
single:
- action: output
pin: light 2
double:
- action: output
pin: switch 2
- id: IN_03
pin: P8_39
actions:
single:
- action: output
pin: light 3
double:
- action: output
pin: switch 3
- id: IN_04
pin: P8_40
actions:
single:
- action: output
pin: light 4
double:
- action: output
pin: switch 4
- id: IN_05
pin: P8_41
actions:
single:
- action: output
pin: light 5
double:
- action: output
pin: switch 5
- id: IN_06
pin: P8_42
actions:
single:
- action: output
pin: light 6
double:
- action: output
pin: switch 6
- id: IN_07
pin: P8_43
actions:
single:
- action: output
pin: light 7

- id: IN_08
pin: P8_44
actions:
single:
- action: output
pin: light 8
- id: IN_09
pin: P8_45
actions:
single:
- action: output
pin: light 9
- id: IN_10
pin: P8_46
actions:
single:
- action: output
pin: light 10
- id: IN_11
pin: P9_42
actions:
single:
- action: output
pin: light 11
- id: IN_12
pin: P9_31
actions:
single:
- action: output
pin: light 12
- id: IN_13
pin: P9_30
actions:
single:
- action: output
pin: light 13
- id: IN_14
pin: P9_29
actions:
single:
- action: output
pin: light 14

- id: IN_15
pin: P9_28
actions:
single:
- action: output
pin: light 15
- id: IN_16
pin: P9_27
actions:
single:
- action: output
pin: light 16
- id: IN_17
pin: P9_25
actions:
single:
- action: output
pin: light 4
- id: IN_18
pin: P9_23
- id: IN_19
pin: P9_22
- id: IN_20
pin: P9_21
- id: IN_21
pin: P9_18

- id: IN_22
pin: P9_17
- id: IN_23
pin: P9_16
- id: IN_24
pin: P9_15
- id: IN_25
pin: P9_14
- id: IN_26
pin: P9_13
- id: IN_27
pin: P9_12
- id: IN_28
pin: P9_11

- id: IN_29
pin: P8_36
- id: IN_30
pin: P8_35
- id: IN_31
pin: P8_34
- id: IN_32
pin: P8_33

- id: IN_33
pin: P8_32
- id: IN_34
pin: P8_31
- id: IN_35
pin: P8_30
- id: IN_36
pin: P8_29
- id: IN_37
pin: P8_28
- id: IN_38
pin: P8_27
- id: IN_39
pin: P8_26

- id: IN_40
pin: P8_19
- id: IN_41
pin: P8_18
- id: IN_42
pin: P8_17
- id: IN_43
pin: P8_16
- id: IN_44
pin: P8_15
- id: IN_45
pin: P8_14
- id: IN_46
pin: P8_13
31 changes: 13 additions & 18 deletions boneio/group/output.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
"""Cover module."""
"""Group output 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"""
Expand Down Expand Up @@ -41,23 +37,22 @@ async def event_listener(self, relay_id=None) -> None:
self._state = state
self._loop.call_soon_threadsafe(self.send_state)

def turn_on(self) -> None:
async def async_turn_on(self) -> None:
"""Call turn on action."""
for x in self._group_members:
asyncio.create_task(x.async_turn_on())
await asyncio.gather(
*[self._loop.run_in_executor(self.executor, x.turn_on) for x in self._group_members]
)

def turn_off(self) -> None:
async def async_turn_off(self) -> None:
"""Call turn off action."""
for x in self._group_members:
asyncio.create_task(x.async_turn_off())
await asyncio.gather(
*[self._loop.run_in_executor(self.executor, x.turn_off) for x in self._group_members]
)

def toggle(self) -> None:
"""Toggle group."""
_LOGGER.debug("Toggle relay.")
if self._state == ON:
self.turn_off()
else:
self.turn_on()
@property
def is_active(self) -> bool:
"""Is relay active."""
return self._state == ON

def send_state(self) -> None:
"""Send state to Mqtt on action."""
Expand Down
2 changes: 2 additions & 0 deletions boneio/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ha_sensor_temp_availabilty_message,
ha_switch_availabilty_message,
ha_led_availabilty_message,
ha_sensor_ina_availabilty_message
)
from boneio.helper.mqtt import BasicMqtt
from boneio.helper.async_updater import AsyncUpdater
Expand Down Expand Up @@ -54,6 +55,7 @@
"ha_sensor_temp_availabilty_message",
"ha_binary_sensor_availabilty_message",
"ha_button_availabilty_message",
"ha_sensor_ina_availabilty_message",
"ha_event_availabilty_message",
"ha_led_availabilty_message",
"GPIOInputException",
Expand Down
6 changes: 3 additions & 3 deletions boneio/helper/async_updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
import asyncio

import time
# Typing imports that create a circular dependency
from typing import TYPE_CHECKING

Expand All @@ -19,11 +19,11 @@ async def _refresh(self) -> None:
while True:
if hasattr(self, "async_update"):
update_interval = (
await self.async_update(time=None)
await self.async_update(time=time.time())
or self._update_interval.total_in_seconds
)
else:
update_interval = (
self.update(time=None) or self._update_interval.total_in_seconds
self.update(time=time.time()) or self._update_interval.total_in_seconds
)
await asyncio.sleep(update_interval)
8 changes: 8 additions & 0 deletions boneio/helper/click_timer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations
import logging
import asyncio
from boneio.helper.timeperiod import TimePeriod
import time

_LOGGER = logging.getLogger(__name__)


class ClickTimer:
"""Represent async call later function with variable to check if timing is ON."""

Expand All @@ -16,6 +20,10 @@ def __init__(self, delay: TimePeriod, action) -> None:
def is_waiting(self) -> bool:
"""If variable is set then timer is ON, if None is Off."""
return self._remove_listener is not None

@property
def delay(self) -> float:
return self._delay

def reset(self) -> None:
"""Uninitialize variable remove_listener."""
Expand Down
22 changes: 21 additions & 1 deletion boneio/helper/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import signal
import time
from datetime import datetime
from typing import Callable, Optional
from typing import Any, Coroutine, List, Optional, Callable, Optional


from boneio.helper.util import callback

Expand Down Expand Up @@ -261,3 +262,22 @@ def async_call_later_miliseconds(
return async_track_point_in_timestamp(
loop=loop, action=action, timestamp=expected_fire_timestamp
)


def create_unawaited_task_threadsafe(
loop: asyncio.AbstractEventLoop,
transient_tasks: List["asyncio.Task[Any]"],
coro: Coroutine[Any, Any, None],
task_future: Optional["asyncio.Future[asyncio.Task[Any]]"] = None,
) -> None:
"""
Schedule a coroutine on the loop and add the Task to transient_tasks.
"""

def callback() -> None:
task = loop.create_task(coro)
transient_tasks.append(task)
if task_future is not None:
task_future.set_result(task)

loop.call_soon_threadsafe(callback)
Loading
Loading