Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Change some conditions to be more pythonic #154

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aiy/_drivers/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def MyButtonPressHandler(channel):
my_button.on_press(MyButtonPressHandler)
"""
GPIO.remove_event_detect(self.channel)
if callback is not None:
if callback:
self.callback = callback
GPIO.add_event_detect(
self.channel, self.polarity, callback=self._debounce_and_callback)
Expand Down
2 changes: 1 addition & 1 deletion src/aiy/_drivers/_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _animate(self):
running = self.running
if not running:
return
if state is not None:
if state:
if not self._parse_state(state):
raise ValueError('unsupported state: %d' % state)
if self.iterator:
Expand Down
2 changes: 1 addition & 1 deletion src/aiy/assistant/auth_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def _try_to_get_credentials(client_secrets):


def get_assistant_credentials(credentials_file=None):
if credentials_file is None:
if not credentials_file:
credentials_file = _ASSISTANT_CREDENTIALS_FILE
return _try_to_get_credentials(credentials_file)
2 changes: 1 addition & 1 deletion src/aiy/assistant/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_assistant():
aiy.audio.play_audio(audio)
"""
global _assistant_recognizer
if _assistant_recognizer is None:
if not _assistant_recognizer:
credentials = aiy.assistant.auth_helpers.get_assistant_credentials()
_assistant_recognizer = _AssistantRecognizer(credentials)
return _assistant_recognizer
6 changes: 3 additions & 3 deletions src/aiy/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_player():
audio.
"""
global _voicehat_player
if _voicehat_player is None:
if not _voicehat_player:
_voicehat_player = aiy._drivers._player.Player()
return _voicehat_player

Expand All @@ -78,7 +78,7 @@ def get_recorder():
use this.
"""
global _voicehat_recorder
if _voicehat_recorder is None:
if not _voicehat_recorder:
_voicehat_recorder = aiy._drivers._recorder.Recorder()
return _voicehat_recorder

Expand Down Expand Up @@ -126,6 +126,6 @@ def get_status_ui():
of statuses it is able to communicate with the LED on the Voicehat.
"""
global _status_ui
if _status_ui is None:
if not _status_ui:
_status_ui = aiy._drivers._StatusUi()
return _status_ui
2 changes: 1 addition & 1 deletion src/aiy/cloudspeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ def get_recognizer():
turn_off_light()
"""
global _cloudspeech_recognizer
if _cloudspeech_recognizer is None:
if not _cloudspeech_recognizer:
_cloudspeech_recognizer = _CloudSpeechRecognizer(CLOUDSPEECH_CREDENTIALS_FILE)
return _cloudspeech_recognizer
6 changes: 3 additions & 3 deletions src/aiy/voicehat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def on_button_press(_):
# Calling wait_for_press() also cancels any callback.
"""
global _voicehat_button
if _voicehat_button is None:
if not _voicehat_button:
_voicehat_button = aiy._drivers._button.Button(channel=_GPIO_BUTTON)
return _voicehat_button

Expand All @@ -76,7 +76,7 @@ def get_led():
led.set_state(aiy.voicehat.LED_OFF)
"""
global _voicehat_led
if _voicehat_led is None:
if not _voicehat_led:
_voicehat_led = aiy._drivers._led.LED(channel=_GPIO_LED)
_voicehat_led.start()
return _voicehat_led
Expand Down Expand Up @@ -104,6 +104,6 @@ def get_status_ui():
aiy.voicehat.get_status_ui().set_state('thinking')
"""
global _status_ui
if _status_ui is None:
if not _status_ui:
_status_ui = aiy._drivers._status_ui._StatusUi()
return _status_ui
4 changes: 2 additions & 2 deletions src/assistant_grpc_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def main():
status_ui.status('listening')
print('Listening...')
text, audio = assistant.recognize()
if text is not None:
if text:
if text == 'goodbye':
status_ui.status('stopping')
print('Bye!')
break
print('You said "', text, '"')
if audio is not None:
if audio:
aiy.audio.play_audio(audio)


Expand Down
2 changes: 1 addition & 1 deletion src/cloudspeech_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main():
button.wait_for_press()
print('Listening...')
text = recognizer.recognize()
if text is None:
if not text:
print('Sorry, I did not hear you.')
else:
print('You said "', text, '"')
Expand Down