Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made device scanning more fault tolerant #129

Merged
merged 1 commit into from
Dec 19, 2021
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
19 changes: 10 additions & 9 deletions lifx_control_panel/__main__.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,27 +52,28 @@ 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)
self.splashscreen.__enter__()

# 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)
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lifx_control_panel/_constants.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lifx_control_panel/build_all.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions lifx_control_panel/utilities/async_bulb_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down