Example #1
0
        private void ExecuteActions(ActionTrigger location)
        {
            var actions = _actionRepository.GetToExecute(location);
            var fifthplayCredentials = _credentialsRepository.GetFifthplay();
            var iftttKey             = _credentialsRepository.GetIfttt();
            var timestamp            = DateTimeOffset.UtcNow;

            Parallel.ForEach(actions, action =>
            {
                try
                {
                    switch (action.ActionTypeName)
                    {
                    case "switch":
                        _fifthplayRepository.SwitchSmartPlug(fifthplayCredentials.Username, fifthplayCredentials.Password,
                                                             action.DeviceIdentifier, (action.ActionArgumentValue == "on" ? true : false));
                        break;

                    case "IFTTT Maker Event":
                        _iftttRepository.TriggerEvent(iftttKey, "homebased", location.ToString(), null, null);
                        break;

                    default:
                        throw new InvalidOperationException($"Action type {action.ActionTypeName} unsupported");
                    }

                    _logger.Log(action, timestamp);
                }
                catch (Exception ex)
                {
                    _logger.Log(ex, action, timestamp);
                }
            });
        }
Example #2
0
        /// <summary>
        /// IFTTT credentials might be present from a previous installation without the required configuration
        /// </summary>
        private void RestoreIfttt()
        {
            var key = _credentialsRepository.GetIfttt();

            if (!string.IsNullOrWhiteSpace(key) &&
                !_deviceRepository.HasDevices())
            {
                _iftttConnector.Connect(key);
            }
        }
Example #3
0
        public override Task LoadViewModel()
        {
            var key = _credentialsRepository.GetIfttt();

            if (!string.IsNullOrWhiteSpace(key))
            {
                Key = key;
            }

            return(base.LoadViewModel());
        }