private void btnSave_Click(object sender, RoutedEventArgs e) { Schedule sc = _scheduleMv.GetSchedule(); CommandResult comres; if (actualobj is Schedule) { comres = _bridge.ModifyObject <Schedule>(sc, actualobj.Id); } else { comres = _bridge.CreateObject <Schedule>(sc); } if (comres.Success) { DialogResult = true; MessageCollection mc = (MessageCollection)comres.resultobject; actualobj = new Schedule() { Id = mc[0].ToString() }; Close(); } else { MessageBox.Show($"{GlobalStrings.Error_ErrorHasOccured} : {_bridge.lastMessages.ToString()}", GlobalStrings.Error, MessageBoxButton.OK, MessageBoxImage.Error); } }
public Form_GroupCreator(HueObject selectedGroup) { InitializeComponent(); gcvm = this.DataContext as GroupCreatorViewModel; gcvm.Group = (Group)selectedGroup; btnCreateGroup.Content = GUI.GroupCreatorForm_ModifyGroupButton; }
private void FillActionPropertyFromAction() { if (_selectedAction == null) { return; } _listboxActionPropertyInfos.Clear(); PropertyInfo[] prop = _selectedAction.body.GetType().GetProperties(); foreach (PropertyInfo p in prop) { if (p.GetValue(_selectedAction.body) == null) { continue; } _listboxActionPropertyInfos.Add(new KeyValuePair <PropertyInfo, dynamic>(p, p.GetValue(_selectedAction.body))); } string[] adr = _selectedAction.address.Split('/'); SelectedActionType = adr[1]; SelectedActionObject = ListActionObjects.Find(x => x.Id == adr[2]); if (SelectedActionObject == null) { _selectedActionObject = null; _selectedActionType = null; ResetActionPropertyFields(); } OnPropertyChanged("CanChangeAction"); OnPropertyChanged("CanAddAction"); }
public SceneCreatorView(List <HueObject> listlights, HueObject obj) { _scene = (Scene)obj; _listAvailableLights = new ObservableCollection <HueObject>(listlights); _listSceneLights = new ObservableCollection <HueObject>(); _cansavescene = true; _canpreviewscene = true; OnPropertyChanged("CanSaveSecene"); OnPropertyChanged("CanPreviewScene"); foreach (string s in _scene.lights) { int index = _listAvailableLights.FindIndex(x => x.Id == s); if (index == -1) { continue; } if (!_scene.lightstates.ContainsKey(s)) { continue; } ((Light)_listAvailableLights[index]).state = _scene.lightstates[s]; _listSceneLights.Add(_listAvailableLights[index]); _listAvailableLights.RemoveAt(index); } foreach (HueObject light in _listAvailableLights) { ((Light)light).state = new State(); } _newstate = new State { @on = true }; }
void bgWorker_DoWork(object sender, DoWorkEventArgs e) { SetPreviewBtn(false); ObservableCollection <HueObject> li = (ObservableCollection <HueObject>)e.Argument; ObservableCollection <HueObject> liOriginalState = new ObservableCollection <HueObject>(); foreach (HueObject obj in li) { HelperResult hr = HueObjectHelper.GetObject <Light>(BridgeStore.SelectedBridge, obj.Id); if (hr.Success) { HueObject newlight = (HueObject)hr.Hrobject; ((Light)newlight).state.alert = null; liOriginalState.Add(newlight); } } foreach (HueObject obj in li) { BridgeStore.SelectedBridge.SetState <Light>(((Light)obj).state, obj.Id); } Thread.Sleep(5000); foreach (HueObject obj in liOriginalState) { BridgeStore.SelectedBridge.SetState <Light>(((Light)obj).state, obj.Id); } Thread.Sleep(2000); SetPreviewBtn(true); }
/// <summary> /// Return the object latest values from the selected bridge. /// </summary> /// <param name="bridge">Bridge to get the object from.</param> /// <param name="obj">Object to get values.</param> /// <returns>The latest values of the object.</returns> public static HueObject GetBridgeObject(Bridge bridge, HueObject obj) { if (obj == null) { return(null); } log.Debug($@"Fetching object : {obj.Id} of type {obj.GetType()}"); if (obj is Light) { return(GetBridgeLight(bridge, obj.Id)); } if (obj is Group) { return(GetBridgeGroup(bridge, obj.Id)); } if (obj is Scene) { return(GetBridgeScene(bridge, obj.Id)); } if (obj is Schedule) { return(GetBridgeSchedule(bridge, obj.Id)); } if (obj is Sensor) { return(GetBridgeSensor(bridge, obj.Id)); } if (obj is Rule) { return(GetBridgeRule(bridge, obj.Id)); } return(null); }
void bgWorker_DoWork(object sender, DoWorkEventArgs e) { SetPreviewBtn(false); ObservableCollection <HueObject> li = (ObservableCollection <HueObject>)e.Argument; ObservableCollection <HueObject> liOriginalState = new ObservableCollection <HueObject>(); foreach (HueObject obj in li) { HueObject newlight = HueObjectHelper.GetBridgeLight(_bridge, obj.Id); ((Light)newlight).state.alert = null; liOriginalState.Add(newlight); } foreach (HueObject obj in li) { _bridge.SetLightState(obj.Id, ((Light)obj).state); } Thread.Sleep(5000); foreach (HueObject obj in liOriginalState) { _bridge.SetLightState(obj.Id, ((Light)obj).state); } Thread.Sleep(2000); SetPreviewBtn(true); }
public Form_SceneCreator(Bridge bridge, HueObject obj) { InitializeComponent(); _id = ((Scene)obj).Id; scv = new SceneCreatorView(HueObjectHelper.GetBridgeLights(bridge), obj, bridge); DataContext = scv; _br = bridge; }
public Form_RenameObject(Bridge bridge, HueObject obj) { InitializeComponent(); _bridge = bridge; _obj = obj; Title = string.Format(Title, obj.GetName()); tbNewName.Text = obj.GetName(); }
public Form_Daylight(Bridge bridge, HueObject obj) { InitializeComponent(); br = bridge; id = obj.Id; daylightView = new DaylightView(br.GetSensor("1")); DataContext = daylightView; }
public RuleCreatorView(List <HueObject> listObjects, HueObject modifiedRule) { _rule = (Rule)modifiedRule; _listDataStore = listObjects; _listcbsensors = listObjects.OfType <Sensor>().ToList <HueObject>(); _listboxConditions = new ObservableCollection <RuleCondition>(_rule.conditions); _listboxActions = new ObservableCollection <RuleAction>(_rule.actions); _listboxActionPropertyInfos = new ObservableCollection <KeyValuePair <PropertyInfo, dynamic> >(); }
public Form_GroupCreator(Bridge bridge, HueObject selectedGroup) { InitializeComponent(); _bridge = bridge; gcv = new GroupCreatorView(HueObjectHelper.GetBridgeLights(_bridge), (Group)selectedGroup); DataContext = gcv; Title = string.Format(GUI.GroupCreatorForm_ModifyingGroup_Title, ((Group)selectedGroup).name); btnCreateGroup.Content = GUI.GroupCreatorForm_ModifyGroupButton; DataContext = gcv; }
public Form_RulesCreator2(Bridge bridge, HueObject rule) { InitializeComponent(); _br = bridge; rcv = new RuleCreatorView(HueObjectHelper.GetBridgeDataStore(bridge), rule); DataContext = rcv; editedRule = (Rule)rule; Title = $"Editing rule {((Rule)rule).name}..."; btnCreateRule.Content = "Update"; }
private void ResetConditionFields() { _selectedOperator = null; OnPropertyChanged("SelectedOperator"); _selectedSensor = null; OnPropertyChanged("SelectedSensor"); _selectedPropertyInfo = null; OnPropertyChanged("SelectedPropertyInfo"); _conditionvalue = string.Empty; OnPropertyChanged("ConditionValue"); }
private void ClearFields() { _selectedavailableLight = null; _selectedgrouplight = null; foreach (HueObject obj in GroupCreator.GroupLightList) { GroupCreator.AvailableLightList.Add(obj); } GroupCreator.GroupLightList.Clear(); GroupCreator.Name = string.Empty; }
public static void SetName(this HueObject obj, string newName) { if (newName == null) { return; } if (!obj.HasProperty("name")) { return; } obj.GetType().GetProperty("name").SetValue(obj, newName); }
/// <summary> /// ctor /// </summary> /// <param name="br">Current bridge.</param> /// <param name="obj">object being scheduled.</param> public Form_ScheduleCreator(Bridge br, HueObject obj) { _scheduleMv = new ScheduleView(obj, br.ApiKey); DataContext = _scheduleMv; InitializeComponent(); _bridge = br; actualobj = obj; Title = obj is Schedule ? GUI.ScheduleCreatorForm_Title_Modify + obj.GetName() : GUI.ScheduleCreatorForm_Title_Create + obj.GetName(); }
private void ClearFields() { _selectedavailableLight = null; _selectedgrouplight = null; foreach (HueObject obj in _grouplights) { _lightlist.Add(obj); } _grouplights.Clear(); GroupName = string.Empty; SetError(GlobalStrings.Group_Select_One_Light, "GroupLightList"); }
public void ClearSelectionSceneLight() { _selectedSceneLight = null; SceneOn = true; OnPropertyChanged("SelectedSceneLight"); OnPropertyChanged("Hue"); OnPropertyChanged("Sat"); OnPropertyChanged("Bri"); OnPropertyChanged("CT"); OnPropertyChanged("X"); OnPropertyChanged("Y"); OnPropertyChanged("TT"); }
public Form_SceneCreator(Bridge bridge, HueObject obj) { InitializeComponent(); _currentscene = ((Scene)obj); HelperResult hr = HueObjectHelper.GetObjectsList <Light>(bridge); if (hr.Success) { scv = new SceneCreatorView((List <HueObject>)hr.Hrobject, obj); DataContext = scv; _br = bridge; } }
private void RemoveSelectedSceneLight() { ((Light)_selectedSceneLight).state = new State(); _scene.lights.Remove(_selectedSceneLight.Id); _listAvailableLights.Add(_selectedSceneLight); _listSceneLights.Remove(_selectedSceneLight); _selectedSceneLight = null; if (_listSceneLights.Count == 0) { SetError(GlobalStrings.Scene_SelectOneLight, "ListSceneLights"); } OnPropertyChanged("SelectedSceneLight"); CanSaveScene = _listSceneLights.Count > 0; }
public ScheduleView(HueObject obj, string apikey) { _objid = obj.Id; _api = apikey; if (obj is Schedule) { _schedule = (Schedule)obj; _schedule.time = null; _type = GetScheduleTypeFromTime(_schedule.localtime); TimeFormatString = _type == "T" ? "yyyy-MM-dd HH:mm:ss" : "HH:mm:ss"; if (_type == "W") { _smask = GetMaskFromAlarm(_schedule.localtime); } if (_schedule.localtime.Contains("A")) { _schedule.localtime = _schedule.localtime.Remove(_schedule.localtime.IndexOf("A"), _schedule.localtime.Length - _schedule.localtime.IndexOf("A")); _smask = "127"; } else { _randomizetime = string.Empty; _smask = "127"; } } else { _schedule = new Schedule { command = new Command { body = new Body() } }; _timeformat = "yyyy-MM-dd HH:mm:ss"; _type = "T"; _smask = "127"; _randomizetime = string.Empty; _schedule.command.body.on = true; _schedule.localtime = BuildScheduleLocaltime(DateTime.Now.AddMinutes(5), _type); _schedule.command.method = "PUT"; _objtype = obj is Light ? "lights" : "groups"; SetAddress(); } OnPropertyChanged("ScheduleMask"); OnPropertyChanged("StartTimeText"); }
public Form_GroupCreator(Bridge bridge, HueObject selectedGroup) { InitializeComponent(); _bridge = bridge; HelperResult hr = HueObjectHelper.GetBridgeLights(_bridge); if (hr.Success) { gcv = new GroupCreatorView((List <HueObject>)hr.Hrobject, (Group)selectedGroup); Title = string.Format(GUI.GroupCreatorForm_ModifyingGroup_Title, ((Group)selectedGroup).name); btnCreateGroup.Content = GUI.GroupCreatorForm_ModifyGroupButton; DataContext = gcv; } else { MessageBoxError.ShowLastErrorMessages(_bridge); this.Close(); } }
private object ParseObject(JToken token) { switch (token.Type) { case JTokenType.Object: HueObject hobj = new HueObject(); foreach (var child in token.Children <JProperty>()) { hobj.SetProperty(child.Name, ParseObject(child.Value)); } return(hobj); case JTokenType.Array: return(token.Select(ParseObject).ToArray()); //return token.Select(ParseObject).ToList(); default: return(((JValue)token).Value); } }
private void ApplyMood(HueObject obj, Mood mood) { /* dynamic state; * * if (obj is Light) * { * state = new State(); * } * else * { * state = new Action(); * } * * if (mood.hue != null) state.hue = mood.hue; * * if (mood.sat != null) state.sat = mood.sat; * * if (mood.bri != null) state.bri = mood.bri; * * if (mood.ct != null) state.ct = mood.ct; * * if (mood.transitiontime != null) state.transitiontime = mood.transitiontime; * * if (mood.xy != null) * { * state.xy = new XY(); * * if (mood.xy.x != null) state.xy.x = mood.xy.x; * if (mood.xy.y != null) state.xy.y = mood.xy.y; * } * * if (obj is Light) * { * // _bridge.SetLightState(obj.Id, state); * } * else * { * // _bridge.SetGroupAction(obj.Id, state); * }*/ }
public Form_RulesCreator2(Bridge bridge, HueObject rule) { InitializeComponent(); _br = bridge; HelperResult hr = HueObjectHelper.GetBridgeDataStore(bridge); List <HueObject> listobj; if (hr.Success) { listobj = (List <HueObject>)hr.Hrobject; } else { listobj = new List <HueObject>(); } rcv = new RuleCreatorView(listobj, rule); DataContext = rcv; editedRule = (Rule)rule; id = editedRule.Id; Title = $"Editing rule {((Rule)rule).name}..."; btnCreateRule.Content = "Update"; }
private void SerializeHueObject(HueObject obj, JsonWriter writer) { obj.RemoveProperty("Id"); obj.RemoveProperty("Image"); writer.WriteStartObject(); foreach (KeyValuePair <string, object> kvp in obj) { writer.WritePropertyName(kvp.Key); if (kvp.Value is HueObject) { SerializeHueObject((HueObject)kvp.Value, writer); } else { if (kvp.Value is Array || kvp.Value.GetType() == typeof(List <>)) { writer.WriteStartArray(); foreach (object o in (Array)kvp.Value) { if (o is HueObject) { SerializeHueObject((HueObject)o, writer); } else { writer.WriteValue(o); } } writer.WriteEnd(); } else { writer.WriteValue(kvp.Value); } } } writer.WriteEnd(); }
public static string GetName(this HueObject obj) { return(obj.HasProperty("name") ? obj.GetType().GetProperty("name").GetValue(obj).ToString() : "Unknown"); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { HueObject hue = (HueObject)value; SerializeHueObject(hue, writer); }
public HueObjectPropertyDescriptor([NotNull] HueObject hobj, Type propertyType, [NotNull] string name, Attribute[] attrs) : base(name, attrs) { _hueObject = hobj; _propertyType = propertyType; }