/// <summary> /// Overwrites the list of <see cref="Leds"/> of the <see cref="Group"/> having the passed ID with the passed LED list. /// Note that the specified LEDs must exist, otherwise non-existing LEDs will not be added. /// The methods throws a <see cref="ResourceNotFoundException"/> if the underlying <see cref="Group"/> does not exist. /// </summary> /// <param name="id"><see cref="Group.Id"/></param> /// <param name="groupLeds">list with LEDs</param> public void SetLedsOfGroup(int id, GroupLeds groupLeds) { if (_groupStorage.HasGroup(id)) { IList <string> ledIds = new List <string>(); foreach (Led led in groupLeds.Leds) { string ledId = led.ControllerId + ":" + led.LedNumber; if (_ledStorage.HasLed(ledId)) { ledIds.Add(ledId); } } _groupStorage.SetLeds(id, ledIds); } else { throw new ResourceNotFoundException(ResourceNotFoundException.MSG_GROUP_NOT_FOUND.Replace("{VALUE}", id + "")); } }
/// <summary> /// Sets the color of the <see cref="Led"/> having the specified ID. /// The method throws a <see cref="ResourceNotFoundException"/> if the underlying <see cref="Led"/> does not exist. /// The method throws a <see cref="BadRequestException"/> if the passed ID is invalid. /// </summary> /// <param name="ledId">ID of the <see cref="Led"/> whose color should be changed</param> /// <param name="rbg">desired RGB value</param> public void SetColor(string ledId, string rgb) { string[] split = ledId.Split(':'); if (split.Length != 2) { throw new BadRequestException(BadRequestException.MSG_INVALID_LED_ID); } else { int controllerId = ApiBase.ParseInt(split[0], BadRequestException.MSG_INVALID_LED_ID); int ledNumber = ApiBase.ParseInt(split[1], BadRequestException.MSG_INVALID_LED_ID); if (_ledStorage.HasLed(controllerId, ledNumber)) { _ledStorage.SetColor(controllerId, ledNumber, rgb); } else { throw new ResourceNotFoundException(ResourceNotFoundException.MSG_LED_NOT_FOUND.Replace("{VALUE}", ledId)); } } }