2626
2727class ApplicationClient (AbstractClient ):
2828 """
29- Extends #wiotp.AbstractClient to implement an application client supporting
29+ Extends #wiotp.AbstractClient to implement an application client supporting
3030 messaging over MQTT
31-
31+
3232 # Parameters
3333 options (dict): Configuration options for the client
34- logHandlers (list<logging.Handler>): Log handlers to configure. Defaults to `None`,
34+ logHandlers (list<logging.Handler>): Log handlers to configure. Defaults to `None`,
3535 which will result in a default log handler being created.
36-
36+
3737 # Configuration Options
3838 The options parameter expects a Python dictionary containing the following keys:
39-
39+
4040 - `auth-key` The API key to to securely connect your application to Watson IoT Platform.
4141 - `auth-token` An authentication token to securely connect your application to Watson IoT Platform.
4242 - `clean-session` A boolean value indicating whether to use MQTT clean session.
@@ -71,9 +71,8 @@ def __init__(self, config, logHandlers=None):
7171 self .client .message_callback_add ("iot-2/type/+/id/+/err/data" , self ._onErrorTopic )
7272 self .client .message_callback_add ("iot-2/thing/type/+/id/+/err/data" , self ._onThingError )
7373
74- # Add handler for commands if not connected to QuickStart
75- if not self ._config .isQuickstart ():
76- self .client .message_callback_add ("iot-2/type/+/id/+/cmd/+/fmt/+" , self ._onDeviceCommand )
74+ # Add handler for commands
75+ self .client .message_callback_add ("iot-2/type/+/id/+/cmd/+/fmt/+" , self ._onDeviceCommand )
7776
7877 # Attach fallback handler
7978 self .client .on_message = self ._onUnsupportedMessage
@@ -87,26 +86,22 @@ def __init__(self, config, logHandlers=None):
8786 self .errorTopicCallback = None
8887 self .appStatusCallback = None
8988
90- # Create an api client if not connected in QuickStart mode
91- if not self ._config .isQuickstart ():
92- apiClient = ApiClient (self ._config , self .logger )
93- self .registry = Registry (apiClient )
94- self .usage = Usage (apiClient )
95- self .dsc = DSC (apiClient )
96- self .lec = LEC (apiClient )
97- self .mgmt = Mgmt (apiClient )
98- self .serviceBindings = ServiceBindings (apiClient )
99- self .actions = Actions (apiClient )
100- self .state = StateMgr (apiClient )
101-
102- # We directly expose the get() method via self.serviceStatus()
103- self ._serviceStatus = ServiceStatus (apiClient )
89+ # Create an api client
90+ apiClient = ApiClient (self ._config , self .logger )
91+ self .registry = Registry (apiClient )
92+ self .usage = Usage (apiClient )
93+ self .dsc = DSC (apiClient )
94+ self .lec = LEC (apiClient )
95+ self .mgmt = Mgmt (apiClient )
96+ self .serviceBindings = ServiceBindings (apiClient )
97+ self .actions = Actions (apiClient )
98+ self .state = StateMgr (apiClient )
99+
100+ # We directly expose the get() method via self.serviceStatus()
101+ self ._serviceStatus = ServiceStatus (apiClient )
104102
105103 def serviceStatus (self ):
106- if not self ._config .isQuickstart ():
107- return self ._serviceStatus .get ()
108- else :
109- return None
104+ return self ._serviceStatus .get ()
110105
111106 def subscribeToDeviceEvents (self , typeId = "+" , deviceId = "+" , eventId = "+" , msgFormat = "+" , qos = 0 ):
112107 """
@@ -125,12 +120,6 @@ def subscribeToDeviceEvents(self, typeId="+", deviceId="+", eventId="+", msgForm
125120 the mid argument if you register a subscriptionCallback method.
126121 If the subscription fails then the return value will be `0`
127122 """
128- if self ._config .isQuickstart () and deviceId == "+" :
129- self .logger .warning (
130- "QuickStart applications do not support wildcard subscription to events from all devices"
131- )
132- return 0
133-
134123 topic = "iot-2/type/%s/id/%s/evt/%s/fmt/%s" % (typeId , deviceId , eventId , msgFormat )
135124 return self ._subscribe (topic , qos )
136125
@@ -148,10 +137,6 @@ def subscribeToDeviceStatus(self, typeId="+", deviceId="+"):
148137 the mid argument if you register a subscriptionCallback method.
149138 If the subscription fails then the return value will be `0`
150139 """
151- if self ._config .isQuickstart () and deviceId == "+" :
152- self .logger .warning ("QuickStart applications do not support wildcard subscription to device status" )
153- return 0
154-
155140 topic = "iot-2/type/%s/id/%s/mon" % (typeId , deviceId )
156141 return self ._subscribe (topic , 0 )
157142
@@ -169,10 +154,6 @@ def subscribeToErrorTopic(self, typeId="+", Id="+"):
169154 the mid argument if you register a subscriptionCallback method.
170155 If the subscription fails then the return value will be `0`
171156 """
172- if self ._config .isQuickstart () and Id == "+" :
173- self .logger .warning ("QuickStart applications do not support wildcard subscription to error topics" )
174- return 0
175-
176157 topic = "iot-2/type/%s/id/%s/err/data" % (typeId , Id )
177158 return self ._subscribe (topic , 0 )
178159
@@ -190,10 +171,6 @@ def subscribeToThingErrors(self, typeId="+", Id="+"):
190171 the mid argument if you register a subscriptionCallback method.
191172 If the subscription fails then the return value will be `0`
192173 """
193- if self ._config .isQuickstart () and Id == "+" :
194- self .logger .warning ("QuickStart applications do not support wildcard subscription to error topics" )
195- return 0
196-
197174 topic = "iot-2/thing/type/%s/id/%s/err/data" % (typeId , Id )
198175 return self ._subscribe (topic , 0 )
199176
@@ -212,10 +189,6 @@ def subscribeToThingState(self, typeId="+", thingId="+", logicalInterfaceId="+")
212189 the mid argument if you register a subscriptionCallback method.
213190 If the subscription fails then the return value will be `0`
214191 """
215- if self ._config .isQuickstart ():
216- self .logger .warning ("QuickStart applications do not support thing state" )
217- return 0
218-
219192 topic = "iot-2/thing/type/%s/id/%s/intf/%s/evt/state" % (typeId , thingId , logicalInterfaceId )
220193 return self ._subscribe (topic , 0 )
221194
@@ -234,10 +207,6 @@ def subscribeToDeviceState(self, typeId="+", deviceId="+", logicalInterfaceId="+
234207 the mid argument if you register a subscriptionCallback method.
235208 If the subscription fails then the return value will be `0`
236209 """
237- if self ._config .isQuickstart ():
238- self .logger .warning ("QuickStart applications do not support device state" )
239- return 0
240-
241210 topic = "iot-2/type/%s/id/%s/intf/%s/evt/state" % (typeId , deviceId , logicalInterfaceId )
242211 return self ._subscribe (topic , 0 )
243212
@@ -258,10 +227,6 @@ def subscribeToDeviceCommands(self, typeId="+", deviceId="+", commandId="+", msg
258227 the mid argument if you register a subscriptionCallback method.
259228 If the subscription fails then the return value will be `0`
260229 """
261- if self ._config .isQuickstart ():
262- self .logger .warning ("QuickStart applications do not support commands" )
263- return 0
264-
265230 topic = "iot-2/type/%s/id/%s/cmd/%s/fmt/%s" % (typeId , deviceId , commandId , msgFormat )
266231 return self ._subscribe (topic , 0 )
267232
@@ -285,9 +250,6 @@ def publishCommand(self, typeId, deviceId, commandId, msgFormat, data=None, qos=
285250 - qos 0 : the client has asynchronously begun to send the event
286251 - qos 1 and 2 : the client has confirmation of delivery from WIoTP
287252 """
288- if self ._config .isQuickstart ():
289- self .logger .warning ("QuickStart applications do not support sending commands" )
290- return False
291253 if not self .connectEvent .wait (timeout = 10 ):
292254 return False
293255 else :
0 commit comments