forked from OpenZWave/python-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
executable file
·1132 lines (887 loc) · 40.9 KB
/
controller.py
File metadata and controls
executable file
·1132 lines (887 loc) · 40.9 KB
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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
.. module:: openzwave.controller
.. _openzwaveController:
This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.
:platform: Unix, Windows, MacOS X
:sinopsis: openzwave API
.. moduleauthor: bibi21000 aka Sébastien GALLET <bibi21000@gmail.com>
License : GPL(v3)
**python-openzwave** is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
**python-openzwave** is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with python-openzwave. If not, see http://www.gnu.org/licenses.
"""
import sys
import six
if six.PY3:
from pydispatch import dispatcher
else:
from louie import dispatcher
from openzwave.object import ZWaveObject, deprecated
from libopenzwave import PyStatDriver
import threading
# Set default logging handler to avoid "No handler found" warnings.
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
"""NullHandler logger for python 2.6"""
def emit(self, record):
pass
logger = logging.getLogger('openzwave')
logger.addHandler(NullHandler())
class ZWaveController(ZWaveObject):
'''
The controller manager.
Allows to retrieve informations about the library, statistics, ...
Also used to send commands to the controller
Commands :
- Driver::ControllerCommand_AddController : Add a new secondary controller to the Z-Wave network.
- Driver::ControllerCommand_AddDevice : Add a new device (but not a controller) to the Z-Wave network.
- Driver::ControllerCommand_CreateNewPrimary : (Not yet implemented)
- Driver::ControllerCommand_ReceiveConfiguration :
- Driver::ControllerCommand_RemoveController : remove a controller from the Z-Wave network.
- Driver::ControllerCommand_RemoveDevice : remove a device (but not a controller) from the Z-Wave network.
- Driver::ControllerCommand_RemoveFailedNode : move a node to the controller's list of failed nodes. The node must actually
have failed or have been disabled since the command will fail if it responds. A node must be in the controller's failed nodes list
or ControllerCommand_ReplaceFailedNode to work.
- Driver::ControllerCommand_HasNodeFailed : Check whether a node is in the controller's failed nodes list.
- Driver::ControllerCommand_ReplaceFailedNode : replace a failed device with another. If the node is not in
the controller's failed nodes list, or the node responds, this command will fail.
- Driver:: ControllerCommand_TransferPrimaryRole : (Not yet implemented) - Add a new controller to the network and
make it the primary. The existing primary will become a secondary controller.
- Driver::ControllerCommand_RequestNetworkUpdate : Update the controller with network information from the SUC/SIS.
- Driver::ControllerCommand_RequestNodeNeighborUpdate : Get a node to rebuild its neighbour list. This method also does ControllerCommand_RequestNodeNeighbors afterwards.
- Driver::ControllerCommand_AssignReturnRoute : Assign a network return route to a device.
- Driver::ControllerCommand_DeleteAllReturnRoutes : Delete all network return routes from a device.
- Driver::ControllerCommand_CreateButton : Create a handheld button id.
- Driver::ControllerCommand_DeleteButton : Delete a handheld button id.
Callbacks :
- Driver::ControllerState_Waiting : The controller is waiting for a user action. A notice should be displayed
to the user at this point, telling them what to do next.
For the add, remove, replace and transfer primary role commands, the user needs to be told to press the
inclusion button on the device that is going to be added or removed. For ControllerCommand_ReceiveConfiguration,
they must set their other controller to send its data, and for ControllerCommand_CreateNewPrimary, set the other
controller to learn new data.
- Driver::ControllerState_InProgress : the controller is in the process of adding or removing the chosen node. It is now too late to cancel the command.
- Driver::ControllerState_Complete : the controller has finished adding or removing the node, and the command is complete.
- Driver::ControllerState_Failed : will be sent if the command fails for any reason.
'''
#@deprecated
SIGNAL_CTRL_NORMAL = 'Normal'
#@deprecated
SIGNAL_CTRL_STARTING = 'Starting'
#@deprecated
SIGNAL_CTRL_CANCEL = 'Cancel'
#@deprecated
SIGNAL_CTRL_ERROR = 'Error'
#@deprecated
SIGNAL_CTRL_WAITING = 'Waiting'
#@deprecated
SIGNAL_CTRL_SLEEPING = 'Sleeping'
#@deprecated
SIGNAL_CTRL_INPROGRESS = 'InProgress'
#@deprecated
SIGNAL_CTRL_COMPLETED = 'Completed'
#@deprecated
SIGNAL_CTRL_FAILED = 'Failed'
#@deprecated
SIGNAL_CTRL_NODEOK = 'NodeOK'
#@deprecated
SIGNAL_CTRL_NODEFAILED = 'NodeFailed'
STATE_NORMAL = 'Normal'
STATE_STARTING = 'Starting'
STATE_CANCEL = 'Cancel'
STATE_ERROR = 'Error'
STATE_WAITING = 'Waiting'
STATE_SLEEPING = 'Sleeping'
STATE_INPROGRESS = 'InProgress'
STATE_COMPLETED = 'Completed'
STATE_FAILED = 'Failed'
STATE_NODEOK = 'NodeOK'
STATE_NODEFAILED = 'NodeFailed'
#@deprecated
SIGNAL_CONTROLLER = 'Message'
SIGNAL_CONTROLLER_STATS = 'ControllerStats'
#@deprecated
CMD_NONE = 0
#@deprecated
CMD_ADDDEVICE = 1
#@deprecated
CMD_CREATENEWPRIMARY = 2
#@deprecated
CMD_RECEIVECONFIGURATION = 3
#@deprecated
CMD_REMOVEDEVICE = 4
#@deprecated
CMD_REMOVEFAILEDNODE = 5
#@deprecated
CMD_HASNODEFAILED = 6
#@deprecated
CMD_REPLACEFAILEDNODE = 7
#@deprecated
CMD_TRANSFERPRIMARYROLE = 8
#@deprecated
CMD_REQUESTNETWORKUPDATE = 9
#@deprecated
CMD_REQUESTNODENEIGHBORUPDATE = 10
#@deprecated
CMD_ASSIGNRETURNROUTE = 11
#@deprecated
CMD_DELETEALLRETURNROUTES = 12
#@deprecated
CMD_SENDNODEINFORMATION = 13
#@deprecated
CMD_REPLICATIONSEND = 14
#@deprecated
CMD_CREATEBUTTON = 15
#@deprecated
CMD_DELETEBUTTON = 16
def __init__(self, controller_id, network, options=None):
"""
Initialize controller object
:param controller_id: The Id of the controller
:type controller_id: int
:param network: The network the controller is attached to
:type network: ZwaveNetwork
:param options: options of the manager
:type options: str
"""
if controller_id is None:
controller_id = 1
ZWaveObject.__init__(self, controller_id, network)
self._node = None
self._options = options
self._library_type_name = None
self._library_version = None
self._python_library_version = None
self.ctrl_last_state = self.SIGNAL_CTRL_NORMAL
self.ctrl_last_message = ""
self._timer_statistics = None
self._interval_statistics = 0.0
def stop(self):
"""
Stop the controller and all this threads.
"""
self.cancel_command()
if self._timer_statistics is not None:
self._timer_statistics.cancel()
for i in range(0, 60):
if self.send_queue_count <= 0:
break
else:
try:
self._network.network_event.wait(1.0)
except AssertionError:
#For gevent AssertionError: Impossible to call blocking function in the event loop callback
pass
logger.debug("Wait for empty send_queue during %s second(s).", i)
def __str__(self):
"""
The string representation of the node.
:rtype: str
"""
node_name = ""
product_name = ""
if self._node is not None:
node_name = self._node.name
product_name = self._node.product_name
return 'home_id: [%s] id: [%s] name: [%s] product: [%s] capabilities: %s library: [%s]' % \
(self._network.home_id_str, self._object_id, node_name, product_name, self.capabilities, self.library_description)
@property
def node(self):
"""
The node controller on the network.
:return: The node controller on the network
:rtype: ZWaveNode
"""
return self._node
@node.setter
def node(self, value):
"""
The node controller on the network.
:param value: The node of the controller on the network
:type value: ZWaveNode
"""
self._node = value
@property
def node_id(self):
"""
The node Id of the controller on the network.
:return: The node id of the controller on the network
:rtype: int
"""
if self.node is not None:
return self.node.object_id
else:
return None
@property
def name(self):
"""
The node name of the controller on the network.
:return: The node's name of the controller on the network
:rtype: str
"""
if self.node is not None:
return self.node.name
else:
return None
@property
def library_type_name(self):
"""
The name of the library.
:return: The cpp library name
:rtype: str
"""
return self._network.manager.getLibraryTypeName(self._network.home_id)
@property
def library_description(self):
"""
The description of the library.
:return: The library description (name and version)
:rtype: str
"""
return '%s version %s' % (self.library_type_name, self.library_version)
@property
def library_version(self):
"""
The version of the library.
:return: The cpp library version
:rtype: str
"""
return self._network.manager.getLibraryVersion(self._network.home_id)
@property
def python_library_version(self):
"""
The version of the python library.
:return: The python library version
:rtype: str
"""
return self._network.manager.getPythonLibraryVersionNumber()
@property
def ozw_library_version(self):
"""
The version of the openzwave library.
:return: The openzwave library version
:rtype: str
"""
return self._network.manager.getOzwLibraryVersion()
@property
def library_config_path(self):
"""
The library Config path.
:return: The library config directory
:rtype: str
"""
if self._options is not None:
return self._options.config_path
else:
return None
@property
def library_user_path(self):
"""
The library User path.
:return: The user directory to store user configuration
:rtype: str
"""
if self._options is not None:
return self._options.user_path
else:
return None
@property
def device(self):
"""
The device path.
:return: The device (ie /dev/zwave)
:rtype: str
"""
if self._options is not None:
return self._options.device
else:
return None
@property
def options(self):
"""
The starting options of the manager.
:return: The options used to start the manager
:rtype: ZWaveOption
"""
return self._options
@property
def stats(self):
"""
Retrieve statistics from driver.
Statistics:
* s_SOFCnt : Number of SOF bytes received
* s_ACKWaiting : Number of unsolicited messages while waiting for an ACK
* s_readAborts : Number of times read were aborted due to timeouts
* s_badChecksum : Number of bad checksums
* s_readCnt : Number of messages successfully read
* s_writeCnt : Number of messages successfully sent
* s_CANCnt : Number of CAN bytes received
* s_NAKCnt : Number of NAK bytes received
* s_ACKCnt : Number of ACK bytes received
* s_OOFCnt : Number of bytes out of framing
* s_dropped : Number of messages dropped & not delivered
* s_retries : Number of messages retransmitted
* s_controllerReadCnt : Number of controller messages read
* s_controllerWriteCnt : Number of controller messages sent
:return: Statistics of the controller
:rtype: dict()
"""
return self._network.manager.getDriverStatistics(self.home_id)
def get_stats_label(self, stat):
"""
Retrieve label of the statistic from driver.
:param stat: The code of the stat label to retrieve.
:type stat:
:return: The label or the stat.
:rtype: str
"""
#print "stat = %s" % stat
return PyStatDriver[stat]
def do_poll_statistics(self):
"""
Timer based polling system for statistics
"""
self._timer_statistics = None
stats = self.stats
dispatcher.send(self.SIGNAL_CONTROLLER_STATS, \
**{'controller':self, 'stats':stats})
self._timer_statistics = threading.Timer(self._interval_statistics, self.do_poll_statistics)
self._timer_statistics.start()
@property
def poll_stats(self):
"""
The interval for polling statistics
:return: The interval in seconds
:rtype: float
"""
return self._interval_statistics
@poll_stats.setter
def poll_stats(self, value):
"""
The interval for polling statistics
:return: The interval in seconds
:rtype: ZWaveNode
:param value: The interval in seconds
:type value: float
"""
if value != self._interval_statistics:
if self._timer_statistics is not None:
self._timer_statistics.cancel()
if value != 0:
self._interval_statistics = value
self._timer_statistics = threading.Timer(self._interval_statistics, self.do_poll_statistics)
self._timer_statistics.start()
@property
def capabilities(self):
"""
The capabilities of the controller.
:return: The capabilities of the controller
:rtype: set
"""
caps = set()
if self.is_primary_controller:
caps.add('primaryController')
if self.is_static_update_controller:
caps.add('staticUpdateController')
if self.is_bridge_controller:
caps.add('bridgeController')
return caps
@property
def is_primary_controller(self):
"""
Is this node a primary controller of the network.
:rtype: bool
"""
return self._network.manager.isPrimaryController(self.home_id)
@property
def is_static_update_controller(self):
"""
Is this controller a static update controller (SUC).
:rtype: bool
"""
return self._network.manager.isStaticUpdateController(self.home_id)
@property
def is_bridge_controller(self):
"""
Is this controller using the bridge controller library.
:rtype: bool
"""
return self._network.manager.isBridgeController(self.home_id)
@property
def send_queue_count(self):
"""
Get count of messages in the outgoing send queue.
:return: The count of messages in the outgoing send queue.
:rtype: int
"""
if self.home_id is not None:
return self._network.manager.getSendQueueCount(self.home_id)
return -1
def hard_reset(self):
"""
Hard Reset a PC Z-Wave Controller.
Resets a controller and erases its network configuration settings.
The controller becomes a primary controller ready to add devices to a new network.
This command fires a lot of louie signals.
Louie's clients must disconnect from nodes and values signals
.. code-block:: python
dispatcher.send(self._network.SIGNAL_NETWORK_RESETTED, **{'network': self._network})
"""
self._network.state = self._network.STATE_RESETTED
dispatcher.send(self._network.SIGNAL_NETWORK_RESETTED, \
**{'network':self._network})
self._network.manager.resetController(self._network.home_id)
try:
self.network.network_event.wait(5.0)
except AssertionError:
#For gevent AssertionError: Impossible to call blocking function in the event loop callback
pass
def soft_reset(self):
"""
Soft Reset a PC Z-Wave Controller.
Resets a controller without erasing its network configuration settings.
"""
self._network.manager.softResetController(self.home_id)
@deprecated
def begin_command_send_node_information(self, node_id):
"""
Send a node information frame.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_SENDNODEINFORMATION, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_replication_send(self, high_power=False):
"""
Send information from primary to secondary.
:param high_power: Usually when adding or removing devices, the controller operates at low power so that the controller must
be physically close to the device for security reasons. If _highPower is true, the controller will
operate at normal power levels instead. Defaults to false.
:type high_power: bool
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REPLICATIONSEND, self.zwcallback, highPower=high_power)
@deprecated
def begin_command_request_network_update(self):
"""
Update the controller with network information from the SUC/SIS.
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REQUESTNETWORKUPDATE, self.zwcallback)
@deprecated
def begin_command_add_device(self, high_power=False):
"""
Add a new device to the Z-Wave network.
:param high_power: Used only with the AddDevice, AddController, RemoveDevice and RemoveController commands.
Usually when adding or removing devices, the controller operates at low power so that the controller must
be physically close to the device for security reasons. If _highPower is true, the controller will
operate at normal power levels instead. Defaults to false.
:type high_power: bool
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_ADDDEVICE, self.zwcallback, highPower=high_power)
@deprecated
def begin_command_remove_device(self, high_power=False):
"""
Remove a device from the Z-Wave network.
:param high_power: Used only with the AddDevice, AddController, RemoveDevice and RemoveController commands.
Usually when adding or removing devices, the controller operates at low power so that the controller must
be physically close to the device for security reasons. If _highPower is true, the controller will
operate at normal power levels instead. Defaults to false.
:type high_power: bool
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REMOVEDEVICE, self.zwcallback, highPower=high_power)
@deprecated
def begin_command_remove_failed_node(self, node_id):
"""
Move a node to the controller's list of failed nodes. The node must
actually have failed or have been disabled since the command
will fail if it responds. A node must be in the controller's
failed nodes list for ControllerCommand_ReplaceFailedNode to work.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REMOVEFAILEDNODE, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_has_node_failed(self, node_id):
"""
Check whether a node is in the controller's failed nodes list.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_HASNODEFAILED, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_replace_failed_node(self, node_id):
"""
Replace a failed device with another. If the node is not in
the controller's failed nodes list, or the node responds, this command will fail.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REPLACEFAILEDNODE, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_request_node_neigbhor_update(self, node_id):
"""
Get a node to rebuild its neighbors list.
This method also does ControllerCommand_RequestNodeNeighbors afterwards.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_REQUESTNODENEIGHBORUPDATE, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_create_new_primary(self):
"""
Add a new controller to the Z-Wave network. Used when old primary fails. Requires SUC.
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_CREATENEWPRIMARY, self.zwcallback)
@deprecated
def begin_command_transfer_primary_role(self, high_power=False):
"""
Make a different controller the primary.
The existing primary will become a secondary controller.
:param high_power: Used only with the AddDevice, AddController, RemoveDevice and RemoveController commands.
Usually when adding or removing devices, the controller operates at low power so that the controller must
be physically close to the device for security reasons. If _highPower is true, the controller will
operate at normal power levels instead. Defaults to false.
:type high_power: bool
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_TRANSFERPRIMARYROLE, self.zwcallback, highPower=high_power)
@deprecated
def begin_command_receive_configuration(self):
"""
-
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_RECEIVECONFIGURATION, self.zwcallback)
@deprecated
def begin_command_assign_return_route(self, from_node_id, to_node_id):
"""
Assign a network return route from a node to another one.
:param from_node_id: The node that we will use the route.
:type from_node_id: int
:param to_node_id: The node that we will change the route
:type to_node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_ASSIGNRETURNROUTE, self.zwcallback, nodeId=from_node_id, arg=to_node_id)
@deprecated
def begin_command_delete_all_return_routes(self, node_id):
"""
Delete all network return routes from a device.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_DELETEALLRETURNROUTES, self.zwcallback, nodeId=node_id)
@deprecated
def begin_command_create_button(self, node_id, arg=0):
"""
Create a handheld button id
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:param arg:
:type arg: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_CREATEBUTTON, self.zwcallback, nodeId=node_id, arg=arg)
@deprecated
def begin_command_delete_button(self, node_id, arg=0):
"""
Delete a handheld button id.
:param node_id: Used only with the ReplaceFailedNode command, to specify the node that is going to be replaced.
:type node_id: int
:param arg:
:type arg: int
:return: True if the command was accepted and has started.
:rtype: bool
"""
return self._network.manager.beginControllerCommand(self.home_id, \
self.CMD_DELETEBUTTON, self.zwcallback, nodeId=node_id, arg=arg)
def cancel_command(self):
"""
Cancels any in-progress command running on a controller.
"""
if self.home_id is not None:
return self._network.manager.cancelControllerCommand(self.home_id)
return False
@deprecated
def zwcallback(self, args):
"""
The Callback Handler used when sendig commands to the controller.
Dispatch a louie message.
To do : add node in signal when necessary
:param args: A dict containing informations about the state of the controller
:type args: dict()
"""
logger.debug('Controller state change : %s', args)
state = args['state']
message = args['message']
self.ctrl_last_state = state
self.ctrl_last_message = message
if state == self.SIGNAL_CTRL_WAITING:
dispatcher.send(self.SIGNAL_CTRL_WAITING, \
**{'state': state, 'message': message, 'network': self._network, 'controller': self})
dispatcher.send(self.SIGNAL_CONTROLLER, \
**{'state': state, 'message': message, 'network': self._network, 'controller': self})
def to_dict(self, extras=['all']):
"""Return a dict representation of the controller.
:param extras: The extra inforamtions to add
:type extras: []
:returns: A dict
:rtype: dict()
"""
ret = self.node.to_dict(extras=extras)
if 'all' in extras:
extras = ['kvals', 'capabilities', 'neighbors']
if 'capabilities' in extras:
ret['capabilities'].update(dict.fromkeys(self.capabilities, 0))
ret["zw_version"] = self.library_version
ret["zw_description"] = self.library_description
ret["oz_version"] = self.ozw_library_version
ret["py_version"] = self.python_library_version
return ret
def create_new_primary(self):
'''Create a new primary controller when old primary fails. Requires SUC.
This command creates a new Primary Controller when the Old Primary has Failed. Requires a SUC on the network to function.
Results of the CreateNewPrimary Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s', 'create_new_primary')
return self._network.manager.createNewPrimary(self.home_id)
def transfer_primary_role(self):
'''
Add a new controller to the network and make it the primary.
The existing primary will become a secondary controller.
Results of the TransferPrimaryRole Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s', 'transfer_primary_role')
return self._network.manager.transferPrimaryRole(self.home_id)
def receive_configuration(self):
'''Receive network configuration information from primary controller. Requires secondary.
This command prepares the controller to recieve Network Configuration from a Secondary Controller.
Results of the ReceiveConfiguration Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s', 'receive_configuration')
return self._network.manager.receiveConfiguration(self.home_id)
def add_node(self, doSecurity=False):
'''Start the Inclusion Process to add a Node to the Network.
The Status of the Node Inclusion is communicated via Notifications. Specifically, you should
monitor ControllerCommand Notifications.
Results of the AddNode Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:param doSecurity: Whether to initialize the Network Key on the device if it supports the Security CC
:type doSecurity: bool
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s, : secure : %s', 'add_node', doSecurity)
return self._network.manager.addNode(self.home_id, doSecurity)
def remove_node(self):
'''Remove a Device from the Z-Wave Network
The Status of the Node Removal is communicated via Notifications. Specifically, you should
monitor ControllerCommand Notifications.
Results of the RemoveNode Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:param doSecurity: Whether to initialize the Network Key on the device if it supports the Security CC
:type doSecurity: bool
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s', 'remove_node')
return self._network.manager.removeNode(self.home_id)
def remove_failed_node(self, nodeid):
'''Remove a Failed Device from the Z-Wave Network
This Command will remove a failed node from the network. The Node should be on the Controllers Failed
Node List, otherwise this command will fail. You can use the HasNodeFailed function below to test if the Controller
believes the Node has Failed.
The Status of the Node Removal is communicated via Notifications. Specifically, you should
monitor ControllerCommand Notifications.
Results of the RemoveFailedNode Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:param nodeId: The ID of the node to query.
:type nodeId: int
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s, : node : %s', 'remove_failed_node', nodeid)
return self._network.manager.removeFailedNode(self.home_id, nodeid)
def has_node_failed(self, nodeid):
'''Check if the Controller Believes a Node has Failed.
This is different from the IsNodeFailed call in that we test the Controllers Failed Node List, whereas the IsNodeFailed is testing
our list of Failed Nodes, which might be different.
The Results will be communicated via Notifications. Specifically, you should monitor the ControllerCommand notifications
:param nodeId: The ID of the node to query.
:type nodeId: int
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s, : node : %s', 'has_node_failed', nodeid)
return self._network.manager.hasNodeFailed(self.home_id, nodeid)
def request_node_neighbor_update(self, nodeid):
'''Ask a Node to update its Neighbor Tables
This command will ask a Node to update its Neighbor Tables.
Results of the RequestNodeNeighborUpdate Command will be send as a Notification with the Notification type as
Notification::Type_ControllerCommand
:param nodeId: The ID of the node to query.
:type nodeId: int
:return: True if the request was sent successfully.
:rtype: bool
'''
logger.debug('Send controller command : %s, : node : %s', 'request_node_neighbor_update', nodeid)
return self._network.manager.requestNodeNeighborUpdate(self.home_id, nodeid)
def assign_return_route(self, nodeid):
'''Ask a Node to update its update its Return Route to the Controller
This command will ask a Node to update its Return Route to the Controller
Results of the AssignReturnRoute Command will be send as a Notification with the Notification type as