diff --git a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py index 955c5e4c06020d..30326f0910303d 100644 --- a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py +++ b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py @@ -13,9 +13,10 @@ # limitations under the License. import logging +from typing import Optional -from matter_idl.matter_idl_types import (Attribute, AttributeQuality, Bitmap, Cluster, ClusterSide, CommandQuality, ConstantEntry, - DataType, Enum, Field, FieldQuality, Idl, Struct, StructTag) +from matter_idl.matter_idl_types import (Attribute, AttributeQuality, Bitmap, Cluster, ClusterSide, Command, CommandQuality, + ConstantEntry, DataType, Enum, Field, FieldQuality, Idl, Struct, StructTag) from .base import BaseHandler, HandledDepth from .context import Context @@ -350,6 +351,7 @@ class CommandHandler(BaseHandler): def __init__(self, context: Context, cluster: Cluster, attrs): super().__init__(context, handled=HandledDepth.SINGLE_TAG) self._cluster = cluster + self._command: Optional[Command] = None # Command information layout: # "response": @@ -388,7 +390,6 @@ def __init__(self, context: Context, cluster: Cluster, attrs): tag=StructTag.REQUEST, ) else: - self._command = None self._struct = Struct( name=NormalizeName(attrs["name"]), fields=[], @@ -422,11 +423,12 @@ def GetNextProcessor(self, name: str, attrs): LOGGER.warn( f"Ignoring invoke privilege for {self._struct.name}") - if "timed" in attrs and attrs["timed"] != "false": - self._command.qualities |= CommandQuality.TIMED_INVOKE + if self._command: + if "timed" in attrs and attrs["timed"] != "false": + self._command.qualities |= CommandQuality.TIMED_INVOKE - if "fabricScoped" in attrs and attrs["fabricScoped"] != "false": - self._command.qualities |= CommandQuality.FABRIC_SCOPED + if "fabricScoped" in attrs and attrs["fabricScoped"] != "false": + self._command.qualities |= CommandQuality.FABRIC_SCOPED return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG) elif name == "field": diff --git a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py index b53a6e3c38fd43..24148e70da328a 100755 --- a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py +++ b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py @@ -27,8 +27,8 @@ os.path.join(os.path.dirname(__file__), '..'))) from matter_idl.data_model_xml import ParseSource, ParseXmls +from matter_idl.matter_idl_parser import CreateParser from matter_idl.matter_idl_types import Idl -from matter_idl_parser import CreateParser def XmlToIdl(what: Union[str, List[str]]) -> Idl: