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 * }); */ }
/// <summary> /// Queries a single group by its unique group id /// </summary> /// <param name="groupId"></param> /// <returns></returns> public static TradfriGroup GetGroup(int groupId) { _coapClient.UriPath = $"{CommandConstants.Groups}/{groupId}"; Response response = _coapClient.Get(); return(TradfriGroup.Parse(response.PayloadString)); }
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> /// Acquires TradfriGroup object /// </summary> /// <param name="refresh">If set to true, than it will ignore existing cached value and ask the gateway for the object</param> /// <returns></returns> public TradfriGroup GetTradfriGroup(bool refresh = false) { if (!refresh && _group != null) { return(_group); } _group = JsonConvert.DeserializeObject <TradfriGroup>(Get().PayloadString); return(_group); }
public static ApiTradfriGroup Map(TradfriGroup group) { return(group != null ? new ApiTradfriGroup { ActiveMood = group.ActiveMood, CreatedAt = group.CreatedAt, Devices = Map(group.Devices), ID = group.ID, LightDimmer = group.LightDimmer, LightState = group.LightState, Name = group.Name } : null); }
private void btnRenameGroup_Click(object sender, EventArgs e) { try { TradfriGroup currentSelectedGroup = (TradfriGroup)dgvGroups.SelectedRows[0].DataBoundItem; tradfriController.GroupController.RenameTradfriGroup(currentSelectedGroup).Wait(); MessageBox.Show("Done", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message + Environment.NewLine + "First change the Name in column, leave the row selected and press the 'Rename' button." , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <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; }
/// <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, int value) { await SetDimmer(group.ID, value); group.LightDimmer = value; }
/// <summary> /// Turns a group of lights on or off /// </summary> /// <param name="group">A <see cref="TradfriGroup"/></param> /// <param name="state">On (True) or Off(false)</param> /// <returns></returns> public async Task SetLight(TradfriGroup group, bool state) { await SetLight(group.ID, state); group.LightState = 1; }
/// <summary> /// Renames TradfriGroup object /// </summary> /// <param name="group"></param> /// <returns></returns> public Task RenameTradfriGroup(TradfriGroup group) { return(RenameTradfriGroup(group.ID, group.Name)); }
/// <summary> /// Renames TradfriGroup object /// </summary> /// <param name="group"></param> /// <returns></returns> public async Task RenameTradfriGroup(TradfriGroup group) { RenameTradfriGroup(group.ID, group.Name); }