diff --git a/boneio/example_config/binary_sensor.yaml b/boneio/example_config/binary_sensor.yaml index 12c901a..c4ec64c 100644 --- a/boneio/example_config/binary_sensor.yaml +++ b/boneio/example_config/binary_sensor.yaml @@ -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 diff --git a/boneio/example_config/event.yaml b/boneio/example_config/event.yaml index cc272cd..117c2d8 100644 --- a/boneio/example_config/event.yaml +++ b/boneio/example_config/event.yaml @@ -1,5 +1,6 @@ - id: IN_01 pin: P8_37 + detection_type: "old" actions: single: - action: output @@ -9,6 +10,7 @@ pin: switch 1 - id: IN_02 pin: P8_38 + detection_type: "new" actions: single: - action: output diff --git a/boneio/helper/loader.py b/boneio/helper/loader.py index 9924b30..efcf803 100644 --- a/boneio/helper/loader.py +++ b/boneio/helper/loader.py @@ -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 @@ -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) @@ -258,7 +258,8 @@ def configure_output_group( restored_state=restored_state, callback=lambda: None, **config, - **kwargs) + **kwargs, + ) return output @@ -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) @@ -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, @@ -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, diff --git a/boneio/input/__init__.py b/boneio/input/__init__.py index 89d7312..2dc030c 100644 --- a/boneio/input/__init__.py +++ b/boneio/input/__init__.py @@ -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"] diff --git a/boneio/input/gpio_beta.py b/boneio/input/gpio_new.py similarity index 94% rename from boneio/input/gpio_beta.py rename to boneio/input/gpio_new.py index 3b0ac47..d7ca746 100644 --- a/boneio/input/gpio_beta.py +++ b/boneio/input/gpio_new.py @@ -1,4 +1,4 @@ -"""GpioEventButtonBeta to receive signals.""" +"""GpioEventButtonNew to receive signals.""" from __future__ import annotations import time import logging @@ -20,7 +20,7 @@ LONG_PRESS_DURATION_MS = 600 -class GpioEventButtonBeta(GpioBaseClass): +class GpioEventButtonNew(GpioBaseClass): """Represent Gpio input switch.""" def __init__(self, **kwargs) -> None: @@ -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 diff --git a/boneio/schema/schema.yaml b/boneio/schema/schema.yaml index 43bafa3..71757d4 100644 --- a/boneio/schema/schema.yaml +++ b/boneio/schema/schema.yaml @@ -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 @@ -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 diff --git a/boneio/sensor/__init__.py b/boneio/sensor/__init__.py index d7e6606..d5136ce 100644 --- a/boneio/sensor/__init__.py +++ b/boneio/sensor/__init__.py @@ -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 @@ -10,8 +10,8 @@ "DallasSensorDS2482", "LM75Sensor", "MCP9808Sensor", - "GpioInputBinarySensor", - "GpioInputBinarySensorBeta", + "GpioInputBinarySensorOld", + "GpioInputBinarySensorNew", "initialize_adc", "GpioADCSensor", ] diff --git a/boneio/sensor/gpio_beta.py b/boneio/sensor/gpio_new.py similarity index 92% rename from boneio/sensor/gpio_beta.py rename to boneio/sensor/gpio_new.py index ee0adfc..6b48655 100644 --- a/boneio/sensor/gpio_beta.py +++ b/boneio/sensor/gpio_new.py @@ -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 @@ -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: