public async Task <bool> Start() { _aircoManager = new AircoManager(_httpClientFactory.CreateClient()); if (!string.IsNullOrEmpty(_config.AuthCode)) { _aircoManager.SetAuthorizationToken(_config.AuthCode); _schedulerService.AddPolling(PollingConds, "PANASONIC_AIR_CONDITIONER", SchedulerServicePollingEnum.NORMAL_POLLING); } else if (!string.IsNullOrEmpty(_config.Username)) { var result = await _aircoManager.Login("0", _config.Username, _config.Password); if (result.Result == 0) { _config.AuthCode = result.UToken; _componentsService.SaveComponentConfig(_config); } } return(true); }
public Task <bool> Start() { if (!string.IsNullOrEmpty(_neonConfig.Home.Name)) { _schedulerService.AddPolling(GetSunSetJob, "SunSetUpdate", SchedulerServicePollingEnum.VERY_LONG_POLLING); GetSunSetJob(); } return(Task.FromResult(true)); }
public async Task <bool> Start() { if (!string.IsNullOrEmpty(_config.ClientId) && string.IsNullOrEmpty(_config.AccessToken)) { BuildUserTokenRequest(); } else if (_config.ExpireOn < DateTime.Now) { BuildUserTokenRequest(); } else { InitSpotifyClient(); RefreshTokenJob(); _schedulerService.AddPolling(PollingRequest, "Spotify_Device", SchedulerServicePollingEnum.NORMAL_POLLING); } return(true); }
public Task <bool> Start() { if (!_discoveryConfig.EnabledDiscovery) { return(Task.FromResult(false)); } StartAdvertiser(); _schedulerService.AddPolling(StartDiscovery, "NETWORK_DISCOVERY", SchedulerServicePollingEnum.HalfNormalPolling); DiscoveredDevices.CollectionChanged += (sender, args) => { foreach (var item in args.NewItems) { var discoveredDevice = (DiscoveryDevice)item; _logger.LogDebug($"{discoveredDevice.Service} - {discoveredDevice.IpAddress}:{discoveredDevice.Port}"); NotifyListener(discoveredDevice); } }; return(Task.FromResult(true)); }
public async Task <bool> Start() { if (string.IsNullOrEmpty(_config.BridgeIpAddress)) { _logger.LogInformation("Searching from Philip Hue bridge..."); var bridgeIps = await _bridgeLocator.LocateBridgesAsync(TimeSpan.FromSeconds(10)); if (bridgeIps.Any()) { _logger.LogInformation($"Found {bridgeIps.Count()} bridges"); _hueClient = new LocalHueClient(bridgeIps.ToList()[0].IpAddress); _config.BridgeIpAddress = bridgeIps.ToList()[0].IpAddress; _logger.LogInformation("Button pressed"); var appKey = await _hueClient.RegisterAsync("LeonHomeControl", "Leon"); _config.ApiKey = appKey; _componentsService.SaveComponentConfig(_config); _hueClient.Initialize(appKey); _logger.LogInformation("Philip Hue Configured"); _hueClient = new LocalHueClient(_config.BridgeIpAddress, _config.ApiKey); _logger.LogInformation("Connected to Philip Hue"); var lights = await _hueClient.GetLightsAsync(); lights.ToList().ForEach(s => { _logger.LogInformation($"{s.Name}"); }); var groups = await _hueClient.GetGroupsAsync(); groups.ToList().ForEach(g => { _logger.LogInformation($"{g.Name}"); }); } } else { _hueClient = new LocalHueClient(_config.BridgeIpAddress); if (string.IsNullOrEmpty(_config.ApiKey)) { _userInteractionService.AddUserInteractionData(new UserInteractionData { Name = "Philip hue component", Fields = new List <UserInteractionField> { new UserInteractionField().Build().SetIsRequired(true) .SetFieldType(UserInteractionFieldTypeEnum.BUTTON) .SetFieldName("PHILIP_HUE_BUTTON_PRESS") .SetDescription("Press Philip hue button for link bride") } }, async data => { }); } else { _hueClient = new LocalHueClient(_config.BridgeIpAddress, _config.ApiKey); _logger.LogInformation("Connected to Philip Hue"); _schedulerService.AddPolling(UpdateEntities, "PhiipHue_UpdateLightEntities", SchedulerServicePollingEnum.NORMAL_POLLING); } } return(true); }
public async Task <bool> LoadComponent(string name) { var cData = new ComponentData() { Id = Guid.NewGuid(), Status = ComponentStatusEnum.Starting, Info = new ComponentInfo() { Name = name } }; ComponentsData.Add(cData); try { var availableComponent = AvailableComponents.FirstOrDefault(c => c.Name == name); if (availableComponent == null) { throw new Exception($"Component name {name} not found!"); } var componentAttribute = availableComponent.ComponentType.GetCustomAttribute <NeonComponentAttribute>(); cData.Info = new ComponentInfo() { Name = componentAttribute.Name, Version = componentAttribute.Version, Author = componentAttribute.Author, Category = componentAttribute.Category, Description = componentAttribute.Description }; var componentObject = _neonManager.Resolve(availableComponent.ComponentType) as INeonComponent; if (componentObject == null) { throw new Exception($"Component {name} not implement INeonComponent interface"); } var configFileName = Path.Combine(_config.ConfigDirectory.DirectoryName, GetComponentConfigFileName(cData)); var componentConfig = _fileSystemManager.ReadFromFile(configFileName, componentAttribute.ConfigType); if (componentConfig == null) { _logger.LogWarning($"Component config {cData.Info.Name} ({GetComponentConfigFileName(cData)}) don't exists, creating default"); componentConfig = componentObject.GetDefaultConfig(); _fileSystemManager.WriteToFile(configFileName, componentConfig); } await componentObject.Init(componentConfig); await componentObject.Start(); var polls = GetComponentPollAttribute(availableComponent.ComponentType); if (polls.Count == 0) { _schedulerService.AddPolling(async() => { await componentObject.Poll(); }, $"COMPONENT_{name.ToUpper()}", SchedulerServicePollingEnum.NormalPolling); } else { polls.ForEach(p => { if (p.ComponentPollRate.IsEnabled) { _schedulerService.AddPolling(() => { p.Method.Invoke(componentObject, null); }, $"COMPONENT_{name.ToUpper()}_{p.Method.Name}", p.ComponentPollRate.Rate); } }); } componentObject.ComponentId = cData.Id.ToString(); cData.Status = ComponentStatusEnum.Started; _runningComponents.Add(cData.Id, componentObject); SaveComponentConfig(componentObject, componentConfig); return(true); } catch (ComponentNeedConfigException ex) { _logger.LogError($"Error during load component {name} - config values need configuration: {string.Join(',', ex.ConfigKeys)}"); cData.Status = ComponentStatusEnum.NeedConfiguration; cData.Error = ex; return(false); } catch (Exception ex) { _logger.LogError($"Error during load component {name} - {ex.Message}"); cData.Error = ex; cData.Status = ComponentStatusEnum.Error; return(false); } }