Skip to content

Commit

Permalink
Code review comments resolved.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirav Shah authored and doublemis1 committed Jun 28, 2021
1 parent e8ab4f6 commit f1eedfa
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from chip.ChipBleUtility import FAKE_CONN_OBJ_VALUE
from chip.setup_payload import SetupPayload
from xmlrpc.server import SimpleXMLRPCServer

from enum import Enum
from typing import Any, Dict,Optional
# Extend sys.path with one or more directories, relative to the location of the
Expand Down Expand Up @@ -73,11 +74,17 @@
elif sys.platform.startswith('linux'):
from chip.ChipBluezMgr import BluezManager as BleManager

# The exceptions for CHIP Device Controller CLI
class StatusCodeEnum(Enum):
SUCCESS = 0
FAILED = 1

class RPCResponseKeyEnum(Enum):
STATUS = "status"
RESULT = "result"
ERROR = "error"

# The exceptions for CHIP Device Controller CLI

class ChipDevCtrlException(exceptions.ChipStackException):
pass

Expand Down Expand Up @@ -734,7 +741,7 @@ def echo_alive(message):
print(message)
return message

def resolve(fabric_id: int, node_id: int) -> str:
def resolve(fabric_id: int, node_id: int) -> Dict[str, Any]:
try:
__check_supported_os()
err = device_manager.devCtrl.ResolveNode(fabric_id, node_id)
Expand Down Expand Up @@ -771,19 +778,13 @@ def start_rpc_server():
print("\nKeyboard interrupt received, exiting.")
sys.exit(0)

def __get_response_dict(status: StatusCodeEnum, result: Optional[Dict[Any, Any]] = None, error:Optional[str] = None) -> Dict [Any, Any]:
if error is not None:
return { "status" : status.value, "error" :f'Unable to connect due to exception {error}' }
else:
if result is not None:
return { "status" : status.value, "result": result}
else:
return { "status" : status.value}
def __get_response_dict(status: StatusCodeEnum, result: Optional[Dict[Any, Any]] = None, error:Optional[str] = None) -> Dict [str, Any]:
return { RPCResponseKeyEnum.STATUS.value : status.value, RPCResponseKeyEnum.RESULT.value : result, RPCResponseKeyEnum.ERROR.value : error }

def __check_supported_os()-> bool:
if platform.system() == 'Darwin':
if platform.system().lower() == 'darwin':
raise Exception(platform.system() + " not supported")
elif sys.platform.startswith('linux'):
elif sys.platform.lower().startswith('linux'):
return True

raise Exception("OS Not Supported")
Expand Down

0 comments on commit f1eedfa

Please sign in to comment.