From 2ae849803ffe1411f64e63f0679f07e8aca8b0ab Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 29 Mar 2024 16:31:22 -0700 Subject: [PATCH] Update validator to be more generic Fix syntax error in pin setup --- neon_phal_plugin_switches/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/neon_phal_plugin_switches/__init__.py b/neon_phal_plugin_switches/__init__.py index 3601d61..e5a729b 100644 --- a/neon_phal_plugin_switches/__init__.py +++ b/neon_phal_plugin_switches/__init__.py @@ -33,15 +33,16 @@ from ovos_plugin_manager.hardware.switches import AbstractSwitches from ovos_utils.log import LOG from ovos_bus_client.message import Message -from gpiozero import Button, pi_info, BadPinFactory, Device +from gpiozero import Button, Device from gpiozero.pins.native import NativeFactory +from gpiozero.exc import BadPinFactory class SwitchValidator: @staticmethod def validate(_=None): try: - pi_info() + Device.ensure_pin_factory() return True except BadPinFactory: return False @@ -145,20 +146,20 @@ def setup_gpio(self, active_state: bool = True): Do GPIO setup. @param active_state: If true, switches are active when high """ - + factory = NativeFactory() act = Button(self.action_pin, pull_up=None, active_state=active_state, - pin_factory=NativeFactory) + pin_factory=factory) act.when_activated = self.on_action vol_up = Button(self.vol_up_pin, pull_up=None, - active_state=active_state, pin_factory=NativeFactory) + active_state=active_state, pin_factory=factory) vol_up.when_activated = self.on_vol_up vol_down = Button(self.vol_dn_pin, pull_up=None, - active_state=active_state, pin_factory=NativeFactory) + active_state=active_state, pin_factory=factory) vol_down.when_activated = self.on_vol_down self.mute_switch = Button(self.mute_pin, pull_up=None, active_state=bool(self._muted), - pin_factory=NativeFactory) + pin_factory=factory) self.mute_switch.when_deactivated = self.on_unmute self.mute_switch.when_activated = self.on_mute