1616 BaseNotificationService ,
1717)
1818
19+ PRIORITIES = {
20+ "high" : 10 ,
21+ "normal" : 5 ,
22+ "default" : 5 ,
23+ "low" : 2 ,
24+ "min" : 0 ,
25+ "none" : 0
26+ }
1927PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend ({vol .Required (CONF_URL ): cv .url , vol .Required (CONF_TOKEN ): cv .string })
2028_LOGGER = logging .getLogger (__name__ )
2129
2230def get_service (hass , config , discovery_info = None ):
2331 url = config .get (CONF_URL )
2432 token = config .get (CONF_TOKEN )
2533 verify_ssl = config .get (CONF_VERIFY_SSL , True )
34+ msg_blacklist = config .get ('msg_blacklist' , [])
2635
2736 _LOGGER .info ('Service created' )
2837
29- return HassAgentNotificationService (hass , url , token , verify_ssl )
38+ return HassAgentNotificationService (hass , url , token , verify_ssl , msg_blacklist )
3039
3140
3241class HassAgentNotificationService (BaseNotificationService ):
33- def __init__ (self , hass , url , token , verify_ssl ):
42+ def __init__ (self , hass , url , token , verify_ssl , msg_blacklist ):
3443 self ._url = url
3544 self ._token = token
3645 self ._hass = hass
3746 self ._verify_ssl = verify_ssl
47+ self ._msg_blacklist = msg_blacklist
3848
3949 if not self ._url .endswith ('/' ):
4050 self ._url += '/'
@@ -44,15 +54,22 @@ def send_request(self, data):
4454 return requests .post (self ._url , headers = {'X-Gotify-Key' : self ._token }, json = data , verify = self ._verify_ssl , timeout = 10 )
4555
4656 async def async_send_message (self , message : str , ** kwargs : Any ):
57+ if message .strip () in self ._msg_blacklist :
58+ return
59+
4760 title = kwargs .get (ATTR_TITLE , ATTR_TITLE_DEFAULT )
4861 data = kwargs .get (ATTR_DATA , None )
4962 if data is None :
5063 data = dict ()
5164
65+ priority = data .get ('priority' , 5 )
66+ if type (priority ) is str :
67+ priority = PRIORITIES .get (priority , 5 )
68+
5269 payload = {
5370 'title' : title ,
5471 'message' : message ,
55- 'priority' : data . get ( ' priority' , 5 )
72+ 'priority' : priority
5673 }
5774 if 'extras' in data :
5875 payload ['extras' ] = data .get ('extras' )
0 commit comments