private async Task LightsOn() { Models.Light firstLights = _context.RmsList?.Include(x => x.Lights).FirstOrDefault()?.Lights?.FirstOrDefault();// if (firstLights != null) { Models.WebHook onHook = firstLights.Hooks?.FirstOrDefault(hook => hook.ActivationCommand == Models.Enums.RmsCommand.LightsOn); if (onHook != null) { await _rmsService.ActOnWebHook(onHook); } } Console.WriteLine("-------- LIGHTS ARE ON --------- i think"); }
private async Task LightsOff() { Models.Light firstLights = _context.Lights?.Include(x => x.Hooks).FirstOrDefault(dev => dev.Type == Models.Enums.DeviceType.LightOnOff); if (firstLights != null) { Models.WebHook ofHook = firstLights.Hooks?.FirstOrDefault(hook => hook.ActivationCommand == Models.Enums.RmsCommand.LightsOff); if (ofHook != null) { await _rmsService.ActOnWebHook(ofHook); } } Console.WriteLine("-------- LIGHTS ARE OFF -------- i think"); }
public async Task <bool> On(Models.Light light) { try { using (HttpClient webClient = new HttpClient()) { string json = JsonConvert.SerializeObject(light); HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await webClient.PostAsync($"{BASE_URL}light/on", content); return(response.StatusCode == System.Net.HttpStatusCode.OK); } } catch (Exception ex) { return(false); } }
public LampViewModel() { _dataAccess = new DataAccess.Light(); Message = "Exemple : Génie allume la lampe"; OnLight = new RelayCommand <int?>(async(idLight) => { bool res = await _dataAccess.On(new Models.Light() { State = true, LightId = idLight ?? 1, Color = new Models.Color() }); if (res) { Message = "Lampe Allumée"; } else { Message = "Erreur durant l'execution"; } }); OffLight = new RelayCommand <int?>(async(param) => { bool res = await _dataAccess.Off(1); if (res) { Message = "Lampe éteinte"; } else { Message = "Erreur durant l'execution"; } }); ChangeColor = new RelayCommand <string>(async(color) => { var light = new Models.Light() { State = true, LightId = 1, Color = new Models.Color() }; switch (color) { case "rouge": light.Color.SetRedColor(); break; case "vert": light.Color.SetGreenColor(); break; case "bleu": light.Color.SetBlueColor(); break; default: break; } bool res = await _dataAccess.On(light); if (res) { Message = "La couleur est : " + color; } else { Message = "Erreur durant l'execution"; } }); StartListeningMyo = new RelayCommand(() => { initMyo(); }, () => { return(!_isEnabledMyo); }); }