diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index e1472b43aa5cf0..34e2bb1992c851 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -4297,6 +4297,8 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; + emits event AccessControlExtensionChanged; callback attribute acl; callback attribute extension; callback attribute subjectsPerAccessControlEntry default = 4; @@ -4307,6 +4309,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -4332,6 +4337,9 @@ endpoint 0 { } server cluster OtaSoftwareUpdateRequestor { + emits event StateTransition; + emits event VersionApplied; + emits event DownloadError; callback attribute defaultOTAProviders; ram attribute updatePossible default = 1; ram attribute updateState; @@ -4410,6 +4418,10 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event HardwareFaultChange; + emits event RadioFaultChange; + emits event NetworkFaultChange; + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute upTime; @@ -4427,6 +4439,7 @@ endpoint 0 { } server cluster SoftwareDiagnostics { + emits event SoftwareFault; callback attribute threadMetrics; callback attribute currentHeapFree; callback attribute currentHeapUsed; @@ -4436,6 +4449,8 @@ endpoint 0 { } server cluster ThreadNetworkDiagnostics { + emits event ConnectionStatus; + emits event NetworkFaultChange; callback attribute channel; callback attribute routingRole; callback attribute networkName; @@ -4504,6 +4519,9 @@ endpoint 0 { } server cluster WiFiNetworkDiagnostics { + emits event Disconnection; + emits event AssociationFailure; + emits event ConnectionStatus; callback attribute bssid; callback attribute securityType; callback attribute wiFiVersion; @@ -4690,6 +4708,8 @@ endpoint 1 { } server cluster Actions { + emits event StateChanged; + emits event ActionFailed; callback attribute actionList; callback attribute endpointLists; callback attribute setupURL; @@ -4698,6 +4718,7 @@ endpoint 1 { } server cluster PowerSource { + emits event BatFaultChange; ram attribute status; ram attribute order default = 2; ram attribute description default = "B2"; @@ -4709,6 +4730,7 @@ endpoint 1 { } server cluster Switch { + emits event SwitchLatched; ram attribute numberOfPositions default = 2; ram attribute currentPosition; ram attribute multiPressMax default = 2; @@ -4729,6 +4751,7 @@ endpoint 1 { } server cluster BooleanState { + emits event StateChange; ram attribute stateValue; ram attribute featureMap; ram attribute clusterRevision default = 1; @@ -4750,6 +4773,10 @@ endpoint 1 { } server cluster DoorLock { + emits event DoorLockAlarm; + emits event LockOperation; + emits event LockOperationError; + emits event LockUserChange; ram attribute lockState default = 2; ram attribute lockType; ram attribute actuatorEnabled; @@ -4825,6 +4852,18 @@ endpoint 1 { } server cluster PumpConfigurationAndControl { + emits event SupplyVoltageLow; + emits event SupplyVoltageHigh; + emits event PowerMissingPhase; + emits event SystemPressureLow; + emits event SystemPressureHigh; + emits event DryRunning; + emits event MotorTemperatureHigh; + emits event PumpMotorFatalFailure; + emits event ElectronicTemperatureHigh; + emits event PumpBlocked; + emits event SensorFailure; + emits event ElectronicNonFatalFailure; ram attribute maxPressure; ram attribute maxSpeed; ram attribute maxFlow; @@ -5131,6 +5170,8 @@ endpoint 1 { } server cluster UnitTesting { + emits event TestEvent; + emits event TestFabricScopedEvent; ram attribute boolean; ram attribute bitmap8; ram attribute bitmap16; diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter index 34ca3399dfcc31..6be1db0d1caf3e 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter @@ -3582,6 +3582,7 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; callback attribute acl; callback attribute subjectsPerAccessControlEntry default = 4; callback attribute targetsPerAccessControlEntry default = 3; @@ -3591,6 +3592,7 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -3608,6 +3610,9 @@ endpoint 0 { } server cluster OtaSoftwareUpdateRequestor { + emits event StateTransition; + emits event VersionApplied; + emits event DownloadError; callback attribute defaultOTAProviders; ram attribute updatePossible default = 1; ram attribute updateState; @@ -3845,6 +3850,8 @@ endpoint 1 { } server cluster Actions { + emits event StateChanged; + emits event ActionFailed; callback attribute actionList; callback attribute endpointLists; ram attribute featureMap; @@ -3860,6 +3867,7 @@ endpoint 1 { } server cluster Switch { + emits event SwitchLatched; ram attribute numberOfPositions default = 2; ram attribute currentPosition; ram attribute featureMap default = 1; @@ -3879,6 +3887,7 @@ endpoint 1 { } server cluster BooleanState { + emits event StateChange; ram attribute stateValue; ram attribute featureMap; ram attribute clusterRevision default = 1; @@ -3897,6 +3906,9 @@ endpoint 1 { } server cluster DoorLock { + emits event DoorLockAlarm; + emits event LockOperation; + emits event LockOperationError; ram attribute lockState default = 2; ram attribute lockType; ram attribute actuatorEnabled; @@ -4102,6 +4114,8 @@ endpoint 1 { } server cluster UnitTesting { + emits event TestEvent; + emits event TestFabricScopedEvent; ram attribute boolean; ram attribute bitmap8; ram attribute bitmap16; diff --git a/examples/bridge-app/bridge-common/bridge-app.matter b/examples/bridge-app/bridge-common/bridge-app.matter index 9c9130951002ea..7681897592318a 100644 --- a/examples/bridge-app/bridge-common/bridge-app.matter +++ b/examples/bridge-app/bridge-common/bridge-app.matter @@ -1533,6 +1533,7 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; callback attribute acl; callback attribute extension; callback attribute subjectsPerAccessControlEntry default = 4; @@ -1546,6 +1547,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -1638,6 +1642,7 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute upTime; @@ -1655,6 +1660,7 @@ endpoint 0 { } server cluster SoftwareDiagnostics { + emits event SoftwareFault; callback attribute threadMetrics; callback attribute currentHeapFree; callback attribute currentHeapUsed; @@ -1732,6 +1738,9 @@ endpoint 0 { } server cluster WiFiNetworkDiagnostics { + emits event Disconnection; + emits event AssociationFailure; + emits event ConnectionStatus; callback attribute bssid; callback attribute securityType; callback attribute wiFiVersion; @@ -1833,6 +1842,7 @@ endpoint 1 { } server cluster Actions { + emits event StateChanged; callback attribute actionList; callback attribute endpointLists; ram attribute setupURL default = "https://example.com"; diff --git a/examples/lighting-app/nxp/zap/lighting-on-off.matter b/examples/lighting-app/nxp/zap/lighting-on-off.matter index 663624453f1f9a..f69d4fe027f847 100644 --- a/examples/lighting-app/nxp/zap/lighting-on-off.matter +++ b/examples/lighting-app/nxp/zap/lighting-on-off.matter @@ -1256,6 +1256,8 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; + emits event AccessControlExtensionChanged; callback attribute acl; callback attribute subjectsPerAccessControlEntry default = 4; callback attribute targetsPerAccessControlEntry default = 3; @@ -1266,6 +1268,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -1283,6 +1288,9 @@ endpoint 0 { } server cluster OtaSoftwareUpdateRequestor { + emits event StateTransition; + emits event VersionApplied; + emits event DownloadError; callback attribute defaultOTAProviders; ram attribute updatePossible default = 1; ram attribute updateState; @@ -1315,6 +1323,7 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute testEventTriggersEnabled; diff --git a/examples/lock-app/lock-common/lock-app.matter b/examples/lock-app/lock-common/lock-app.matter index 21e16d7bdaa102..bf69baf34291a6 100644 --- a/examples/lock-app/lock-common/lock-app.matter +++ b/examples/lock-app/lock-common/lock-app.matter @@ -2008,6 +2008,8 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; + emits event AccessControlExtensionChanged; callback attribute acl; callback attribute extension; callback attribute subjectsPerAccessControlEntry default = 4; @@ -2019,6 +2021,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -2044,6 +2049,9 @@ endpoint 0 { } server cluster OtaSoftwareUpdateRequestor { + emits event StateTransition; + emits event VersionApplied; + emits event DownloadError; callback attribute defaultOTAProviders; ram attribute updatePossible default = 1; ram attribute updateState; @@ -2074,6 +2082,7 @@ endpoint 0 { } server cluster PowerSource { + emits event WiredFaultChange; ram attribute status default = 1; ram attribute order; ram attribute description default = "USB"; @@ -2111,6 +2120,10 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event HardwareFaultChange; + emits event RadioFaultChange; + emits event NetworkFaultChange; + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute upTime; @@ -2125,6 +2138,7 @@ endpoint 0 { } server cluster SoftwareDiagnostics { + emits event SoftwareFault; callback attribute threadMetrics; callback attribute currentHeapFree; callback attribute currentHeapUsed; @@ -2134,6 +2148,8 @@ endpoint 0 { } server cluster ThreadNetworkDiagnostics { + emits event ConnectionStatus; + emits event NetworkFaultChange; callback attribute channel; callback attribute routingRole; callback attribute networkName; @@ -2202,6 +2218,9 @@ endpoint 0 { } server cluster WiFiNetworkDiagnostics { + emits event Disconnection; + emits event AssociationFailure; + emits event ConnectionStatus; callback attribute bssid; callback attribute securityType; callback attribute wiFiVersion; @@ -2315,6 +2334,11 @@ endpoint 1 { } server cluster DoorLock { + emits event DoorLockAlarm; + emits event DoorStateChange; + emits event LockOperation; + emits event LockOperationError; + emits event LockUserChange; persist attribute lockState default = 1; ram attribute lockType; ram attribute actuatorEnabled; diff --git a/examples/lock-app/nxp/zap/lock-app.matter b/examples/lock-app/nxp/zap/lock-app.matter index 41807705d58670..f5aaf526416588 100644 --- a/examples/lock-app/nxp/zap/lock-app.matter +++ b/examples/lock-app/nxp/zap/lock-app.matter @@ -1350,6 +1350,8 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; + emits event AccessControlExtensionChanged; callback attribute acl; callback attribute subjectsPerAccessControlEntry default = 4; callback attribute targetsPerAccessControlEntry default = 3; @@ -1360,6 +1362,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -1400,6 +1405,7 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute testEventTriggersEnabled; @@ -1535,6 +1541,10 @@ endpoint 1 { } server cluster DoorLock { + emits event DoorLockAlarm; + emits event LockOperation; + emits event LockOperationError; + emits event LockUserChange; ram attribute lockState; ram attribute lockType; ram attribute actuatorEnabled; diff --git a/examples/window-app/common/window-app.matter b/examples/window-app/common/window-app.matter index 49bf90e0122ae6..e9553397544da5 100644 --- a/examples/window-app/common/window-app.matter +++ b/examples/window-app/common/window-app.matter @@ -1683,6 +1683,8 @@ endpoint 0 { } server cluster AccessControl { + emits event AccessControlEntryChanged; + emits event AccessControlExtensionChanged; callback attribute acl; callback attribute extension; callback attribute subjectsPerAccessControlEntry default = 4; @@ -1696,6 +1698,9 @@ endpoint 0 { } server cluster BasicInformation { + emits event StartUp; + emits event ShutDown; + emits event Leave; callback attribute dataModelRevision default = 10; callback attribute vendorName; callback attribute vendorID; @@ -1724,6 +1729,9 @@ endpoint 0 { } server cluster OtaSoftwareUpdateRequestor { + emits event StateTransition; + emits event VersionApplied; + emits event DownloadError; callback attribute defaultOTAProviders; ram attribute updatePossible default = 1; ram attribute updateState; @@ -1805,6 +1813,7 @@ endpoint 0 { } server cluster GeneralDiagnostics { + emits event BootReason; callback attribute networkInterfaces; callback attribute rebootCount; callback attribute upTime; @@ -1899,6 +1908,9 @@ endpoint 0 { } server cluster WiFiNetworkDiagnostics { + emits event Disconnection; + emits event AssociationFailure; + emits event ConnectionStatus; callback attribute bssid; callback attribute securityType; callback attribute wiFiVersion; diff --git a/scripts/py_matter_idl/matter_idl/matter_grammar.lark b/scripts/py_matter_idl/matter_idl/matter_grammar.lark index a63f97e385bb5b..14c0ffbb1baf55 100644 --- a/scripts/py_matter_idl/matter_idl/matter_grammar.lark +++ b/scripts/py_matter_idl/matter_idl/matter_grammar.lark @@ -61,12 +61,16 @@ endpoint: "endpoint"i positive_integer "{" endpoint_content* "}" endpoint_device_type: "device" "type" id "=" positive_integer "," "version" positive_integer ";" endpoint_cluster_binding: "binding"i "cluster"i id ";" -endpoint_server_cluster: "server"i "cluster"i id "{" endpoint_attribute_instantiation* "}" +endpoint_server_cluster: "server"i "cluster"i id "{" endpoint_cluster_entry* "}" + endpoint_attribute_storage: "ram"i -> ram_attribute | "persist"i -> persist_attribute | "callback"i -> callback_attribute +?endpoint_cluster_entry: endpoint_emitted_event | endpoint_attribute_instantiation + +endpoint_emitted_event: "emits"i "event"i id ";" endpoint_attribute_instantiation: endpoint_attribute_storage "attribute"i id default_value? ";" bool_default: "true"i -> bool_default_true diff --git a/scripts/py_matter_idl/matter_idl/matter_idl_parser.py b/scripts/py_matter_idl/matter_idl/matter_idl_parser.py index 0864db3fe6f578..4a3c0b47f33c96 100755 --- a/scripts/py_matter_idl/matter_idl/matter_idl_parser.py +++ b/scripts/py_matter_idl/matter_idl/matter_idl_parser.py @@ -318,6 +318,11 @@ def endpoint_attribute_instantiation(self, meta, storage, id, default=None): meta = None if self.skip_meta else ParseMetaData(meta) return AttributeInstantiation(parse_meta=meta, name=id, storage=storage, default=default) + @v_args(meta=True, inline=True) + def endpoint_emitted_event(self, meta, id): + meta = None if self.skip_meta else ParseMetaData(meta) + return id + def ESCAPED_STRING(self, s): # handle escapes, skip the start and end quotes return s.value[1:-1].encode('utf-8').decode('unicode-escape') @@ -366,9 +371,18 @@ def endpoint_cluster_binding(self, id): return AddBindingToEndpointTransform(id) @v_args(meta=True, inline=True) - def endpoint_server_cluster(self, meta, id, *attributes): + def endpoint_server_cluster(self, meta, id, *content): meta = None if self.skip_meta else ParseMetaData(meta) - return AddServerClusterToEndpointTransform(ServerClusterInstantiation(parse_meta=meta, name=id, attributes=list(attributes))) + + attributes = [] + events = set() + + for item in content: + if isinstance(item, AttributeInstantiation): + attributes.append(item) + else: + events.add(item) + return AddServerClusterToEndpointTransform(ServerClusterInstantiation(parse_meta=meta, name=id, attributes=attributes, events_emitted=events)) @v_args(inline=True, meta=True) def cluster(self, meta, side, name, code, *content): diff --git a/scripts/py_matter_idl/matter_idl/matter_idl_types.py b/scripts/py_matter_idl/matter_idl/matter_idl_types.py index 68559439e079a9..362f921b2a8a82 100644 --- a/scripts/py_matter_idl/matter_idl/matter_idl_types.py +++ b/scripts/py_matter_idl/matter_idl/matter_idl_types.py @@ -223,6 +223,7 @@ class AttributeInstantiation: class ServerClusterInstantiation: name: str attributes: List[AttributeInstantiation] = field(default_factory=list) + events_emitted: List[str] = field(default_factory=set) # Parsing meta data missing only when skip meta data is requested parse_meta: Optional[ParseMetaData] = field(default=None) @@ -239,7 +240,8 @@ class DeviceType: class Endpoint: number: int device_types: List[DeviceType] = field(default_factory=list) - server_clusters: List[ServerClusterInstantiation] = field(default_factory=list) + server_clusters: List[ServerClusterInstantiation] = field( + default_factory=list) client_bindings: List[str] = field(default_factory=list) diff --git a/scripts/py_matter_idl/matter_idl/test_matter_idl_parser.py b/scripts/py_matter_idl/matter_idl/test_matter_idl_parser.py index 8b7d24a22355ac..be7bd82e0ee9c9 100755 --- a/scripts/py_matter_idl/matter_idl/test_matter_idl_parser.py +++ b/scripts/py_matter_idl/matter_idl/test_matter_idl_parser.py @@ -508,6 +508,36 @@ def test_multi_endpoints(self): ]) self.assertEqual(actual, expected) + def test_emits_events(self): + actual = parseText(""" + endpoint 1 { + server cluster Example {} + } + endpoint 2 { + server cluster Example { + emits event FooBar; + emits event SomeNewEvent; + } + server cluster AnotherExample { + emits event StartUp; + emits event ShutDown; + } + } + """) + + expected = Idl(endpoints=[ + Endpoint(number=1, server_clusters=[ + ServerClusterInstantiation(name="Example")]), + Endpoint(number=2, server_clusters=[ + ServerClusterInstantiation(name="Example", events_emitted={ + "FooBar", "SomeNewEvent"}), + ServerClusterInstantiation(name="AnotherExample", events_emitted={ + "StartUp", "ShutDown"}), + ]) + ]) + + self.assertEqual(actual, expected) + if __name__ == '__main__': unittest.main() diff --git a/scripts/setup/bootstrap_version.txt b/scripts/setup/bootstrap_version.txt new file mode 100644 index 00000000000000..6572314aa17287 --- /dev/null +++ b/scripts/setup/bootstrap_version.txt @@ -0,0 +1 @@ +1.0 - Reason for bootstrap refresh: changes to IDL parser to support emitted events. diff --git a/src/app/zap-templates/templates/app/MatterIDL.zapt b/src/app/zap-templates/templates/app/MatterIDL.zapt index 48b701de91de95..9f67be02284118 100644 --- a/src/app/zap-templates/templates/app/MatterIDL.zapt +++ b/src/app/zap-templates/templates/app/MatterIDL.zapt @@ -142,6 +142,11 @@ endpoint {{endpointId}} { {{#if (isServer side)}} server cluster {{asUpperCamelCase name}} { + {{#user_cluster_events}} + {{#if included}} + emits event {{name}}; + {{/if}} + {{/user_cluster_events}} {{#user_cluster_attributes}} {{#if included}} {{~#if (is_str_equal storageOption "NVM")}}