2 # Copyright (c) 2021 Project CHIP Authors
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 "InvalidArgumentCount",
23 "InvalidArgumentType",
30 class ChipStackException(Exception):
34 class ChipStackError(ChipStackException):
35 def __init__(self, err, msg=None):
37 self.msg = msg if msg else "Chip Stack Error %d" % err
43 class DeviceError(ChipStackException):
44 def __init__(self, profileId, statusCode, systemErrorCode, msg=None):
45 self.profileId = profileId
46 self.statusCode = statusCode
47 self.systemErrorCode = systemErrorCode
49 self.msg = "[ %08X:%d ]" % (profileId, statusCode)
51 self.msg += " (system err %d)" % systemErrorCode
56 return "Device Error: " + self.msg
59 class ClusterError(ChipStackException):
63 class InvalidArgumentCount(ChipStackException):
64 def __init__(self, expect: int, given: int):
69 return "InvalidArgumentCount: Expect {}, {} given".format(self.expect, self.given)
72 class InvalidArgumentType(ChipStackException):
73 def __init__(self, expect: type, given: type, name: str):
79 return "InvalidArgumentType: Argument {} should be {}, {} got".format(self.argname, self.expect, self.given)
82 class UnknownCluster(ClusterError):
83 def __init__(self, cluster: str):
84 self.cluster = cluster
87 return "UnknownCluster: {}".format(self.cluster)
90 class UnknownCommand(ClusterError):
91 def __init__(self, cluster: str, command: str):
92 self.cluster = cluster
93 self.command = command
96 return "UnknownCommand: cluster: {}, command: {}".format(self.cluster, self.command)
99 class UnknownAttribute(ClusterError):
100 def __init__(self, cluster: str, attribute: str):
101 self.cluster = cluster
102 self.attribute = attribute
105 return "UnknownAttribute: cluster: {}, attribute: {}".format(self.cluster, self.attribute)