public async Task ProcessDevicesChanges(bool sendStatus = true) { if (DateTime.UtcNow < _nextDeviceCycle) { return; } _nextDeviceCycle = DateTime.UtcNow.AddMilliseconds(_currentCycleMS); if (await _adaptor.GetStatus(_fastCycleMS)) { if (sendStatus && !_isOnline) { await _apiStatus.SetStatus($"{_adaptor.DisplayName} OK", false); } if (_adaptor.Muted != _lastMuted || _adaptor.Volume != _lastVolume) { _lastMuted = _volume.IsMuted = _adaptor.Muted; _lastVolume = _volume.VolumeValue = _adaptor.Volume; _logger.LogTrace($"UPDATEVOLUME volume {_volume.VolumeValue} mute{_volume.IsMuted}"); await _apiControlVolume.UpdateState(_volume); } RoonApiControlSource.EStatus newStatus = GetSourceControlStatus(); if (newStatus != _lastStatus) { _lastStatus = _source.Status = newStatus; _logger.LogTrace($"UPDATESTATUS {newStatus}"); await _apiControlSource.UpdateState(_source); } _isOnline = true; } else { if (sendStatus && _isOnline) { await _apiStatus.SetStatus($"{_adaptor.DisplayName} FAILED", true); } _isOnline = false; } }
public async Task <bool> Start() { _lastStatus = GetSourceControlStatus(); _lastVolume = _adaptor.Volume; _lastMuted = _adaptor.Muted; SetSlowCycle(); _logger.LogInformation("Start RIC's Roon Controller"); // Init Controls _apiControlVolume = new RoonApiControlVolume(_api, false); _volume = new RoonApiControlVolume.Volume { DisplayName = _adaptor.DisplayName + " Volume", VolumeMax = _adaptor.MaxVolume, VolumeStep = 1, VolumeType = "number", VolumeValue = _adaptor.Volume, IsMuted = _adaptor.Muted }; _apiControlVolume.AddControl(_volume, new RoonApiControlVolume.VolumeFunctions { SetVolume = async(arg) => { _logger.LogTrace($"SETVOLUME {arg.Mode} {arg.Value}"); await _adaptor.SetVolume(arg.Value); SetFastCycle(); return(true); }, Mute = async(arg) => { _logger.LogTrace($"MUTE {arg.Mute} "); await _adaptor.SetMuted(arg.Mute == RoonApiTransport.EMute.mute); SetFastCycle(); return(true); } }); _apiControlSource = new RoonApiControlSource(_api, false); _source = new RoonApiControlSource.Source { DisplayName = _adaptor.DisplayName + " Source", SupportsStandBy = true, Status = GetSourceControlStatus() }; _apiControlSource.AddControl(_source, new RoonApiControlSource.SourceFunctions { SetStandby = async(arg) => { _logger.LogTrace($"SET STANDBY {arg.Status}"); await _adaptor.SetPower(false); SetSlowCycle(); return(true); }, SetConvenience = async(arg) => { _logger.LogTrace($"SETCONVENIENCE"); if (!_adaptor.Power) { await _adaptor.SetPower(true); } if (_adaptor.Selected) { await _adaptor.Select(); } SetFastCycle(); return(true); } }); // Init Service Registration List <string> services = new List <string>(new string[] { RoonApi.ServiceStatus, RoonApi.ControlVolume, RoonApi.ControlSource }); if (_apiSettings != null) { services.Add(RoonApi.ServiceSettings); } _roonRegister = new RoonApi.RoonRegister { DisplayName = "Ric's Roon Controller", DisplayVersion = "1.0.0", Publisher = "Christian Riedl", Email = "*****@*****.**", WebSite = "https://github.com/christian-riedl/roon-control", ExtensionId = "com.ric.controller", Token = null, OptionalServices = new string[0], RequiredServices = new string[0], ProvidedServices = services.ToArray() }; Discovery discovery = new Discovery(_myIPAddress, 1000, _logger); var coreList = await discovery.QueryServiceId((res) => { if (res.CoreName == _coreName) { _core = res; return(true); } return(false); }); _api.StartReceiver(_core.CoreIPAddress, _core.HttpPort, _roonRegister); return(true); }