File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -91,15 +91,22 @@ extension MqttFormExtension on Form {
9191
9292 /// Gets the MQTT topic for publishing from this [Form] .
9393 ///
94- /// Throws an [Exception] if no topic could be retrieved.
94+ /// If present, this getter uses the dedicated vocabulary term `topic` .
95+ /// Otherwise, the URI path from the `href` field is being used as a fallback.
9596 String get topicName {
9697 final topic = _obtainVocabularyTerm <String >('topic' );
9798
98- if (topic = = null ) {
99- throw MqttBindingException ( 'MQTT topic was not defined on form.' ) ;
99+ if (topic ! = null ) {
100+ return topic;
100101 }
101102
102- return topic;
103+ final path = Uri .decodeComponent (href.path);
104+
105+ if (path.isEmpty) {
106+ return path;
107+ }
108+
109+ return path.substring (1 );
103110 }
104111
105112 /// Gets the MQTT topic for subscribing from this [Form] .
You can’t perform that action at this time.
0 commit comments