/// <summary> /// adds an Item, only if it doesnt exist. /// /// </summary> /// <param name="newItem"></param> /// <returns>returns false, if Item already existed</returns> public bool addItem(ItemStateOpenHAB newItem) { if (!States.Contains(newItem)) { States.Add(newItem); return(true); } else { return(false); } }
/// <summary> /// Updates a State from an Item if item exist. /// </summary> /// <param name="name"></param> /// <param name="newState"></param> /// /// <param name="publishMessage">should the message be send to OpenHAB?</param> /// <returns></returns> public bool updateItem(string name, string newState, bool publishMessage) { ItemStateOpenHAB toUpdate = getItemByName(name); if (toUpdate == null) { //Debug.Log("UpdateItem 2: contains no item named: " + toUpdate.name); return(false); } else { string oldState = toUpdate.state; toUpdate.state = newState; //Debug.Log("Old State = " + oldState + " New State = " + newState); //if state change then invoke subscribtions if (!newState.Equals(oldState)) { //Debug.Log("UpdateItem 2: put on changed list: " + toUpdate.name); if (!hasChangedList.Contains(toUpdate)) { hasChangedList.Add(toUpdate); } } //but publish anyways if (publishMessage) { // Debug.Log("UpdateItem 2: send Message async: " + toUpdate.name); restCommunicator.Instance.publishItemStateopenHAB(toUpdate); } //Debug.Log("UpdateItem 2: returns " + toUpdate.name); return(true); } }
/// <summary> /// Updates a State from an Item if item exist. /// </summary> /// <param name="updatedItem"></param> /// <param name="publishMessage">should the message be send to OpenHAB?</param> /// /// <returns>returns false, if Item doesnt exist</returns> public bool updateItem(ItemStateOpenHAB updatedItem, bool publishMessage) { if (!States.Contains(updatedItem)) { //Debug.Log("UpdateItem 1: contains no item named: " + updatedItem.name); return(false); } ItemStateOpenHAB olditem = getItemByName(updatedItem.name); string oldState = olditem.state; //Item should exist //search for it and remove it States.Remove(olditem); States.Add(updatedItem); //only if state changed then invoke subscribtions if (!updatedItem.state.Equals(oldState)) { //Debug.Log("UpdateItem 1: put on changed list: " + updatedItem.name); // invokeSubscriber(updatedItem.name); if (!hasChangedList.Contains(updatedItem)) { hasChangedList.Add(updatedItem); } } //publish if wanted if (publishMessage) { //Debug.Log("UpdateItem 1: send Message async: " + updatedItem.name); restCommunicator.Instance.publishItemStateopenHAB(updatedItem); } //Debug.Log("UpdateItem 1: returns " + updatedItem.name); return(true); }