Skip to content

Commit

Permalink
rename stable/beta to old/new sensor algorthims
Browse files Browse the repository at this point in the history
  • Loading branch information
pszafer committed Sep 18, 2023
1 parent a35a023 commit 69272a5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 72 deletions.
2 changes: 2 additions & 0 deletions boneio/example_config/binary_sensor.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
- 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
Expand Down
2 changes: 2 additions & 0 deletions boneio/example_config/event.yaml
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
97 changes: 43 additions & 54 deletions boneio/helper/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
from boneio.helper.ha_discovery import ha_cover_availabilty_message
from boneio.helper.timeperiod import TimePeriod
from boneio.helper.pcf8575 import PCF8575
from boneio.input import GpioEventButton, GpioEventButtonBeta
from boneio.input import GpioEventButtonOld, GpioEventButtonNew
from boneio.sensor import (
DallasSensorDS2482,
GpioInputBinarySensor,
GpioInputBinarySensorBeta,
GpioInputBinarySensorOld,
GpioInputBinarySensorNew,
)
from boneio.sensor.temp.dallas import DallasSensorW1

Expand Down Expand Up @@ -240,7 +240,7 @@ def configure_output_group(
topic_prefix: str,
relay_id: str,
config: dict,
**kwargs
**kwargs,
) -> Any:
"""Configure kind of relay. Most common MCP."""
restore_state = config.pop(RESTORE_STATE, False)
Expand All @@ -258,7 +258,8 @@ def configure_output_group(
restored_state=restored_state,
callback=lambda: None,
**config,
**kwargs)
**kwargs,
)
return output


Expand All @@ -269,7 +270,7 @@ def configure_relay(
relay_id: str,
relay_callback: Callable,
config: dict,
**kwargs
**kwargs,
) -> Any:
"""Configure kind of relay. Most common MCP."""
restore_state = config.pop(RESTORE_STATE, False)
Expand Down Expand Up @@ -348,52 +349,36 @@ def configure_relay(
return relay


InputEntry = namedtuple(
"InputEntry", "InputClass input_type ha_type availability_msg_f"
)


def input_chooser(input_type: str):
"""Get named tuple based on input."""
if input_type == SENSOR:
return InputEntry(
GpioInputBinarySensor,
INPUT_SENSOR,
BINARY_SENSOR,
ha_binary_sensor_availabilty_message,
)
else:
return InputEntry(
GpioEventButton, INPUT, EVENT_ENTITY, ha_event_availabilty_message
)


def configure_event_sensor(
gpio: dict,
pin: str,
press_callback: Callable,
send_ha_autodiscovery: Callable,
input: GpioEventButton | GpioEventButtonBeta | None = None
) -> GpioEventButton | GpioEventButtonBeta | None:
input: GpioEventButtonOld | GpioEventButtonNew | None = None,
) -> GpioEventButtonOld | GpioEventButtonNew | None:
"""Configure input sensor or button."""
try:
GpioEventButtonClass = (
GpioEventButton
if gpio.get("detection_type", "stable") == "stable"
else GpioEventButtonBeta
GpioEventButtonNew
if gpio.get("detection_type", "new") == "new"
else GpioEventButtonOld
)
if input:
if not isinstance(input, GpioEventButtonClass):
_LOGGER.warn("You preconfigured type of input. It's forbidden. Please restart boneIO.")
_LOGGER.warn(
"You preconfigured type of input. It's forbidden. Please restart boneIO."
)
return input
input.set_press_callback(press_callback=lambda x, i, z: press_callback(
x=x,
inpin=i,
actions=gpio.get(ACTIONS, {}).get(x, []),
input_type=INPUT,
empty_message_after=gpio.get("clear_message", False),
duration=z,
))
input.set_press_callback(
press_callback=lambda x, i, z: press_callback(
x=x,
inpin=i,
actions=gpio.get(ACTIONS, {}).get(x, []),
input_type=INPUT,
empty_message_after=gpio.get("clear_message", False),
duration=z,
)
)
else:
input = GpioEventButtonClass(
pin=pin,
Expand Down Expand Up @@ -426,27 +411,31 @@ def configure_binary_sensor(
pin: str,
press_callback: Callable,
send_ha_autodiscovery: Callable,
input: GpioInputBinarySensor | GpioInputBinarySensorBeta | None = None
) -> GpioInputBinarySensor | GpioInputBinarySensorBeta | None:
input: GpioInputBinarySensorOld | GpioInputBinarySensorNew | None = None,
) -> GpioInputBinarySensorOld | GpioInputBinarySensorNew | None:
"""Configure input sensor or button."""
try:
GpioInputBinarySensorClass = (
GpioInputBinarySensor
if gpio.get("detection_type", "stable") == "stable"
else GpioInputBinarySensorBeta
GpioInputBinarySensorNew
if gpio.get("detection_type", "new") == "new"
else GpioInputBinarySensorOld
)
if input:
if not isinstance(input, GpioInputBinarySensorClass):
_LOGGER.warn("You preconfigured type of input. It's forbidden. Please restart boneIO.")
_LOGGER.warn(
"You preconfigured type of input. It's forbidden. Please restart boneIO."
)
return input
input.set_press_callback(press_callback=lambda x, i, z: press_callback(
x=x,
inpin=i,
actions=gpio.get(ACTIONS, {}).get(x, []),
input_type=INPUT,
empty_message_after=gpio.get("clear_message", False),
duration=z,
))
input.set_press_callback(
press_callback=lambda x, i, z: press_callback(
x=x,
inpin=i,
actions=gpio.get(ACTIONS, {}).get(x, []),
input_type=INPUT,
empty_message_after=gpio.get("clear_message", False),
duration=z,
)
)
else:
input = GpioInputBinarySensorClass(
pin=pin,
Expand Down
6 changes: 3 additions & 3 deletions boneio/input/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Input classes."""

from boneio.input.gpio import GpioEventButton
from boneio.input.gpio_beta import GpioEventButtonBeta
from boneio.input.gpio import GpioEventButton as GpioEventButtonOld
from boneio.input.gpio_new import GpioEventButtonNew


__all__ = ["GpioEventButton", "GpioEventButtonBeta"]
__all__ = ["GpioEventButtonOld", "GpioEventButtonNew"]
6 changes: 3 additions & 3 deletions boneio/input/gpio_beta.py → boneio/input/gpio_new.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""GpioEventButtonBeta to receive signals."""
"""GpioEventButtonNew to receive signals."""
from __future__ import annotations
import time
import logging
Expand All @@ -20,7 +20,7 @@
LONG_PRESS_DURATION_MS = 600


class GpioEventButtonBeta(GpioBaseClass):
class GpioEventButtonNew(GpioBaseClass):
"""Represent Gpio input switch."""

def __init__(self, **kwargs) -> None:
Expand All @@ -47,7 +47,7 @@ def __init__(self, **kwargs) -> None:

add_event_detect(pin=self._pin, edge=BOTH)
add_event_callback(pin=self._pin, callback=self.check_state)
_LOGGER.debug("Configured BETA listening for input pin %s", self._pin)
_LOGGER.debug("Configured NEW listening for input pin %s", self._pin)

def double_click_press_callback(self):
self._is_waiting_for_second_click = False
Expand Down
12 changes: 6 additions & 6 deletions boneio/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ binary_sensor:
detection_type:
type: string
required: True
default: "stable"
allowed: ["stable", "beta"]
default: "new"
allowed: ["new", "old"]
meta:
label: There are 2 detector algorithms. Stable consumes more CPU. Beta is more optimized, but needed extra time for testing.
label: There are 2 detector algorithms. Old consumes more CPU but it is tested by many users. New is more optimized, but needed extra time for testing.
clear_message:
type: boolean
default: False
Expand Down Expand Up @@ -484,10 +484,10 @@ event:
detection_type:
type: string
required: True
default: "stable"
allowed: ["stable", "beta"]
default: "new"
allowed: ["new", "old"]
meta:
label: There are 2 detector algorithms. Stable consumes more CPU. Beta is more optimized, but needed extra time for testing.
label: There are 2 detector algorithms. Old consumes more CPU but it is tested by many users. New is more optimized, but needed extra time for testing.
clear_message:
type: boolean
default: False
Expand Down
8 changes: 4 additions & 4 deletions boneio/sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Sensor module."""
from boneio.sensor.adc import GpioADCSensor, initialize_adc
from boneio.sensor.gpio import GpioInputBinarySensor
from boneio.sensor.gpio_beta import GpioInputBinarySensorBeta
from boneio.sensor.gpio import GpioInputBinarySensor as GpioInputBinarySensorOld
from boneio.sensor.gpio_new import GpioInputBinarySensorNew
from boneio.sensor.temp.dallas import DallasSensorDS2482
from boneio.sensor.temp.lm75 import LM75Sensor
from boneio.sensor.temp.mcp9808 import MCP9808Sensor
Expand All @@ -10,8 +10,8 @@
"DallasSensorDS2482",
"LM75Sensor",
"MCP9808Sensor",
"GpioInputBinarySensor",
"GpioInputBinarySensorBeta",
"GpioInputBinarySensorOld",
"GpioInputBinarySensorNew",
"initialize_adc",
"GpioADCSensor",
]
4 changes: 2 additions & 2 deletions boneio/sensor/gpio_beta.py → boneio/sensor/gpio_new.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""GpioInputBinarySensor to receive signals."""
"""GpioInputBinarySensorNew to receive signals."""
import logging
from functools import partial
from boneio.const import PRESSED, RELEASED, BOTH
Expand All @@ -8,7 +8,7 @@
_LOGGER = logging.getLogger(__name__)


class GpioInputBinarySensorBeta(GpioBaseClass):
class GpioInputBinarySensorNew(GpioBaseClass):
"""Represent Gpio sensor on input boards."""

def __init__(self, **kwargs) -> None:
Expand Down

0 comments on commit 69272a5

Please sign in to comment.