summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0323/stanza/sensordata.py
blob: 79094e4cd0dca772c0afc2f4f5fc5e99b413a917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
"""
    Slixmpp: The Slick XMPP Library
    Implementation of xeps for Internet of Things
    http://wiki.xmpp.org/web/Tech_pages/IoT_systems
    Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se
    This file is part of Slixmpp.

    See the file LICENSE for copying permission.
"""

from slixmpp import Iq, Message
from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
from re import match

class Sensordata(ElementBase):
    """ Placeholder for the namespace, not used as a stanza """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'sensordata'
    plugin_attrib = name
    interfaces = set(tuple())

class FieldTypes():
    """
    All field types are optional booleans that default to False
    """
    field_types = set([ 'momentary','peak','status','computed','identity','historicalSecond','historicalMinute','historicalHour', \
                        'historicalDay','historicalWeek','historicalMonth','historicalQuarter','historicalYear','historicalOther'])

class FieldStatus():
    """
    All field statuses are optional booleans that default to False
    """
    field_status = set([ 'missing','automaticEstimate','manualEstimate','manualReadout','automaticReadout','timeOffset','warning','error', \
                         'signed','invoiced','endOfSeries','powerFailure','invoiceConfirmed'])

class Request(ElementBase):
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'req'
    plugin_attrib = name
    interfaces = {'seqnr','nodes','fields','serviceToken','deviceToken','userToken','from','to','when','historical','all'}
    interfaces.update(FieldTypes.field_types)
    _flags = {'serviceToken','deviceToken','userToken','from','to','when','historical','all'}
    _flags.update(FieldTypes.field_types)

    def __init__(self, xml=None, parent=None):
        ElementBase.__init__(self, xml, parent)
        self._nodes = set()
        self._fields = set()

    def setup(self, xml=None):
        """
        Populate the stanza object using an optional XML object.

        Overrides ElementBase.setup

        Caches item information.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        ElementBase.setup(self, xml)
        self._nodes = {node['nodeId'] for node in self['nodes']}
        self._fields = {field['name'] for field in self['fields']}

    def _get_flags(self):
        """
        Helper function for getting of flags. Returns all flags in
        dictionary format: { "flag name": "flag value" ... }
        """
        flags = {}
        for f in self._flags:
            if not self[f] == "":
                flags[f] = self[f]
        return flags

    def _set_flags(self, flags):
        """
        Helper function for setting of flags.

        Arguments:
            flags -- Flags in dictionary format: { "flag name": "flag value" ... }
        """
        for f in self._flags:
            if flags is not None and f in flags:
                self[f] = flags[f]
            else:
                self[f] = None

    def add_node(self, nodeId, sourceId=None, cacheType=None):
        """
        Add a new node element. Each item is required to have a
        nodeId, but may also specify a sourceId value and cacheType.

        Arguments:
            nodeId    -- The ID for the node.
            sourceId  -- [optional] identifying the data source controlling the device
            cacheType -- [optional] narrowing down the search to a specific kind of node
        """
        if nodeId not in self._nodes:
            self._nodes.add((nodeId))
            node = RequestNode(parent=self)
            node['nodeId'] = nodeId
            node['sourceId'] = sourceId
            node['cacheType'] = cacheType
            self.iterables.append(node)
            return node
        return None

    def del_node(self, nodeId):
        """
        Remove a single node.

        Arguments:
            nodeId  -- Node ID of the item to remove.
        """
        if nodeId in self._nodes:
            nodes = [i for i in self.iterables if isinstance(i, RequestNode)]
            for node in nodes:
                if node['nodeId'] == nodeId:
                    self.xml.remove(node.xml)
                    self.iterables.remove(node)
                    return True
        return False

    def get_nodes(self):
        """Return all nodes."""
        nodes = []
        for node in self['substanzas']:
            if isinstance(node, RequestNode):
                nodes.append(node)
        return nodes

    def set_nodes(self, nodes):
        """
        Set or replace all nodes. The given nodes must be in a
        list or set where each item is a tuple of the form:
            (nodeId, sourceId, cacheType)

        Arguments:
            nodes -- A series of nodes in tuple format.
        """
        self.del_nodes()
        for node in nodes:
            if isinstance(node, RequestNode):
                self.add_node(node['nodeId'], node['sourceId'], node['cacheType'])
            else:
                nodeId, sourceId, cacheType = node
                self.add_node(nodeId, sourceId, cacheType)

    def del_nodes(self):
        """Remove all nodes."""
        self._nodes = set()
        nodes = [i for i in self.iterables if isinstance(i, RequestNode)]
        for node in nodes:
            self.xml.remove(node.xml)
            self.iterables.remove(node)


    def add_field(self, name):
        """
        Add a new field element. Each item is required to have a
        name.

        Arguments:
            name  -- The name of the field.
        """
        if name not in self._fields:
            self._fields.add((name))
            field = RequestField(parent=self)
            field['name'] = name
            self.iterables.append(field)
            return field
        return None

    def del_field(self, name):
        """
        Remove a single field.

        Arguments:
            name  -- name of field to remove.
        """
        if name in self._fields:
            fields = [i for i in self.iterables if isinstance(i, RequestField)]
            for field in fields:
                if field['name'] == name:
                    self.xml.remove(field.xml)
                    self.iterables.remove(field)
                    return True
        return False

    def get_fields(self):
        """Return all fields."""
        fields = []
        for field in self['substanzas']:
            if isinstance(field, RequestField):
                fields.append(field)
        return fields

    def set_fields(self, fields):
        """
        Set or replace all fields. The given fields must be in a
        list or set where each item is RequestField or string

        Arguments:
            fields -- A series of fields in RequestField or string format.
        """
        self.del_fields()
        for field in fields:
            if isinstance(field, RequestField):
                self.add_field(field['name'])
            else:
                self.add_field(field)

    def del_fields(self):
        """Remove all fields."""
        self._fields = set()
        fields = [i for i in self.iterables if isinstance(i, RequestField)]
        for field in fields:
            self.xml.remove(field.xml)
            self.iterables.remove(field)


class RequestNode(ElementBase):
    """ Node element in a request """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'node'
    plugin_attrib = name
    interfaces = {'nodeId','sourceId','cacheType'}

class RequestField(ElementBase):
    """ Field element in a request """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'field'
    plugin_attrib = name
    interfaces = {'name'}

class Accepted(ElementBase):
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'accepted'
    plugin_attrib = name
    interfaces = {'seqnr','queued'}

class Started(ElementBase):
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'started'
    plugin_attrib = name
    interfaces = {'seqnr'}

class Failure(ElementBase):
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'failure'
    plugin_attrib = name
    interfaces = {'seqnr','done'}

class Error(ElementBase):
    """ Error element in a request failure """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'error'
    plugin_attrib = name
    interfaces = {'nodeId','timestamp','sourceId','cacheType','text'}

    def get_text(self):
        """Return then contents inside the XML tag."""
        return self.xml.text

    def set_text(self, value):
        """Set then contents inside the XML tag.

        :param value: string
        """

        self.xml.text = value
        return self

    def del_text(self):
        """Remove the contents inside the XML tag."""
        self.xml.text = ""
        return self

class Rejected(ElementBase):
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'rejected'
    plugin_attrib = name
    interfaces = {'seqnr','error'}
    sub_interfaces = {'error'}

class Fields(ElementBase):
    """ Fields element, top level in a response message with data """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'fields'
    plugin_attrib = name
    interfaces = {'seqnr','done','nodes'}

    def __init__(self, xml=None, parent=None):
        ElementBase.__init__(self, xml, parent)
        self._nodes = set()

    def setup(self, xml=None):
        """
        Populate the stanza object using an optional XML object.

        Overrides ElementBase.setup

        Caches item information.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        ElementBase.setup(self, xml)
        self._nodes = {node['nodeId'] for node in self['nodes']}


    def add_node(self, nodeId, sourceId=None, cacheType=None, substanzas=None):
        """
        Add a new node element. Each item is required to have a
        nodeId, but may also specify a sourceId value and cacheType.

        Arguments:
            nodeId  -- The ID for the node.
            sourceId  -- [optional] identifying the data source controlling the device
            cacheType -- [optional] narrowing down the search to a specific kind of node
        """
        if nodeId not in self._nodes:
            self._nodes.add((nodeId))
            node = FieldsNode(parent=self)
            node['nodeId'] = nodeId
            node['sourceId'] = sourceId
            node['cacheType'] = cacheType
            if substanzas is not None:
                node.set_timestamps(substanzas)

            self.iterables.append(node)
            return node
        return None

    def del_node(self, nodeId):
        """
        Remove a single node.

        Arguments:
            nodeId  -- Node ID of the item to remove.
        """
        if nodeId in self._nodes:
            nodes = [i for i in self.iterables if isinstance(i, FieldsNode)]
            for node in nodes:
                if node['nodeId'] == nodeId:
                    self.xml.remove(node.xml)
                    self.iterables.remove(node)
                    return True
        return False

    def get_nodes(self):
        """Return all nodes."""
        nodes = []
        for node in self['substanzas']:
            if isinstance(node, FieldsNode):
                nodes.append(node)
        return nodes

    def set_nodes(self, nodes):
        """
        Set or replace all nodes. The given nodes must be in a
        list or set where each item is a tuple of the form:
            (nodeId, sourceId, cacheType)

        Arguments:
            nodes -- A series of nodes in tuple format.
        """
        #print(str(id(self)) + " set_nodes: got " + str(nodes))
        self.del_nodes()
        for node in nodes:
            if isinstance(node, FieldsNode):
                self.add_node(node['nodeId'], node['sourceId'], node['cacheType'], substanzas=node['substanzas'])
            else:
                nodeId, sourceId, cacheType = node
                self.add_node(nodeId, sourceId, cacheType)

    def del_nodes(self):
        """Remove all nodes."""
        self._nodes = set()
        nodes = [i for i in self.iterables if isinstance(i, FieldsNode)]
        for node in nodes:
            self.xml.remove(node.xml)
            self.iterables.remove(node)


class FieldsNode(ElementBase):
    """ Node element in response fields """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'node'
    plugin_attrib = name
    interfaces = {'nodeId','sourceId','cacheType','timestamps'}

    def __init__(self, xml=None, parent=None):
        ElementBase.__init__(self, xml, parent)
        self._timestamps = set()

    def setup(self, xml=None):
        """
        Populate the stanza object using an optional XML object.

        Overrides ElementBase.setup

        Caches item information.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        ElementBase.setup(self, xml)
        self._timestamps = {ts['value'] for ts in self['timestamps']}

    def add_timestamp(self, timestamp, substanzas=None):
        """
        Add a new timestamp element.

        Arguments:
            timestamp  -- The timestamp in ISO format.
        """
        #print(str(id(self)) + " add_timestamp: " + str(timestamp))

        if timestamp not in self._timestamps:
            self._timestamps.add((timestamp))
            ts = Timestamp(parent=self)
            ts['value'] = timestamp
            if not substanzas is None:
                ts.set_datas(substanzas)
                #print("add_timestamp with substanzas: " + str(substanzas))
            self.iterables.append(ts)
            #print(str(id(self)) + " added_timestamp: " + str(id(ts)))
            return ts
        return None

    def del_timestamp(self, timestamp):
        """
        Remove a single timestamp.

        Arguments:
            timestamp  -- timestamp (in ISO format) of the item to remove.
        """
        #print("del_timestamp: ")
        if timestamp in self._timestamps:
            timestamps = [i for i in self.iterables if isinstance(i, Timestamp)]
            for ts in timestamps:
                if ts['value'] == timestamp:
                    self.xml.remove(ts.xml)
                    self.iterables.remove(ts)
                    return True
        return False

    def get_timestamps(self):
        """Return all timestamps."""
        #print(str(id(self)) + " get_timestamps: ")
        timestamps = []
        for timestamp in self['substanzas']:
            if isinstance(timestamp, Timestamp):
                timestamps.append(timestamp)
        return timestamps

    def set_timestamps(self, timestamps):
        """
        Set or replace all timestamps. The given timestamps must be in a
        list or set where each item is a timestamp

        Arguments:
            timestamps -- A series of timestamps.
        """
        #print(str(id(self)) + " set_timestamps: got " + str(timestamps))
        self.del_timestamps()
        for timestamp in timestamps:
            #print("set_timestamps: subset " + str(timestamp))
            #print("set_timestamps: subset.substanzas " + str(timestamp['substanzas']))
            if isinstance(timestamp, Timestamp):
                self.add_timestamp(timestamp['value'], substanzas=timestamp['substanzas'])
            else:
                #print("set_timestamps: got " + str(timestamp))
                self.add_timestamp(timestamp)

    def del_timestamps(self):
        """Remove all timestamps."""
        #print(str(id(self)) + " del_timestamps: ")
        self._timestamps = set()
        timestamps = [i for i in self.iterables if isinstance(i, Timestamp)]
        for timestamp in timestamps:
            self.xml.remove(timestamp.xml)
            self.iterables.remove(timestamp)

class Field(ElementBase):
    """
    Field element in response Timestamp. This is a base class,
    all instances of fields added to Timestamp must be of types:
        DataNumeric
        DataString
        DataBoolean
        DataDateTime
        DataTimeSpan
        DataEnum
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'field'
    plugin_attrib = name
    interfaces = {'name','module','stringIds'}
    interfaces.update(FieldTypes.field_types)
    interfaces.update(FieldStatus.field_status)

    _flags = set()
    _flags.update(FieldTypes.field_types)
    _flags.update(FieldStatus.field_status)

    def set_stringIds(self, value):
        """Verifies stringIds according to regexp from specification XMPP-0323.

        :param value: string
        """

        pattern = re.compile("^\d+([|]\w+([.]\w+)*([|][^,]*)?)?(,\d+([|]\w+([.]\w+)*([|][^,]*)?)?)*$")
        if pattern.match(value) is not None:
            self.xml.stringIds = value
        else:
            # Bad content, add nothing
            pass

        return self

    def _get_flags(self):
        """
        Helper function for getting of flags. Returns all flags in
        dictionary format: { "flag name": "flag value" ... }
        """
        flags = {}
        for f in self._flags:
            if not self[f] == "":
                flags[f] = self[f]
        return flags

    def _set_flags(self, flags):
        """
        Helper function for setting of flags.

        Arguments:
            flags -- Flags in dictionary format: { "flag name": "flag value" ... }
        """
        for f in self._flags:
            if flags is not None and f in flags:
                self[f] = flags[f]
            else:
                self[f] = None

    def _get_typename(self):
        return "invalid type, use subclasses!"


class Timestamp(ElementBase):
    """ Timestamp element in response Node """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'timestamp'
    plugin_attrib = name
    interfaces = {'value','datas'}

    def __init__(self, xml=None, parent=None):
        ElementBase.__init__(self, xml, parent)
        self._datas = set()

    def setup(self, xml=None):
        """
        Populate the stanza object using an optional XML object.

        Overrides ElementBase.setup

        Caches item information.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        ElementBase.setup(self, xml)
        self._datas = {data['name'] for data in self['datas']}

    def add_data(self, typename, name, value, module=None, stringIds=None, unit=None, dataType=None, flags=None):
        """
        Add a new data element.

        Arguments:
            typename   -- The type of data element (numeric, string, boolean, dateTime, timeSpan or enum)
            value      -- The value of the data element
            module     -- [optional] language module to use for the data element
            stringIds  -- [optional] The stringIds used to find associated text in the language module
            unit       -- [optional] The unit. Only applicable for type numeric
            dataType   -- [optional] The dataType. Only applicable for type enum
        """
        if name not in self._datas:
            dataObj = None
            if typename == "numeric":
                dataObj = DataNumeric(parent=self)
                dataObj['unit'] = unit
            elif typename == "string":
                dataObj = DataString(parent=self)
            elif typename == "boolean":
                dataObj = DataBoolean(parent=self)
            elif typename == "dateTime":
                dataObj = DataDateTime(parent=self)
            elif typename == "timeSpan":
                dataObj = DataTimeSpan(parent=self)
            elif typename == "enum":
                dataObj = DataEnum(parent=self)
                dataObj['dataType'] = dataType

            dataObj['name'] = name
            dataObj['value'] = value
            dataObj['module'] = module
            dataObj['stringIds'] = stringIds

            if flags is not None:
                dataObj._set_flags(flags)

            self._datas.add(name)
            self.iterables.append(dataObj)
            return dataObj
        return None

    def del_data(self, name):
        """
        Remove a single data element.

        Arguments:
            data_name  -- The data element name to remove.
        """
        if name in self._datas:
            datas = [i for i in self.iterables if isinstance(i, Field)]
            for data in datas:
                if data['name'] == name:
                    self.xml.remove(data.xml)
                    self.iterables.remove(data)
                    return True
        return False

    def get_datas(self):
        """ Return all data elements. """
        datas = []
        for data in self['substanzas']:
            if isinstance(data, Field):
                datas.append(data)
        return datas

    def set_datas(self, datas):
        """
        Set or replace all data elements. The given elements must be in a
        list or set where each item is a data element (numeric, string, boolean, dateTime, timeSpan or enum)

        Arguments:
            datas -- A series of data elements.
        """
        self.del_datas()
        for data in datas:
            self.add_data(typename=data._get_typename(), name=data['name'], value=data['value'], module=data['module'], stringIds=data['stringIds'], unit=data['unit'], dataType=data['dataType'], flags=data._get_flags())

    def del_datas(self):
        """Remove all data elements."""
        self._datas = set()
        datas = [i for i in self.iterables if isinstance(i, Field)]
        for data in datas:
            self.xml.remove(data.xml)
            self.iterables.remove(data)

class DataNumeric(Field):
    """
    Field data of type numeric.
    Note that the value is expressed as a string.
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'numeric'
    plugin_attrib = name
    interfaces = {'value', 'unit'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "numeric"

class DataString(Field):
    """
    Field data of type string
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'string'
    plugin_attrib = name
    interfaces = {'value'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "string"

class DataBoolean(Field):
    """
    Field data of type boolean.
    Note that the value is expressed as a string.
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'boolean'
    plugin_attrib = name
    interfaces = {'value'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "boolean"

class DataDateTime(Field):
    """
    Field data of type dateTime.
    Note that the value is expressed as a string.
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'dateTime'
    plugin_attrib = name
    interfaces = {'value'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "dateTime"

class DataTimeSpan(Field):
    """
    Field data of type timeSpan.
    Note that the value is expressed as a string.
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'timeSpan'
    plugin_attrib = name
    interfaces = {'value'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "timeSpan"

class DataEnum(Field):
    """
    Field data of type enum.
    Note that the value is expressed as a string.
    """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'enum'
    plugin_attrib = name
    interfaces = {'value', 'dataType'}
    interfaces.update(Field.interfaces)

    def _get_typename(self):
        return "enum"

class Done(ElementBase):
    """ Done element used to signal that all data has been transferred """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'done'
    plugin_attrib = name
    interfaces = {'seqnr'}

class Cancel(ElementBase):
    """ Cancel element used to signal that a request shall be cancelled """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'cancel'
    plugin_attrib = name
    interfaces = {'seqnr'}

class Cancelled(ElementBase):
    """ Cancelled element used to signal that cancellation is confirmed """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'cancelled'
    plugin_attrib = name
    interfaces = {'seqnr'}


register_stanza_plugin(Iq, Request)
register_stanza_plugin(Request, RequestNode, iterable=True)
register_stanza_plugin(Request, RequestField, iterable=True)

register_stanza_plugin(Iq, Accepted)
register_stanza_plugin(Message, Failure)
register_stanza_plugin(Failure, Error)

register_stanza_plugin(Iq, Rejected)

register_stanza_plugin(Message, Fields)
register_stanza_plugin(Fields, FieldsNode, iterable=True)
register_stanza_plugin(FieldsNode, Timestamp, iterable=True)
register_stanza_plugin(Timestamp, Field, iterable=True)
register_stanza_plugin(Timestamp, DataNumeric, iterable=True)
register_stanza_plugin(Timestamp, DataString, iterable=True)
register_stanza_plugin(Timestamp, DataBoolean, iterable=True)
register_stanza_plugin(Timestamp, DataDateTime, iterable=True)
register_stanza_plugin(Timestamp, DataTimeSpan, iterable=True)
register_stanza_plugin(Timestamp, DataEnum, iterable=True)

register_stanza_plugin(Message, Started)

register_stanza_plugin(Iq, Cancel)
register_stanza_plugin(Iq, Cancelled)