DRY button validation

This commit is contained in:
grace
2020-07-10 23:08:15 -07:00
parent 2581296c15
commit b6d20a5750
+8 -12
View File
@@ -150,11 +150,7 @@ async def set_nfc(controller_state, file_path):
async def mash_button(controller_state, button, interval): async def mash_button(controller_state, button, interval):
# waits until controller is fully connected await ensure_valid_button(controller_state, button)
await controller_state.connect()
if button not in controller_state.button_state.get_available_buttons():
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
user_input = asyncio.ensure_future( user_input = asyncio.ensure_future(
ainput(prompt=f'Pressing the {button} button every {interval} seconds... Press <enter> to stop.') ainput(prompt=f'Pressing the {button} button every {interval} seconds... Press <enter> to stop.')
@@ -169,24 +165,24 @@ async def mash_button(controller_state, button, interval):
async def hold_button(controller_state, button): async def hold_button(controller_state, button):
# waits until controller is fully connected await ensure_valid_button(controller_state, button)
await controller_state.connect()
if button not in controller_state.button_state.get_available_buttons():
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
await button_down(controller_state, button) await button_down(controller_state, button)
async def release_button(controller_state, button): async def release_button(controller_state, button):
await ensure_valid_button(controller_state, button)
await button_up(controller_state, button)
async def ensure_valid_button(controller_state, button):
# waits until controller is fully connected # waits until controller is fully connected
await controller_state.connect() await controller_state.connect()
if button not in controller_state.button_state.get_available_buttons(): if button not in controller_state.button_state.get_available_buttons():
raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}') raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}')
await button_up(controller_state, button)
async def _main(args): async def _main(args):
# parse the spi flash # parse the spi flash