public async Task DiscoverDevices() { if (SessionData == null) { return; } if (SessionData.Expires_at < DateTimeOffset.Now.ToUnixTimeSeconds()) { await RefreshToken(); } var reqData = new DeviceRequest { Header = new DeviceRequest_Header { Name = "Discovery", Namespace = "discovery", PayloadVersion = 1, }, Payload = new DeviceRequest_Payload { AccessToken = SessionData.Access_token, DevId = null } }; var res = await ApiServices.PostJsonData <DeviceResponse>(deviceUri, reqData.ToString()); if (res.Header.Code == "SUCCESS") { DevicesList = res.Payload.Devices; if (!Directory.Exists(Path.GetDirectoryName(devicesListPath))) { Directory.CreateDirectory(Path.GetDirectoryName(devicesListPath)); } File.WriteAllText(devicesListPath, JsonConvert.SerializeObject(DevicesList)); } }
public async void ControlDevicesAsync(string deviceId, int state) { if (SessionData.Expires_at < DateTimeOffset.Now.ToUnixTimeSeconds()) { await RefreshToken(); } var reqData = new DeviceRequest { Header = new DeviceRequest_Header { Name = "turnOnOff", Namespace = "control", PayloadVersion = 1, }, Payload = new DeviceRequest_Payload { AccessToken = SessionData.Access_token, DevId = deviceId, Value = state, } }; await ApiServices.PostJsonData <DeviceResponse>(deviceUri, reqData.ToString()); }