diff --git a/appdaemon/adapi.py b/appdaemon/adapi.py index 9fc186f6a..abfc94c75 100644 --- a/appdaemon/adapi.py +++ b/appdaemon/adapi.py @@ -979,11 +979,11 @@ async def set_production_mode(self, mode: bool = True) -> bool | None: The specified mode or ``None`` if a wrong parameter is passed. """ - if not isinstance(mode, bool): + if isinstance(mode, bool): + self.AD.production_mode = mode + return mode + else: self.logger.warning("%s not a valid parameter for Production Mode", mode) - return - await self.AD.utility.set_production_mode(mode) - return mode # # Internal Helper functions diff --git a/appdaemon/appdaemon.py b/appdaemon/appdaemon.py index efb63b7bd..7e3422ab2 100755 --- a/appdaemon/appdaemon.py +++ b/appdaemon/appdaemon.py @@ -1,5 +1,4 @@ import os -import os.path import threading from asyncio import BaseEventLoop from concurrent.futures import ThreadPoolExecutor @@ -276,6 +275,12 @@ def namespaces(self): def production_mode(self): return self.config.production_mode + @production_mode.setter + def production_mode(self, mode: bool): + self.config.production_mode = mode + action = "activated" if mode else "deactivated" + self.logger.info("AD Production Mode %s", action) + @property def qsize_warning_iterations(self): return self.config.qsize_warning_iterations diff --git a/appdaemon/utility_loop.py b/appdaemon/utility_loop.py index 110ae9e45..f47434031 100644 --- a/appdaemon/utility_loop.py +++ b/appdaemon/utility_loop.py @@ -256,16 +256,11 @@ async def loop(self): if self.AD.http is not None: await self.AD.http.stop_server() - async def set_production_mode(self, mode: bool = True): - if mode is True: - self.logger.info("AD Production Mode Activated") - else: - self.logger.info("AD Production Mode Deactivated") - self.AD.production_mode = mode - async def production_mode_service(self, ns, domain, service, kwargs): - if "mode" in kwargs: - mode = kwargs["mode"] - await self.set_production_mode(mode) + if mode := kwargs.get("mode"): + if isinstance(mode, bool): + self.AD.production_mode = mode + else: + self.logger.warning("Invalid 'mode' specified in service call") else: self.logger.warning("'Mode' not specified in service call")