public async Task <ApiTradfriGroup> SetMood(long id, [FromBody] ApiTradfriMood value) { if (value != null) { var mood = new TradfriMood { CreatedAt = value.CreatedAt, GroupID = value.GroupID, ID = value.ID, Name = value.Name, The9057 = value.The9057, The9068 = value.The9068, MoodProperties = value.MoodProperties?.Select(m => new TradfriMoodProperties { ColorHex = m.ColorHex, ColorHue = m.ColorHue, ColorSaturation = m.ColorSaturation, ColorX = m.ColorX, ColorY = m.ColorY, Dimmer = m.Dimmer, ID = m.ID, LightState = m.LightState, Mireds = m.Mireds }).ToArray() }; await _controller.GroupController.SetMood(id, mood); } return(await GetByIdAsync(id)); }
private async void btnMood_ClickAsync(object sender, EventArgs e) { TradfriGroup group = (TradfriGroup)dgvGroups.Rows[0].DataBoundItem; List <TradfriMood> moods = new List <TradfriMood>(await tradfriController.GatewayController.GetMoods()).OrderBy(x => x.Name).ToList(); TradfriMood relaxMood = moods.First(m => m.Name.Equals("RELAX", StringComparison.OrdinalIgnoreCase) && m.GroupID.Equals(group.ID)); // recommended if you want to use group instance later on tradfriController.GroupController.SetMood(group, relaxMood); // just change the mood //tradfriController.GroupController.SetMood(relaxMood.GroupID, relaxMood.ID); /* * set custom tradfri mood properties to every bulb in a group * tradfriController.GroupController.SetMood(groups[0].ID, new TradfriMoodProperties * { * ColorHex = "f1e0b5", * ColorHue = 24394, * ColorSaturation = 5800, * ColorX = 65535, * ColorY = 65535, * Dimmer = 254, * ID = 1, * LightState = 1, * Mireds = 0 * }); */ }
public async Task Setup() { BaseSetup(); controller = tradfriController.GroupController; groups = new List <TradfriGroup>(await tradfriController.GatewayController.GetGroupObjects()); group = groups.FirstOrDefault(); mood = (await tradfriController.GatewayController.GetMoods()).FirstOrDefault(); }
/// <summary> /// Sets a mood for the group /// </summary> /// <param name="id">Id of the group</param> /// <param name="mood">TradfriMood object which needs to be set</param> /// <returns></returns> public async Task SetMood(long id, TradfriMood mood) { await HandleRequest($"/{(int)TradfriConstRoot.Groups}/{id}", Call.PUT, content : mood.MoodProperties[0], statusCode : System.Net.HttpStatusCode.NoContent); var set = new SwitchStateRequestOption() { Mood = mood.ID }; await HandleRequest($"/{(int)TradfriConstRoot.Groups}/{id}", Call.PUT, content : set, statusCode : System.Net.HttpStatusCode.NoContent); }
public static ApiTradfriMood Map(TradfriMood mood) { return(mood != null ? new ApiTradfriMood { CreatedAt = mood.CreatedAt, GroupID = mood.GroupID, ID = mood.ID, MoodProperties = mood.MoodProperties?.Select(moodProp => Map(moodProp)).ToArray(), Name = mood.Name, The9057 = mood.The9057, The9068 = mood.The9068 } : null); }
/// <summary> /// Acquire TradfriMoods by groups /// </summary> /// <returns></returns> public async Task <List <TradfriMood> > GetMoods() { List <TradfriMood> moods = new List <TradfriMood>(); foreach (int groupID in await MakeRequest <List <int> >($"/{(int)TradfriConstRoot.Moods}")) { foreach (int moodID in await MakeRequest <List <int> >($"/{(int)TradfriConstRoot.Moods}/{groupID}")) { TradfriMood mood = await MakeRequest <TradfriMood>($"/{(int)TradfriConstRoot.Moods}/{groupID}/{moodID}"); mood.GroupID = groupID; moods.Add(mood); } } return(moods); }
/// <summary> /// Sets a mood for the group /// </summary> /// <param name="mood">TradfriMood object which needs to be set</param> /// <returns></returns> public Response SetMood(TradfriMood mood) { Response request = _coapClent.UpdateValues(new TradfriRequest { UriPath = $"/{(int)TradfriConstRoot.Groups}/{_id}", Payload = JsonConvert.SerializeObject(mood.MoodProperties[0]) }); if (_group != null && request.CodeString.Equals("2.04 Changed")) { _group.ActiveMood = mood.ID; } return(_coapClent.UpdateValues(new TradfriRequest { UriPath = $"/{(int)TradfriConstRoot.Groups}/{_id}", Payload = string.Format(@"{{""{0}"":{1}}}", (int)TradfriConstAttribute.Mood, mood.ID) })); }
/// <summary> /// Set Dimmer for Light Devices in Group /// </summary> /// <param name="group">A <see cref="TradfriGroup"/></param> /// <param name="value">Dimmer intensity (0-255)</param> /// <returns></returns> public async Task SetDimmer(TradfriGroup group, TradfriMood mood) { await SetMood(group.ID, mood); group.ActiveMood = mood.ID; }