private IObservable <bool> IsAutomationEnabled(Automation automation) => _mqtt .GetAndObserveTopic(GetTopic(automation)) .Select(topic => { var s = topic.Values.GetValueOrDefault("state"); return(s == null || s == "enabled"); // If not configured, we assumed enabled });
/// <inheritdoc /> public IObservable <bool> GetAndObserveIsEnabled(Automation automation) { var isClientEnabled = _mqtt .GetAndObserveIsEnabled(); var isAutomationEnabled = _mqtt .GetAndObserveTopic(GetTopic(automation)) .Select(topic => { var s = topic.Values.GetValueOrDefault("state"); return(s == null || s == "enabled"); // If not configured, we assumed enabled }); return(Observable .CombineLatest(isClientEnabled, isAutomationEnabled, (c, a) => c & a) .DistinctUntilChanged()); }
/// <inheritdoc cref="IDeviceHost"/> public IObservable <DeviceState> GetAndObserveState(IDevice device) => _mqtt .GetAndObserveTopic(_getTopic(device)) .Select(topic => new DeviceState(device.Id, _getValues(topic), topic.IsRetainedState));