private bool IsValid(IAppEndpoint channel) => !(channel is NullEndpoint nullEndpoint) || !nullEndpoint.ShouldBeRevalidated();
private async Task <Unit> MqttToSmartthings(CancellationToken ct, MqttMessage message, Device[] devices, IAppEndpoint endpoint) { try { var topicParts = message.Topic.Split(new[] { '/' }, 3, StringSplitOptions.RemoveEmptyEntries); //var topicNamespace = topicParts[0]; var topicDeviceId = topicParts[1]; var topicProperty = topicParts[2]; var device = devices.SingleOrDefault(d => d.Id.Equals(topicDeviceId, StringComparison.InvariantCultureIgnoreCase)); if (device == null) { this.Log().Warning("No device found on ST for id: " + topicDeviceId); return(Unit.Default); } if (!TryGetCommand(device, topicProperty, message.Value, out var command, out var parameters)) { this.Log().Warning($"No command found on {device.Name} for {message}"); return(Unit.Default); } using (await _gate.LockAsync(ct)) { this.Log().Info($"[MQTT => ST] Sending ({device.Name}): {message}"); await endpoint.Execute(ct, topicDeviceId, command, parameters); this.Log().Info($"[MQTT => ST] Sent {message} ({device.Name}.{command}({parameters.FirstOrDefault().Value ?? ""}))"); } } catch (Exception e) { this.Log().Error($"[MQTT => ST] Failed to send: {message}", e); } return(Unit.Default); }