From b370ec5b7e5688709f374e33e08675bf3c590bce Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Wed, 14 Aug 2024 22:20:45 -0400 Subject: [PATCH] str fallback --- pioreactor/background_jobs/monitor.py | 10 +++------- pioreactor/background_jobs/od_reading.py | 2 +- pioreactor/utils/networking.py | 5 ++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pioreactor/background_jobs/monitor.py b/pioreactor/background_jobs/monitor.py index 002902a4..7ba43427 100644 --- a/pioreactor/background_jobs/monitor.py +++ b/pioreactor/background_jobs/monitor.py @@ -235,7 +235,7 @@ def check_for_network(self) -> None: def did_find_network() -> bool: ipv4 = get_ip() - if ipv4 == "127.0.0.1" or ipv4 is None: + if ipv4 == "127.0.0.1" or ipv4 == "": # no connection? Sound the alarm. self.logger.warning("Unable to find a network...") self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION) @@ -243,12 +243,8 @@ def did_find_network() -> bool: else: return True - if utils.boolean_retry(did_find_network, retries=3, sleep_for=2): - ipv4: str = get_ip() or "" - else: - ipv4 = "" - - self.ipv4 = ipv4 + utils.boolean_retry(did_find_network, retries=3, sleep_for=2) + self.ipv4 = get_ip() try: with open("/sys/class/net/wlan0/address", "r") as f: diff --git a/pioreactor/background_jobs/od_reading.py b/pioreactor/background_jobs/od_reading.py index 896c45a7..252d4c5d 100644 --- a/pioreactor/background_jobs/od_reading.py +++ b/pioreactor/background_jobs/od_reading.py @@ -1018,7 +1018,7 @@ def add_post_read_callback(cls, function: Callable): @property def ir_led_on_and_rest_off_state(self) -> dict[pt.LedChannel, pt.LedIntensityValue]: - if config.getboolean("od_reading.config", "turn_off_leds_during_reading", fallback=True): + if config.getboolean("od_reading.config", "turn_off_leds_during_reading", fallback="True"): return { channel: (self.ir_led_intensity if channel == self.ir_channel else 0.0) for channel in led_utils.ALL_LED_CHANNELS diff --git a/pioreactor/utils/networking.py b/pioreactor/utils/networking.py index 72d1fbcc..f034482b 100644 --- a/pioreactor/utils/networking.py +++ b/pioreactor/utils/networking.py @@ -7,7 +7,6 @@ from queue import Queue from threading import Thread from typing import Generator -from typing import Optional def cp_file_across_cluster(unit: str, localpath: str, remotepath: str, timeout: int = 5) -> None: @@ -64,14 +63,14 @@ def is_reachable(address: str) -> bool: return False -def get_ip() -> Optional[str]: +def get_ip() -> str: # returns all ipv4s as comma-separated string result = subprocess.run(["hostname", "-I"], stdout=subprocess.PIPE, text=True) ipv4_addresses = result.stdout.strip().split() if ipv4_addresses: return ",".join(ipv4_addresses) else: - return None + return "" def discover_workers_on_network(terminate: bool = False) -> Generator[str, None, None]: