Skip to content

Commit

Permalink
Merge pull request #20 from chip-csg/csg/feature/qr-code-validation
Browse files Browse the repository at this point in the history
Csg/feature/qr code validation
  • Loading branch information
Xiole-KKE authored Jun 1, 2021
2 parents 2ac9e00 + 1593600 commit ba381d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
from enum import Enum
from typing import Any, Dict,Optional

from enum import Enum
from typing import Any, Dict,Optional
# Extend sys.path with one or more directories, relative to the location of the
# running script, in which the chip package might be found . This makes it
# possible to run the device manager shell from a non-standard install location,
Expand Down Expand Up @@ -732,6 +734,12 @@ def ip_connect(ip_address: string, pin_code: int, node_id: int) -> Dict[str, Any
except Exception as e:
return __get_response_dict(status = StatusCodeEnum.FAILED, error = str(e))

def qr_code_parse(qr_code):
try:
result = SetupPayload().ParseQrCode(qr_code).Dictionary()
return __get_response_dict(status = StatusCodeEnum.SUCCESS, result = result)
except Exception as e:
return __get_response_dict(status = StatusCodeEnum.FAILED, error = str(e))

def start_rpc_server():
with SimpleXMLRPCServer(("0.0.0.0", 5000), allow_none=True) as server:
Expand All @@ -742,6 +750,7 @@ def start_rpc_server():
server.register_function(zcl_add_network)
server.register_function(zcl_enable_network)
server.register_function(resolve)
server.register_function(qr_code_parse)
server.register_multicall_functions()
print('Serving XML-RPC on localhost port 5000')
try:
Expand Down
9 changes: 9 additions & 0 deletions src/controller/python/chip/setup_payload/setup_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ def __InitNativeFunctions(self, chipLib):
setter.Set("pychip_SetupPayload_ParseManualPairingCode",
c_int32,
[c_char_p, SetupPayload.AttributeVisitor, SetupPayload.VendorAttributeVisitor])

######----------------------------------------------------------------------------------------######

def Dictionary(self):
payload_dict = {}
attributes_array = self.attributes + self.vendor_attributes
for name, value in attributes_array:
payload_dict[name] = value
return payload_dict

0 comments on commit ba381d0

Please sign in to comment.