26
26
27
27
class ApplicationClient (AbstractClient ):
28
28
"""
29
- Extends #wiotp.AbstractClient to implement an application client supporting
29
+ Extends #wiotp.AbstractClient to implement an application client supporting
30
30
messaging over MQTT
31
-
31
+
32
32
# Parameters
33
33
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`,
35
35
which will result in a default log handler being created.
36
-
36
+
37
37
# Configuration Options
38
38
The options parameter expects a Python dictionary containing the following keys:
39
-
39
+
40
40
- `auth-key` The API key to to securely connect your application to Watson IoT Platform.
41
41
- `auth-token` An authentication token to securely connect your application to Watson IoT Platform.
42
42
- `clean-session` A boolean value indicating whether to use MQTT clean session.
@@ -71,9 +71,8 @@ def __init__(self, config, logHandlers=None):
71
71
self .client .message_callback_add ("iot-2/type/+/id/+/err/data" , self ._onErrorTopic )
72
72
self .client .message_callback_add ("iot-2/thing/type/+/id/+/err/data" , self ._onThingError )
73
73
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 )
77
76
78
77
# Attach fallback handler
79
78
self .client .on_message = self ._onUnsupportedMessage
@@ -87,26 +86,22 @@ def __init__(self, config, logHandlers=None):
87
86
self .errorTopicCallback = None
88
87
self .appStatusCallback = None
89
88
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 )
104
102
105
103
def serviceStatus (self ):
106
- if not self ._config .isQuickstart ():
107
- return self ._serviceStatus .get ()
108
- else :
109
- return None
104
+ return self ._serviceStatus .get ()
110
105
111
106
def subscribeToDeviceEvents (self , typeId = "+" , deviceId = "+" , eventId = "+" , msgFormat = "+" , qos = 0 ):
112
107
"""
@@ -125,12 +120,6 @@ def subscribeToDeviceEvents(self, typeId="+", deviceId="+", eventId="+", msgForm
125
120
the mid argument if you register a subscriptionCallback method.
126
121
If the subscription fails then the return value will be `0`
127
122
"""
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
-
134
123
topic = "iot-2/type/%s/id/%s/evt/%s/fmt/%s" % (typeId , deviceId , eventId , msgFormat )
135
124
return self ._subscribe (topic , qos )
136
125
@@ -148,10 +137,6 @@ def subscribeToDeviceStatus(self, typeId="+", deviceId="+"):
148
137
the mid argument if you register a subscriptionCallback method.
149
138
If the subscription fails then the return value will be `0`
150
139
"""
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
-
155
140
topic = "iot-2/type/%s/id/%s/mon" % (typeId , deviceId )
156
141
return self ._subscribe (topic , 0 )
157
142
@@ -169,10 +154,6 @@ def subscribeToErrorTopic(self, typeId="+", Id="+"):
169
154
the mid argument if you register a subscriptionCallback method.
170
155
If the subscription fails then the return value will be `0`
171
156
"""
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
-
176
157
topic = "iot-2/type/%s/id/%s/err/data" % (typeId , Id )
177
158
return self ._subscribe (topic , 0 )
178
159
@@ -190,10 +171,6 @@ def subscribeToThingErrors(self, typeId="+", Id="+"):
190
171
the mid argument if you register a subscriptionCallback method.
191
172
If the subscription fails then the return value will be `0`
192
173
"""
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
-
197
174
topic = "iot-2/thing/type/%s/id/%s/err/data" % (typeId , Id )
198
175
return self ._subscribe (topic , 0 )
199
176
@@ -212,10 +189,6 @@ def subscribeToThingState(self, typeId="+", thingId="+", logicalInterfaceId="+")
212
189
the mid argument if you register a subscriptionCallback method.
213
190
If the subscription fails then the return value will be `0`
214
191
"""
215
- if self ._config .isQuickstart ():
216
- self .logger .warning ("QuickStart applications do not support thing state" )
217
- return 0
218
-
219
192
topic = "iot-2/thing/type/%s/id/%s/intf/%s/evt/state" % (typeId , thingId , logicalInterfaceId )
220
193
return self ._subscribe (topic , 0 )
221
194
@@ -234,10 +207,6 @@ def subscribeToDeviceState(self, typeId="+", deviceId="+", logicalInterfaceId="+
234
207
the mid argument if you register a subscriptionCallback method.
235
208
If the subscription fails then the return value will be `0`
236
209
"""
237
- if self ._config .isQuickstart ():
238
- self .logger .warning ("QuickStart applications do not support device state" )
239
- return 0
240
-
241
210
topic = "iot-2/type/%s/id/%s/intf/%s/evt/state" % (typeId , deviceId , logicalInterfaceId )
242
211
return self ._subscribe (topic , 0 )
243
212
@@ -258,10 +227,6 @@ def subscribeToDeviceCommands(self, typeId="+", deviceId="+", commandId="+", msg
258
227
the mid argument if you register a subscriptionCallback method.
259
228
If the subscription fails then the return value will be `0`
260
229
"""
261
- if self ._config .isQuickstart ():
262
- self .logger .warning ("QuickStart applications do not support commands" )
263
- return 0
264
-
265
230
topic = "iot-2/type/%s/id/%s/cmd/%s/fmt/%s" % (typeId , deviceId , commandId , msgFormat )
266
231
return self ._subscribe (topic , 0 )
267
232
@@ -285,9 +250,6 @@ def publishCommand(self, typeId, deviceId, commandId, msgFormat, data=None, qos=
285
250
- qos 0 : the client has asynchronously begun to send the event
286
251
- qos 1 and 2 : the client has confirmation of delivery from WIoTP
287
252
"""
288
- if self ._config .isQuickstart ():
289
- self .logger .warning ("QuickStart applications do not support sending commands" )
290
- return False
291
253
if not self .connectEvent .wait (timeout = 10 ):
292
254
return False
293
255
else :
0 commit comments