Beispiel #1
0
        public IACSetting Update(IACSetting setting)
        {
            if (_currentAcDevice == null)
            {
                throw new CurrentACDeviceNotSetException();
            }

            var acSetting = _currentAcDevice.AvailableSettings?.SingleOrDefault(x => x.UniqueId.Equals(setting.UniqueId));

            if (acSetting == null)
            {
                throw new ItemNotFoundException("Cannot update - ACSetting with guid {guid} not found in current ACDevice available settings list");
            }
            acSetting = setting;
            return(acSetting);
        }
        private void ChangeACState(IACState newState)
        {
            if (_currentAcDevice == null)
            {
                throw new CurrentACDeviceNotSetException();
            }

            IACSetting acSetting = null;

            if (newState.ACSettingGuid != null)
            {
                acSetting = _currentAcDevice.AvailableSettings.SingleOrDefault(x => x.UniqueId.Equals(newState.ACSettingGuid));
            }

            //business logic:
            //if isoff=false and state null ->default on
            //isoff true - if state notnull and isoff - state code, if its not isoff - exception. if state null - default off
            //isoff null - what is in ACState
            //both null - exception

            switch (newState.IsTurnOff)
            {
            case null:
                if (acSetting == null)
                {
                    throw new ArgumentException("ACState is empty");
                }
                else
                {
                    ChangeACSetting(acSetting);
                }
                break;

            case false:
                if (acSetting == null)
                {
                    if (_currentAcDevice.DefaultTurnOnSetting != null)
                    {
                        ChangeACSetting(_currentAcDevice.DefaultTurnOnSetting);
                    }
                    else
                    {
                        throw new InvalidOperationException("Default TurnOnSetting in ACDevice not specified!");
                    }
                }

                else
                {
                    if (acSetting.IsTurnOff == false)
                    {
                        ChangeACSetting(acSetting);
                    }
                    else
                    {
                        throw new ArgumentException("IACState members inconsistency: IACState.IsTurnOff==false while IACState.ACSetting.IsTurnOff=true!");
                    }
                }
                break;

            case true:
                if (acSetting == null)
                {
                    if (_currentAcDevice.TurnOffSetting != null)
                    {
                        ChangeACSetting(_currentAcDevice.TurnOffSetting);
                    }
                    else
                    {
                        throw new InvalidOperationException("Default TurnOffSetting in ACDevice not specified!");
                    }
                }
                else
                {
                    if (acSetting.IsTurnOff == true)
                    {
                        ChangeACSetting(acSetting);
                    }
                    else
                    {
                        throw new ArgumentException("IACState members inconsistency: IACState.IsTurnOff==true while IACState.ACSetting.IsTurnOff=false!");
                    }
                }
                break;
            }
        }
 public void ChangeACSetting(IACSetting setting)
 {
     _irControlService.SendMessage(setting.Code);
 }