Skip to content

Commit

Permalink
[python] Add zclwrite command for writing attributes (#7672)
Browse files Browse the repository at this point in the history
* [python] Add zclwrite command for writing attributes

* fix typo

* Run codegen
  • Loading branch information
erjiaqing authored and pull[bot] committed Jul 9, 2021
1 parent 2e27454 commit 1295288
Show file tree
Hide file tree
Showing 8 changed files with 2,058 additions and 379 deletions.
34 changes: 32 additions & 2 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def do_zclread(self, line):
elif len(args) == 2 and args[0] == '?':
if args[1] not in all_attrs:
raise exceptions.UnknownCluster(args[1])
print('\n'.join(all_attrs.get(args[1])))
print('\n'.join(all_attrs.get(args[1]).keys()))
elif len(args) == 5:
if args[0] not in all_attrs:
raise exceptions.UnknownCluster(args[0])
Expand All @@ -644,6 +644,35 @@ def do_zclread(self, line):
print("An exception occurred during processing input:")
print(str(ex))

def do_zclwrite(self, line):
"""
To write ZCL attribute:
zclwrite <cluster> <attribute> <nodeid> <endpoint> <groupid> <value>
"""
try:
args = shlex.split(line)
all_attrs = self.devCtrl.ZCLAttributeList()
if len(args) == 1 and args[0] == '?':
print('\n'.join(all_attrs.keys()))
elif len(args) == 2 and args[0] == '?':
if args[1] not in all_attrs:
raise exceptions.UnknownCluster(args[1])
cluster_attrs = all_attrs.get(args[1], {})
print('\n'.join(["{}: {}".format(key, cluster_attrs[key]["type"]) for key in cluster_attrs.keys() if cluster_attrs[key].get("writable", False)]))
elif len(args) == 6:
if args[0] not in all_attrs:
raise exceptions.UnknownCluster(args[0])
self.devCtrl.ZCLWriteAttribute(args[0], args[1], int(
args[2]), int(args[3]), int(args[4]), args[5])
else:
self.do_help("zclwrite")
except exceptions.ChipStackException as ex:
print("An exception occurred during writing ZCL attribute:")
print(str(ex))
except Exception as ex:
print("An exception occurred during processing input:")
print(str(ex))

def do_zclconfigure(self, line):
"""
To configure ZCL attribute reporting:
Expand All @@ -657,7 +686,8 @@ def do_zclconfigure(self, line):
elif len(args) == 2 and args[0] == '?':
if args[1] not in all_attrs:
raise exceptions.UnknownCluster(args[1])
print('\n'.join(all_attrs.get(args[1])))
cluster_attrs = all_attrs.get(args[1], {})
print('\n'.join([key for key in cluster_attrs.keys() if cluster_attrs[key].get("reportable", False)]))
elif len(args) == 7:
if args[0] not in all_attrs:
raise exceptions.UnknownCluster(args[0])
Expand Down
11 changes: 11 additions & 0 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ def ZCLReadAttribute(self, cluster, attribute, nodeid, endpoint, groupid, blocki
res = self._Cluster.ReadAttribute(
device, cluster, attribute, endpoint, groupid, False)

def ZCLWriteAttribute(self, cluster, attribute, nodeid, endpoint, groupid, value, blocking=True):
device = c_void_p(None)
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceByNodeId(
self.devCtrl, nodeid, pointer(device)))
if res != 0:
raise self._ChipStack.ErrorToException(res)

# We are not using IM for Attributes.
res = self._Cluster.WriteAttribute(
device, cluster, attribute, endpoint, groupid, value, False)

def ZCLConfigureAttribute(self, cluster, attribute, nodeid, endpoint, minInterval, maxInterval, change, blocking=True):
device = c_void_p(None)
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceByNodeId(
Expand Down
398 changes: 398 additions & 0 deletions src/controller/python/chip/clusters/CHIPClusters.cpp

Large diffs are not rendered by default.

Loading

0 comments on commit 1295288

Please sign in to comment.