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 @@ -87,15 +87,22 @@ extension MqttFormExtension on AugmentedForm {
87
87
88
88
/// Gets the MQTT topic for publishing from this [Form] .
89
89
///
90
- /// Throws an [Exception] if no topic could be retrieved.
90
+ /// If present, this getter uses the dedicated vocabulary term `topic` .
91
+ /// Otherwise, the URI path from the `href` field is being used as a fallback.
91
92
String get topicName {
92
93
final topic = _obtainVocabularyTerm <String >("topic" );
93
94
94
- if (topic = = null ) {
95
- throw MqttBindingException ( "MQTT topic was not defined on form." ) ;
95
+ if (topic ! = null ) {
96
+ return topic;
96
97
}
97
98
98
- return topic;
99
+ final path = Uri .decodeComponent (href.path);
100
+
101
+ if (path.isEmpty) {
102
+ return path;
103
+ }
104
+
105
+ return path.substring (1 );
99
106
}
100
107
101
108
/// Gets the MQTT topic for subscribing from this [Form] .
You can’t perform that action at this time.
0 commit comments