Skip to content

Commit 28795dd

Browse files
committed
Add support for BONJOUR query
1 parent 3c78508 commit 28795dd

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ The following event_id's are defined:
169169
* DISCOVER - Subscribe to user initiated device discovery event
170170
* OAUTH - Subscribe to oauth token authentication data events
171171
* WEBHOOK - Subscribe to webhook data events
172+
* BONJOUR - Subscribe to get responses from the bonjour mdns query
172173

173174

174175
The data events will send the specific type of data, when that data changes in PG3. For example, when the user changes a custom parameter, the CUSTOMPARAMS event will be published with the current (changed) custom parameter data.
@@ -366,6 +367,7 @@ __getValidAddress(address)__ Remove characters that are considered illegal for n
366367
* __addLogLevel__(name, level, string\_name), Add a new log level to the logger and to the list displayed to the user. 'name' is the level name string (typically all upper case like DEBUG, WARNING, etc.) 'level' is the numeric value of new level, and string_name is the string to display to the user in the log level selector. <BR> **NOTE** that this modifies the node server log level list which is stored as part of the node server configuration in PG3. Thus you should only attempt to add items to the list after the config data has been recieved from PG3. The best place to do this would be in a CONFIG event handler. <BR>**NOTE2** that there is currently no way to remove or modify an item on the list other than replacing the whole list. See __setLogList()__ below.
367368
* __setLogList(list)__ Send the list of log levels for the frontend log level list selector. The 'list' is an array of __{display_name:LOGLEVEL}__ objects. The user will be presented with the 'display_name' and when selected, it will set the log level to LOGLEVEL. LOGLEVEL must be one of the valid levels supported by the logger or added via the addLevelName method in the logger. (DEPRECATED) <BR>Currently you have to pass all values including default ones to add yours:
368369
* __webhookResponse(response, status)__ Sends a response to the webhook request
370+
* __bonjour()__ Sends a request to make a bonjour (mDNS) query on the local network. The response is sent back in a polyglot.BONJOUR event
369371

370372
```python
371373
poly.setLogList([

udi_interface/interface.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class pub(object):
5959
'node_server_info',
6060
'discover',
6161
'oauth',
62-
'webhook'
62+
'webhook',
63+
'bonjour'
6364
]
6465

6566
topics = {}
@@ -187,6 +188,7 @@ class Interface(object):
187188
DISCOVER = 18
188189
OAUTH = 19
189190
WEBHOOK = 20
191+
BONJOUR = 21
190192

191193
"""
192194
Polyglot Interface Class
@@ -343,7 +345,7 @@ def _message(self, mqttc, userdata, msg):
343345
'config', 'customdata', 'customparams', 'notices',
344346
'getIsyInfo', 'getAll', 'setLogLevel',
345347
'customtypeddata', 'customtypedparams', 'getNsInfo',
346-
'discover', 'nsdata', 'setController', 'oauth', 'webhook' ]
348+
'discover', 'nsdata', 'setController', 'oauth', 'webhook', 'bonjour' ]
347349

348350
parsed_msg = json.loads(msg.payload.decode('utf-8'))
349351
#LOGGER.debug('MQTT Received Message: {}: {}'.format(msg.topic, parsed_msg))
@@ -994,6 +996,8 @@ def _handleInput(self, key, item, published):
994996
LOGGER.debug('connection status node/driver update')
995997
elif key == 'webhook':
996998
pub.publish(self.WEBHOOK, None, item)
999+
elif key == 'bonjour':
1000+
pub.publish(self.BONJOUR, None, item)
9971001

9981002
def _handleResult(self, result):
9991003
try:
@@ -1493,11 +1497,22 @@ def webhookResponse(self, body='Success', status=200):
14931497
LOGGER.debug('Returning webhook response')
14941498
self.send({'webhook': { 'body': body, 'status': status } }, 'portal')
14951499

1496-
def bonjour(self, type, subtype, protocol):
1500+
""" Node server method to initiate a bonjour query on the network. Response is returned as a polyglot.BONJOUR event """
1501+
def bonjour(self, type, subtypes, protocol):
1502+
1503+
if type is not None and not isinstance(type, str):
1504+
raise TypeError('type must be a string')
1505+
1506+
if subtypes is not None and not isinstance(subtypes, list):
1507+
raise TypeError('subtypes must be an array')
1508+
1509+
if protocol not in ['tcp', 'udp', None]:
1510+
raise ValueError('protocol can be either "tcp", "udp"')
1511+
14971512
message = {
14981513
'bonjour': [{
14991514
'type': type,
1500-
'subtype': subtype,
1515+
'subtypes': subtypes,
15011516
'protocol': protocol
15021517
}]
15031518
}

0 commit comments

Comments
 (0)