Skip to content

Commit 6b388ea

Browse files
committed
bug #397: mypy
1 parent 5576417 commit 6b388ea

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/reachy_mini/daemon/app/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ def run_app(args: Args) -> None:
161161
from reachy_mini.media.audio_control_utils import init_respeaker_usb
162162

163163
respeaker = init_respeaker_usb()
164-
respeaker.write("REBOOT", [1])
165-
respeaker.close()
166-
logging.debug("Respeaker rebooted.")
164+
if respeaker is None:
165+
logging.error("Respeaker device not found. Cannot apply audio fix.")
166+
else:
167+
respeaker.write("REBOOT", [1])
168+
respeaker.close()
169+
logging.debug("Respeaker rebooted.")
167170

168171
health_check_event = asyncio.Event()
169172
app = create_app(args, health_check_event)

src/reachy_mini/media/audio_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, log_level: str = "INFO") -> None:
2323
"""Initialize the audio device."""
2424
self.logger = logging.getLogger(__name__)
2525
self.logger.setLevel(log_level)
26-
self._respeaker: ReSpeaker = init_respeaker_usb()
26+
self._respeaker: Optional[ReSpeaker] = init_respeaker_usb()
2727

2828
def __del__(self) -> None:
2929
"""Destructor to ensure resources are released."""

src/reachy_mini/media/audio_sounddevice.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def __init__(
3030
self.stream = None
3131
self._output_stream = None
3232
self._buffer: List[npt.NDArray[np.float32]] = []
33-
self._output_device_id = self.get_device_id(
33+
self._output_device_id = self._get_device_id(
3434
["Reachy Mini Audio", "respeaker"], device_io_type="output"
3535
)
36-
self._input_device_id = self.get_device_id(
36+
self._input_device_id = self._get_device_id(
3737
["Reachy Mini Audio", "respeaker"], device_io_type="input"
3838
)
3939

@@ -185,12 +185,17 @@ def _clean_up_thread() -> None:
185185
daemon=True,
186186
).start()
187187

188-
def get_device_id(
188+
def _get_device_id(
189189
self, names_contains: List[str], device_io_type: str = "output"
190190
) -> int:
191-
"""Return the output device id whose name contains the given string (case-insensitive).
191+
"""Return the output device id whose name contains the given strings (case-insensitive).
192+
193+
Args:
194+
names_contains (List[str]): List of strings that should be contained in the device name.
195+
device_io_type (str): 'input' or 'output' to specify device type.
192196
193197
If not found, return the default output device id.
198+
194199
"""
195200
devices = sd.query_devices()
196201

0 commit comments

Comments
 (0)