Skip to content

Commit cbfa4bf

Browse files
authored
Merge pull request #2254 from AppDaemon/production_mode
added setter for production mode and cleaned up a bit
2 parents c56853f + ff813fc commit cbfa4bf

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

appdaemon/adapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,11 @@ async def set_production_mode(self, mode: bool = True) -> bool | None:
979979
The specified mode or ``None`` if a wrong parameter is passed.
980980
981981
"""
982-
if not isinstance(mode, bool):
982+
if isinstance(mode, bool):
983+
self.AD.production_mode = mode
984+
return mode
985+
else:
983986
self.logger.warning("%s not a valid parameter for Production Mode", mode)
984-
return
985-
await self.AD.utility.set_production_mode(mode)
986-
return mode
987987

988988
#
989989
# Internal Helper functions

appdaemon/appdaemon.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import os.path
32
import threading
43
from asyncio import BaseEventLoop
54
from concurrent.futures import ThreadPoolExecutor
@@ -276,6 +275,12 @@ def namespaces(self):
276275
def production_mode(self):
277276
return self.config.production_mode
278277

278+
@production_mode.setter
279+
def production_mode(self, mode: bool):
280+
self.config.production_mode = mode
281+
action = "activated" if mode else "deactivated"
282+
self.logger.info("AD Production Mode %s", action)
283+
279284
@property
280285
def qsize_warning_iterations(self):
281286
return self.config.qsize_warning_iterations

appdaemon/utility_loop.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,11 @@ async def loop(self):
256256
if self.AD.http is not None:
257257
await self.AD.http.stop_server()
258258

259-
async def set_production_mode(self, mode: bool = True):
260-
if mode is True:
261-
self.logger.info("AD Production Mode Activated")
262-
else:
263-
self.logger.info("AD Production Mode Deactivated")
264-
self.AD.production_mode = mode
265-
266259
async def production_mode_service(self, ns, domain, service, kwargs):
267-
if "mode" in kwargs:
268-
mode = kwargs["mode"]
269-
await self.set_production_mode(mode)
260+
if mode := kwargs.get("mode"):
261+
if isinstance(mode, bool):
262+
self.AD.production_mode = mode
263+
else:
264+
self.logger.warning("Invalid 'mode' specified in service call")
270265
else:
271266
self.logger.warning("'Mode' not specified in service call")

0 commit comments

Comments
 (0)