File tree 1 file changed +11
-4
lines changed
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 {
91
91
92
92
/// Gets the MQTT topic for publishing from this [Form] .
93
93
///
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.
95
96
String get topicName {
96
97
final topic = _obtainVocabularyTerm <String >('topic' );
97
98
98
- if (topic = = null ) {
99
- throw MqttBindingException ( 'MQTT topic was not defined on form.' ) ;
99
+ if (topic ! = null ) {
100
+ return topic;
100
101
}
101
102
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 );
103
110
}
104
111
105
112
/// Gets the MQTT topic for subscribing from this [Form] .
You can’t perform that action at this time.
0 commit comments