Skip to content

Commit

Permalink
feat(binding_mqtt): support MQTT URI scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jul 21, 2023
1 parent d0bf7ad commit e5c9360
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/src/binding_mqtt/mqtt_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,22 @@ extension MqttFormExtension on Form {

/// Gets the MQTT topic for publishing from this [Form].
///
/// Throws an [Exception] if no topic could be retrieved.
/// If present, this getter uses the dedicated vocabulary term `topic`.
/// Otherwise, the URI path from the `href` field is being used as a fallback.
String get topicName {
final topic = _obtainVocabularyTerm<String>('topic');

if (topic == null) {
throw MqttBindingException('MQTT topic was not defined on form.');
if (topic != null) {
return topic;
}

return topic;
final path = Uri.decodeComponent(href.path);

if (path.isEmpty) {
return path;
}

return path.substring(1);
}

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

0 comments on commit e5c9360

Please sign in to comment.