From e7ea80a4acf324635415d281fa96bf744b1f2a9f Mon Sep 17 00:00:00 2001 From: Sawyer McLane Date: Sun, 19 Dec 2021 13:34:07 -0700 Subject: [PATCH] Added a bunch of try catches to critical parts of the scan to ensure startup can run correctly --- lifx_control_panel/__main__.pyw | 19 ++++++++-------- lifx_control_panel/_constants.py | 4 ++-- lifx_control_panel/build_all.spec | 2 +- .../utilities/async_bulb_interface.py | 22 +++++++++++++------ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lifx_control_panel/__main__.pyw b/lifx_control_panel/__main__.pyw index 49f242b..8f85eca 100644 --- a/lifx_control_panel/__main__.pyw +++ b/lifx_control_panel/__main__.pyw @@ -17,7 +17,7 @@ import traceback from collections import OrderedDict from logging.handlers import RotatingFileHandler from tkinter import messagebox, ttk -from typing import List, Dict, Union +from typing import List, Dict, Union, Optional import lifxlan import pystray @@ -52,8 +52,8 @@ class LifxFrame(ttk.Frame): # pylint: disable=too-many-ancestors bulb_interface: AsyncBulbInterface current_lightframe: LightFrame - def __init__(self, master, lifx_instance: lifxlan.LifxLAN, bulb_interface: AsyncBulbInterface): - # We take a lifx instance so we can inject our own for testing. + def __init__(self, master: tkinter.Tk, lifx_instance: lifxlan.LifxLAN, bulb_interface: AsyncBulbInterface): + # We take a lifx instance, so we can inject our own for testing. # Start showing splash_screen while processing self.splashscreen = Splash(master, SPLASHFILE) @@ -61,18 +61,19 @@ class LifxFrame(ttk.Frame): # pylint: disable=too-many-ancestors # Setup frame and grid ttk.Frame.__init__(self, master, padding="3 3 12 12") - self.master = master + self.master: tkinter.Tk = master self.master.protocol("WM_DELETE_WINDOW", self.on_closing) self.grid(column=0, row=0, sticky=(tkinter.N, tkinter.W, tkinter.E, tkinter.S)) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.lifx: lifxlan.LifxLAN = lifx_instance - self.bulb_interface = bulb_interface + self.bulb_interface: AsyncBulbInterface = bulb_interface self.audio_interface = audio.AudioInterface() self.audio_interface.init_audio(config) # Setup logger - self.logger = logging.getLogger(master.logger.name + '.' + self.__class__.__name__) + master_logger: str = master.logger.name if hasattr(master, 'logger') else "root" + self.logger = logging.getLogger(master_logger + '.' + self.__class__.__name__) self.logger.info('Root logger initialized: %s', self.logger.name) self.logger.info('Binary Version: %s', VERSION) self.logger.info('Build time: %s', BUILD_DATE) @@ -92,8 +93,8 @@ class LifxFrame(ttk.Frame): # pylint: disable=too-many-ancestors self.lightvar = tkinter.StringVar(self) self.lightsdict: Dict[str, lifxlan.Light] = OrderedDict() # LifxLight objects self.framesdict: Dict[str, LightFrame] = {} # corresponding LightFrame GUI - self.current_lightframe: LightFrame # currently selected and visible LightFrame - self.current_light: lifxlan.Light + self.current_lightframe: Optional[LightFrame] = None # currently selected and visible LightFrame + self.current_light: Optional[lifxlan.Light] self.bulb_icons = BulbIconList(self) self.group_icons = BulbIconList(self, is_group=True) @@ -160,7 +161,7 @@ class LifxFrame(ttk.Frame): # pylint: disable=too-many-ancestors """ Communicating with the interface Thread, attempt to find any new devices """ # Stop and restart the bulb interface stop_event: threading.Event = self.bulb_interface.stopped - if not stop_event.isSet(): + if not stop_event.is_set(): stop_event.set() device_list: List[Union[lifxlan.Group, lifxlan.Light, lifxlan.MultiZoneLight]] = self.lifx.get_devices() if self.bulb_interface: diff --git a/lifx_control_panel/_constants.py b/lifx_control_panel/_constants.py index 0f2afcc..66ef100 100644 --- a/lifx_control_panel/_constants.py +++ b/lifx_control_panel/_constants.py @@ -1,4 +1,4 @@ -VERSION = "2.1.2" -BUILD_DATE = "2021-12-14T11:43:33.756405" +VERSION = "2.2.0" +BUILD_DATE = "2021-12-19T13:28:42.468338" AUTHOR = "Sawyer McLane" DEBUGGING = False diff --git a/lifx_control_panel/build_all.spec b/lifx_control_panel/build_all.spec index 34c5ffd..413beba 100644 --- a/lifx_control_panel/build_all.spec +++ b/lifx_control_panel/build_all.spec @@ -3,7 +3,7 @@ import datetime bd = datetime.datetime.now().isoformat() auth = "Sawyer McLane" -vers = "2.1.2" +vers = "2.2.0" is_debug = False # Write version info into _constants.py resource file diff --git a/lifx_control_panel/utilities/async_bulb_interface.py b/lifx_control_panel/utilities/async_bulb_interface.py index d685a71..5b72fd2 100644 --- a/lifx_control_panel/utilities/async_bulb_interface.py +++ b/lifx_control_panel/utilities/async_bulb_interface.py @@ -27,21 +27,29 @@ def __init__(self, event, heartbeat_ms): self.logger = logging.getLogger("root") def set_device_list( - self, - device_list: List[Union[lifxlan.Group, lifxlan.Light, lifxlan.MultiZoneLight]], + self, device_list: List[lifxlan.Device], ): """ Set internet device list to passed list of LIFX devices. """ for dev in device_list: try: label = dev.get_label() self.color_queue[label] = queue.Queue() - color = ( - dev.get_color_zones()[0] if dev.supports_multizone() else dev.color - ) + try: + if dev.supports_multizone(): + dev: lifxlan.MultiZoneLight + color = dev.get_color_zones()[0] + else: + color = getattr(dev, "color", None) + except Exception as e: + self.logger.error(e) + color = None self.color_cache[dev.label] = color self.power_queue[dev.label] = queue.Queue() - self.power_cache[dev.label] = dev.power_level or dev.get_power() - + try: + self.power_cache[dev.label] = dev.power_level or dev.get_power() + except Exception as e: + self.logger.error(e) + self.power_cache[dev.label] = 0 self.device_list.append(dev) except lifxlan.WorkflowException as exc: self.logger.warning(