forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChipCommissionableNodeCtrl.py
100 lines (77 loc) · 3.37 KB
/
ChipCommissionableNodeCtrl.py
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
#
# Copyright (c) 2020-2021 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# @file
# Python interface for ChipCommissionableNodeController
#
"""Chip Commissionable Node Controller interface
"""
from __future__ import absolute_import, print_function
from ctypes import CDLL, POINTER, c_void_p, pointer
from typing import Any
from .ChipStack import ChipStack
from .native import PyChipError
__all__ = ["ChipCommissionableNodeController"]
def _singleton(cls):
instance = [None]
def wrapper(*args, **kwargs):
if instance[0] is None:
instance[0] = cls(*args, **kwargs)
return instance[0]
return wrapper
@_singleton
class ChipCommissionableNodeController(object):
def __init__(self, chipStack: ChipStack):
self.commissionableNodeCtrl = None
self._ChipStack = chipStack
self._dmLib: Any = None
self._InitLib()
commissionableNodeCtrl = c_void_p(None)
self._dmLib.pychip_CommissionableNodeController_NewController(
pointer(commissionableNodeCtrl)).raise_on_error()
self.commissionableNodeCtrl = commissionableNodeCtrl
self._ChipStack.commissionableNodeCtrl = commissionableNodeCtrl
def __del__(self):
if self.commissionableNodeCtrl is not None:
self._dmLib.pychip_CommissionableNodeController_DeleteController(
self.commissionableNodeCtrl)
self.commissionableNodeCtrl = None
def PrintDiscoveredCommissioners(self):
self._ChipStack.Call(
lambda: self._dmLib.pychip_CommissionableNodeController_PrintDiscoveredCommissioners(
self.commissionableNodeCtrl)
)
def DiscoverCommissioners(self):
self._ChipStack.Call(
lambda: self._dmLib.pychip_CommissionableNodeController_DiscoverCommissioners(
self.commissionableNodeCtrl)
).raise_on_error()
# ----- Private Members -----
def _InitLib(self):
if self._dmLib is None:
self._dmLib = CDLL(self._ChipStack.LocateChipDLL())
self._dmLib.pychip_CommissionableNodeController_NewController.argtypes = [
POINTER(c_void_p)]
self._dmLib.pychip_CommissionableNodeController_NewController.restype = PyChipError
self._dmLib.pychip_CommissionableNodeController_DeleteController.argtypes = [
c_void_p]
self._dmLib.pychip_CommissionableNodeController_DeleteController.restype = PyChipError
self._dmLib.pychip_CommissionableNodeController_DiscoverCommissioners.argtypes = [
c_void_p]
self._dmLib.pychip_CommissionableNodeController_DiscoverCommissioners.restype = PyChipError
self._dmLib.pychip_CommissionableNodeController_PrintDiscoveredCommissioners.argtypes = [
c_void_p]