Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d9ece4

Browse files
committedJul 21, 2023
feat(binding_mqtt): support MQTT URI scheme
1 parent d0bf7ad commit 1d9ece4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎lib/src/binding_mqtt/mqtt_extensions.dart

+11-4
Original file line numberDiff line numberDiff 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].

0 commit comments

Comments
 (0)
Please sign in to comment.