File tree Expand file tree Collapse file tree 5 files changed +18
-16
lines changed
Expand file tree Collapse file tree 5 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ mqttwarn changelog
66in progress
77===========
88
9+ - Allow dispatching of messages with no target address information.
10+ This helps for service plugins like Apprise to make the configuration
11+ snippet more compact. Now, service configurations can omit the ``targets ``
12+ option altogether.
13+
914
10152021-10-17 0.27.0
1116=================
Original file line number Diff line number Diff line change @@ -543,10 +543,6 @@ targets = {
543543[config:apprise-json]
544544module = ' apprise'
545545baseuri = ' json://localhost:1234/mqtthook'
546- ; Surrogate for satisfying machinery.
547- targets = {
548- ' n/a' : [' ' ],
549- }
550546
551547[apprise-test]
552548topic = apprise/#
Original file line number Diff line number Diff line change @@ -102,17 +102,12 @@ def get_service_config(self, service):
102102 return dict (config )
103103
104104 def get_service_targets (self , service ):
105+ # Be more graceful with jobs w/o any target address information (2021-10-18 [amo]).
105106 try :
106- targets = self .config .getdict ('config:' + service , 'targets' )
107- if type (targets ) != dict :
108- logger .error ("No targets for service `%s'" % service )
107+ targets = self .config .getdict ('config:' + service , 'targets' ) or [None ]
108+ return targets
109109 except :
110- logger .error ("No targets for service `%s'" % service )
111-
112- if targets is None :
113- return {}
114-
115- return dict (targets )
110+ logger .exception ("Unable to access targets for service `%s'" % service )
116111
117112
118113@attr .s
Original file line number Diff line number Diff line change @@ -454,12 +454,18 @@ def processor(worker_id=None):
454454 q_in .task_done ()
455455 continue
456456
457+ # Be more graceful with jobs w/o any target address information (2021-10-18 [amo]).
458+ if target is None :
459+ addrs = []
460+ else :
461+ addrs = service_targets [target ]
462+
457463 item = {
458464 'service' : service ,
459465 'section' : section ,
460466 'target' : target ,
461467 'config' : service_config ,
462- 'addrs' : service_targets [ target ] ,
468+ 'addrs' : addrs ,
463469 'topic' : topic ,
464470 'payload' : job .payload ,
465471 'data' : None ,
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22# (c) 2021 The mqttwarn developers
3- from dataclasses import dataclass
3+ from dataclasses import dataclass , field
44from typing import Dict , List , Union
55
66
@@ -13,7 +13,7 @@ class ProcessorItem:
1313 service : str = None
1414 target : str = None
1515 config : Dict = None
16- addrs : List [str ] = None
16+ addrs : List [str ] = field ( default_factory = list )
1717 priority : int = None
1818 topic : str = None
1919 title : str = None
You can’t perform that action at this time.
0 commit comments