Skip to content

Commit 35bc521

Browse files
committed
feat(binding_mqtt): support MQTT URI scheme
1 parent 3a2d79a commit 35bc521

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/src/binding_mqtt/mqtt_extensions.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,22 @@ extension MqttFormExtension on AugmentedForm {
8787

8888
/// Gets the MQTT topic for publishing from this [Form].
8989
///
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.
9192
String get topicName {
9293
final topic = _obtainVocabularyTerm<String>("topic");
9394

94-
if (topic == null) {
95-
throw MqttBindingException("MQTT topic was not defined on form.");
95+
if (topic != null) {
96+
return topic;
9697
}
9798

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);
99106
}
100107

101108
/// Gets the MQTT topic for subscribing from this [Form].

0 commit comments

Comments
 (0)