From d50660116f996f0fc2334a082810702af685cb88 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Sun, 28 Dec 2025 21:01:02 -0500 Subject: [PATCH] fix rejected pin value of -1 from init --- appdaemon/app_management.py | 9 ++++----- appdaemon/callbacks.py | 2 +- appdaemon/scheduler.py | 2 +- appdaemon/threads.py | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/appdaemon/app_management.py b/appdaemon/app_management.py index fb87c5d1f..99aeeb9af 100644 --- a/appdaemon/app_management.py +++ b/appdaemon/app_management.py @@ -527,12 +527,11 @@ async def safe_create(self: "AppManagement"): module_name, ) - if (pin := cfg.pin_thread) and pin >= self.AD.threading.total_threads: + if (pin := cfg.pin_thread) is not None and pin >= self.AD.threading.total_threads: raise ade.PinOutofRange(pin_thread=pin, total_threads=self.AD.threading.total_threads) - elif (obj := self.objects.get(app_name)) and obj.pin_thread is not None: + if (obj := self.objects.get(app_name)) and obj.pin_thread is not None: pin = obj.pin_thread - else: - pin = -1 + # else pin is already None from cfg.pin_thread # This module should already be loaded and stored in sys.modules mod_obj = await utils.run_in_executor(self, importlib.import_module, module_name) @@ -585,7 +584,7 @@ def add_plugin_object(self, name: str, object: "PluginBase") -> None: type="plugin", object=object, pin_app=False, - pin_thread=-1, + pin_thread=None, running=False, ) diff --git a/appdaemon/callbacks.py b/appdaemon/callbacks.py index d84a6cc61..640506db0 100644 --- a/appdaemon/callbacks.py +++ b/appdaemon/callbacks.py @@ -80,7 +80,7 @@ async def get_callback_entries(self, type="all"): ) callbacks[name][str(uuid_)]["pin_thread"] = ( self.callbacks[name][uuid_]["pin_thread"] - if self.callbacks[name][uuid_]["pin_thread"] != -1 + if self.callbacks[name][uuid_]["pin_thread"] is not None else "None" ) return callbacks diff --git a/appdaemon/scheduler.py b/appdaemon/scheduler.py index 1b4b1866c..2c250f265 100644 --- a/appdaemon/scheduler.py +++ b/appdaemon/scheduler.py @@ -757,7 +757,7 @@ async def get_scheduler_entries(self): schedule[name][str(entry)]["callback"] = self.schedule[name][entry]["callback"].func.__name__ else: schedule[name][str(entry)]["callback"] = self.schedule[name][entry]["callback"].__name__ - schedule[name][str(entry)]["pin_thread"] = self.schedule[name][entry]["pin_thread"] if self.schedule[name][entry]["pin_thread"] != -1 else "None" + schedule[name][str(entry)]["pin_thread"] = self.schedule[name][entry]["pin_thread"] if self.schedule[name][entry]["pin_thread"] is not None else "None" schedule[name][str(entry)]["pin_app"] = "True" if self.schedule[name][entry]["pin_app"] is True else "False" # Order it diff --git a/appdaemon/threads.py b/appdaemon/threads.py index 8e50e4235..312eab2c5 100644 --- a/appdaemon/threads.py +++ b/appdaemon/threads.py @@ -333,7 +333,7 @@ def select_q(self, args): thread = args["pin_thread"] # Handle the case where an App is unpinned but selects a pinned callback without specifying a thread # If this happens a lot, thread 0 might get congested but the alternatives are worse! - if thread == -1: + if thread is None: self.logger.warning( "Invalid thread ID for pinned thread in app: %s - assigning to thread 0", args["name"], @@ -572,7 +572,7 @@ async def calculate_pin_threads(self): thread_pins = [0] * self.pin_threads for name, obj in self.AD.app_management.objects.items(): # Looking for apps that already have a thread pin value - if obj.pin_app and (thread := obj.pin_thread) != -1: + if obj.pin_app and (thread := obj.pin_thread) is not None: if thread >= self.thread_count: raise ValueError("Pinned thread out of range - check apps.yaml for 'pin_thread' or app code for 'set_pin_thread()'") # Ignore anything outside the pin range as it will have been set by the user @@ -581,7 +581,7 @@ async def calculate_pin_threads(self): # Now we know the numbers, go fill in the gaps for name, obj in self.AD.app_management.objects.items(): - if obj.pin_app and obj.pin_thread == -1: + if obj.pin_app and obj.pin_thread is None: thread = thread_pins.index(min(thread_pins)) self.AD.app_management.set_pin_thread(name, thread) thread_pins[thread] += 1