public async Task RunScene(Scene scene) { var parameters = new Parameters(); parameters.id = scene.id; parameters.state = "run"; var jsonrpc = new JsonRpcClient(parameters); if (await jsonrpc.SendRequest("scenario::changeState")) { await UpdateScene(scene); } }
public async Task ExecuteCommand(Command cmd, Parameters parameters = null) { cmd.Updating = true; if (parameters == null) { parameters = new Parameters(); parameters.id = cmd.id; parameters.name = cmd.name; } var jsonrpc = new JsonRpcClient(parameters); if (await jsonrpc.SendRequest("cmd::execCmd")) { var response = jsonrpc.GetRequestResponseDeserialized<Response<CommandResult>>(); cmd.Value = response.result.value; } else { cmd.Value = "N/A"; } cmd.Updating = false; }
private async Task UpdateScene(Scene scene) { var parameters = new Parameters(); parameters.id = scene.id; var jsonrpc = new JsonRpcClient(parameters); if (await jsonrpc.SendRequest("scenario::byId")) { var response = jsonrpc.GetRequestResponseDeserialized<Response<Scene>>(); scene.lastLaunch = response.result.lastLaunch; } }
public async Task UpdateObject(JdObject obj) { var parameters = new Parameters(); parameters.object_id = obj.id; var jsonrpc = new JsonRpcClient(parameters); if (await jsonrpc.SendRequest("eqLogic::byObjectId")) { var response = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<EqLogic>>>(); if (response.result != null) { foreach (EqLogic eqnew in response.result) { var lst = from e in EqLogicList where e.id == eqnew.id select e; if (lst.Count() != 0) { var eqold = lst.First(); eqnew.cmds = eqold.cmds; eqold = eqnew; } else { EqLogicList.Add(eqnew); obj.eqLogics.Add(eqnew); } await UpdateEqLogic(eqnew); } } } }
public async Task GetEventChanges() { var parameters = new Parameters(); parameters.datetime = _dateTime; var jsonrpc = new JsonRpcClient(parameters); if (await jsonrpc.SendRequest("event::changes")) { var response = jsonrpc.GetEvents(); foreach (JdEvent e in response.result) { switch (e.name) { case "cmd::update": var ev = e as Event<Option>; var cmds = from c in CommandList where c.id == ev.option.cmd_id select c; foreach (Command cmd in cmds) { if (cmd.datetime < ev.datetime) { cmd.Value = ev.option.value; cmd.datetime = ev.datetime; } } break; } } _dateTime = response.datetime; } }
/*public async Task<Error> DownloadCommands() { var jsonrpc = new JsonRpcClient(); if (await jsonrpc.SendRequest("cmd::all")) { CommandList.Clear(); var response = jsonrpc.GetRequestResponseDeserialized<ResponseCommandList>(); if (response != null) CommandList = response.result; foreach (Command cmd in CommandList) { var eqlist = from eq in EqLogicList where eq.id == cmd.eqLogic_id select eq; var parenteq = eqlist.First(); if (parenteq.cmds == null) parenteq.cmds = new ObservableCollection<Command>(); parenteq.cmds.Add(cmd); cmd.Parent = parenteq; if (cmd.name == "On") parenteq.OnVisibility = true; if (cmd.type == "info") await ExecuteCommand(cmd); } } return jsonrpc.Error; }*/ public async Task<Error> interactTryToReply(string query) { InteractReply = ""; var jsonrpc = new JsonRpcClient(); Parameters parameters = new Parameters(); parameters.query = query; jsonrpc.SetParameters(parameters); if (await jsonrpc.SendRequest("interact::tryToReply")) { var response = jsonrpc.GetRequestResponseDeserialized<Response<string>>(); if (response != null) InteractReply = response.result; } return jsonrpc.Error; }
/// <summary> /// Télécharge les informations sur les JdObject, les EqLogic et les Command (sans les value) /// </summary> /// <returns>Le code et le message d'erreur de Jeedom</returns> public async Task<Error> DownloadObjects() { var jsonrpc = new JsonRpcClient(); EqLogicList.Clear(); CommandList.Clear(); ObjectList.Clear(); if (await jsonrpc.SendRequest("object::full")) { //List<string> idList = new List<string>(); var response = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<JdObject>>>(); if (response != null) { foreach (JdObject o in response.result) { ObjectList.Add(o); //idList.Add("dmj" + o.id); //UpdateObjectImage(o); if (o.eqLogics != null) { foreach (EqLogic eq in o.eqLogics) { EqLogicList.Add(eq); if (eq.cmds != null) { foreach (Command cmd in eq.cmds) { cmd.Parent = eq; CommandList.Add(cmd); } } else eq.cmds = new ObservableCollection<Command>(); } } } JdObject fakeobj = new JdObject(); fakeobj.name = "Autres"; //UpdateObjectImage(fakeobj); ObjectList.Add(fakeobj); fakeobj.eqLogics = new ObservableCollection<EqLogic>(); // Récupère les EqLogic du fake (object_id==null) if (await jsonrpc.SendRequest("eqLogic::byObjectId")) { var responseEqLogic = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<EqLogic>>>(); if (responseEqLogic != null) { foreach (EqLogic eq in responseEqLogic.result) { var param = new Parameters(); param.id = eq.id; jsonrpc.SetParameters(param); if (await jsonrpc.SendRequest("eqLogic::fullById")) { var responseEq = jsonrpc.GetRequestResponseDeserialized<Response<EqLogic>>(); if (responseEq.result?.cmds != null) eq.cmds = responseEq.result.cmds; else eq.cmds = new ObservableCollection<Command>(); fakeobj.eqLogics.Add(eq); EqLogicList.Add(eq); foreach (Command cmd in eq.cmds) { CommandList.Add(cmd); } } } } } // Efface les images inutiles /*var files = await ImageFolder.GetFilesAsync(); foreach (StorageFile f in files) { if (!idList.Contains(f.DisplayName)) { await f.DeleteAsync(); } }*/ } } return jsonrpc.Error; }