Skip to content

Commit 8c48325

Browse files
committed
Merge branch 'dev' of https://github.com/AppDaemon/appdaemon into dev
2 parents 302e8c9 + 21a6d1d commit 8c48325

File tree

7 files changed

+35
-27
lines changed

7 files changed

+35
-27
lines changed

appdaemon/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def run(self, ad_config_model: AppDaemonConfig, *args, http):
124124
self.logger.info("Running AD using uvloop")
125125
uvloop.install()
126126

127-
loop: asyncio.BaseEventLoop = asyncio.new_event_loop()
127+
loop: asyncio.AbstractEventLoop = asyncio.new_event_loop()
128128

129129
# Initialize AppDaemon
130130

appdaemon/app_management.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,10 @@ async def create_app_object(self, app_name: str) -> None:
513513
def get_managed_app_names(self, include_globals: bool = False) -> set[str]:
514514
apps = set(name for name, o in self.objects.items() if o.type == "app")
515515
if include_globals:
516-
globals = set(
516+
apps |= set(
517517
name for name, cfg in self.app_config.root.items()
518518
if isinstance(cfg, GlobalModule)
519-
)
520-
apps |= globals
519+
) # fmt: skip
521520
return apps
522521

523522
def add_plugin_object(self, name: str, object: "PluginBase", use_dictionary_unpacking: bool = False) -> None:

appdaemon/appdaemon.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ def __init__(self, logging: "Logging", loop: BaseEventLoop, ad_config_model: App
113113
self.global_vars: Any = {}
114114
self.main_thread_id = threading.current_thread().ident
115115

116-
if not self.apps:
117-
self.logging.log("INFO", "Apps are disabled")
118-
119116
# Initialize subsystems
120117
self.callbacks = Callbacks(self)
121118
self.events = Events(self)
@@ -125,7 +122,9 @@ def __init__(self, logging: "Logging", loop: BaseEventLoop, ad_config_model: App
125122
self.state = State(self)
126123
self.futures = Futures(self)
127124

128-
if self.apps is True:
125+
if not self.apps:
126+
self.logger.info("Apps are disabled, skipping app management initialization")
127+
else:
129128
assert self.config_dir is not None, "Config_dir not set. This is a development problem"
130129
assert self.config_dir.exists(), f"{self.config_dir} does not exist"
131130
assert os.access(
@@ -146,12 +145,13 @@ def __init__(self, logging: "Logging", loop: BaseEventLoop, ad_config_model: App
146145
self.logger.info(f"Using {self.app_dir} as app_dir")
147146

148147
self.app_management = AppManagement(self)
149-
self.threading = Threading(self)
150148

151-
# Create ThreadAsync loop
152-
self.logger.debug("Starting thread_async loop")
153-
self.thread_async = ThreadAsync(self)
154-
loop.create_task(self.thread_async.loop())
149+
self.threading = Threading(self)
150+
151+
# Create ThreadAsync loop
152+
self.logger.debug("Starting thread_async loop")
153+
self.thread_async = ThreadAsync(self)
154+
loop.create_task(self.thread_async.loop())
155155

156156
self.executor = ThreadPoolExecutor(max_workers=self.threadpool_workers)
157157

appdaemon/logging.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import traceback
66
import uuid
77
from collections import OrderedDict
8-
from logging import Logger, StreamHandler
8+
from logging import LogRecord, Logger, StreamHandler
99
from logging.handlers import RotatingFileHandler
1010
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
1111

@@ -40,23 +40,22 @@ def __init__(self, logger: logging.Logger, threshold: float, delay: float, timeo
4040
self.timeout = timeout
4141
self.last_log_time = None
4242

43-
def filter(self, record: logging.LogRecord) -> bool:
43+
def filter(self, record: logging.LogRecord) -> bool | LogRecord:
4444
if record.msg == "Previous message repeated %s times":
4545
return True
4646
if self.threshold == 0:
4747
return True
4848
current_log = (record.module, record.levelno, record.msg, record.args)
4949
if current_log != self.last_log:
5050
self.last_log = current_log
51+
result = True
5152
if self.filtering is True:
52-
self.logger.info(
53-
"Previous message repeated %s times",
54-
self.current_count - self.threshold + 1,
55-
)
53+
record.msg = "Previous message repeated %s times"
54+
record.args = (self.current_count - self.threshold + 1,)
55+
result = record
5656
self.current_count = 0
5757
self.filtering = False
5858
self.start_time = None
59-
result = True
6059
self.first_time = True
6160
self.last_log_time = datetime.datetime.now()
6261
else:

appdaemon/plugin_management.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ def __init__(self, ad: "AppDaemon", config: Mapping[str, PluginConfig]):
302302
#
303303
# Create app entry for the plugin so we can listen_state/event
304304
#
305-
self.AD.app_management.add_plugin_object(name, plugin, self.config[name].use_dictionary_unpacking)
305+
if not self.AD.config.disable_apps:
306+
self.AD.app_management.add_plugin_object(
307+
name,
308+
plugin,
309+
self.config[name].use_dictionary_unpacking
310+
)
306311

307312
self.AD.loop.create_task(plugin.get_updates())
308313
except Exception:

appdaemon/plugins/hass/hassapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ def constrain_input_boolean(self, value: str | Iterable[str]) -> bool:
410410
def constrain_input_select(self, value: str | Iterable[str]) -> bool:
411411
"""Returns True if unconstrained - all inputs match a desired state."""
412412
match value:
413-
case Iterable():
414-
constraints = value if isinstance(value, list) else list(value)
415413
case str():
416414
constraints = [value]
415+
case Iterable():
416+
constraints = value if isinstance(value, list) else list(value)
417417

418418
assert isinstance(constraints, list) and all(isinstance(v, str) for v in constraints)
419419

appdaemon/utility_loop.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ async def loop(self):
7474
#
7575
# Setup
7676
#
77-
# self.AD.threading = Threading(self)
77+
7878
await self.AD.threading.init_admin_stats()
79-
await self.AD.threading.create_initial_threads()
80-
await self.AD.app_management.init_admin_stats()
79+
if not self.AD.config.disable_apps:
80+
await self.AD.threading.create_initial_threads()
81+
await self.AD.app_management.init_admin_stats()
82+
else:
83+
await self.AD.threading.add_thread(silent=True)
84+
self.total_threads = 1
8185

8286
#
8387
# Start the web server
@@ -246,7 +250,8 @@ async def loop(self):
246250
#
247251
# Stop apps
248252
#
249-
if self.AD.app_management is not None:
253+
if not self.AD.config.disable_apps and \
254+
self.AD.app_management is not None: # fmt: skip
250255
await self.AD.app_management.terminate()
251256

252257
#

0 commit comments

Comments
 (0)