Skip to content

Commit

Permalink
Merge pull request #1753 from Odianosen25/plugin-event-fix
Browse files Browse the repository at this point in the history
Fix for events listening to event
  • Loading branch information
acockburn committed Apr 16, 2023
2 parents a90f869 + 444daae commit 0fd9d3e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion appdaemon/app_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,15 @@ async def init_object(self, name):
)
await self.increase_inactive_apps(name)

def init_plugin_object(self, name, object):
def init_plugin_object(self, name: str, object: object, use_dictionary_unpacking: bool = False) -> None:
self.objects[name] = {
"type": "plugin",
"object": object,
"id": uuid.uuid4().hex,
"pin_app": False,
"pin_thread": -1,
"running": False,
"use_dictionary_unpacking": use_dictionary_unpacking,
}

def init_sequence_object(self, name, object):
Expand Down
15 changes: 13 additions & 2 deletions appdaemon/plugin_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def __init__(self, ad: AppDaemon, kwargs):
if "refresh_timeout" not in self.plugins[name]:
self.plugins[name]["refresh_timeout"] = 30

if "use_dictionary_unpacking" not in self.plugins[name]:
self.plugins[name]["use_dictionary_unpacking"] = True

basename = self.plugins[name]["type"]
type = self.plugins[name]["type"]
module_name = "{}plugin".format(basename)
Expand Down Expand Up @@ -153,7 +156,8 @@ def __init__(self, ad: AppDaemon, kwargs):
#
# Create app entry for the plugin so we can listen_state/event
#
self.AD.app_management.init_plugin_object(name, plugin)
use_dictionary_unpacking = self.plugins[name]["use_dictionary_unpacking"]
self.AD.app_management.init_plugin_object(name, plugin, use_dictionary_unpacking)

self.AD.loop.create_task(plugin.get_updates())
except Exception:
Expand Down Expand Up @@ -297,7 +301,14 @@ async def notify_plugin_started(self, name, ns, meta, state, first_time=False):
"admin",
"plugin.{}".format(name),
"active",
{"bytes_sent_ps": 0, "bytes_recv_ps": 0, "requests_sent_ps": 0, "updates_recv_ps": 0},
{
"bytes_sent_ps": 0,
"bytes_recv_ps": 0,
"requests_sent_ps": 0,
"updates_recv_ps": 0,
"totalcallbacks": 0,
"instancecallbacks": 0,
},
)

self.logger.info("Got initial state from namespace %s", namespace)
Expand Down
18 changes: 13 additions & 5 deletions appdaemon/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,19 @@ async def async_worker(self, args): # noqa: C901
if "__silent" in args["kwargs"]:
silent = args["kwargs"]["__silent"]

app_args = self.AD.app_management.app_config[args["name"]]
if "use_dictionary_unpacking" in app_args:
use_dictionary_unpacking = app_args["use_dictionary_unpacking"]
else:
use_dictionary_unpacking = self.AD.use_dictionary_unpacking
# first we get AD's level directive
use_dictionary_unpacking = self.AD.use_dictionary_unpacking

# app level config takes priority so processed after AD's
if args["name"] in self.AD.app_management.app_config:
app_args = self.AD.app_management.app_config[args["name"]]

if "use_dictionary_unpacking" in app_args:
use_dictionary_unpacking = app_args["use_dictionary_unpacking"]

elif args["name"] in self.AD.app_management.objects:
# plugin's directive is to use dictionary unpacking
use_dictionary_unpacking = self.AD.app_management.objects[args["name"]]["use_dictionary_unpacking"]

app = await self.AD.app_management.get_app_instance(name, objectid)
if app is not None:
Expand Down

0 comments on commit 0fd9d3e

Please sign in to comment.