Skip to content

Commit

Permalink
Update validator to be more generic
Browse files Browse the repository at this point in the history
Fix syntax error in pin setup
  • Loading branch information
NeonDaniel committed Mar 29, 2024
1 parent 305cd22 commit 2ae8498
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions neon_phal_plugin_switches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ae8498

Please sign in to comment.