public async Task <IActionResult> OnPostSwitchOffAsync(int action)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await ActionsApi.RunActionsAsync(
                       accessToken,
                       new ActionToRun
            {
                DeviceID = Id,
                Actions = new List <ActionToRunItem>
                {
                    new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0)
                }
            },
                       new ResultHandler <ActionToRun>
            {
                OnError = DefaultErrorHandler.Handle
            }
                       ));
        }
Exemplo n.º 2
0
        /// <summary> Initializes a new instance of the Stackstorm.Api.Client.St2Client class. </summary>
        /// <exception cref="ArgumentException">Thrown when one or more arguments have unsupported or
        ///          illegal values. </exception>
        /// <param name="authUrl">        URL of the authentication endpoint. </param>
        /// <param name="apiUrl">        URL of the API. </param>
        /// <param name="username">        The username. </param>
        /// <param name="password">        The password. </param>
        /// <param name="ignoreCertificateValidation"> true to ignore certificate validation. </param>
        public St2Client(string authUrl, string apiUrl, string username, string password, bool ignoreCertificateValidation = false)
        {
            if (String.IsNullOrWhiteSpace(authUrl))
            {
                throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'authUrl'.",
                                            "authUrl");
            }

            if (String.IsNullOrWhiteSpace(apiUrl))
            {
                throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'apiUrl'.",
                                            "apiUrl");
            }

            if (String.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'password'.",
                                            "password");
            }

            if (String.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'username'.",
                                            "username");
            }

            _apiUrl   = new Uri(apiUrl);
            _authUrl  = new Uri(authUrl);
            _password = password;
            _username = username;

            if (ignoreCertificateValidation)
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            }

            Actions    = new ActionsApi(this);
            Packs      = new PacksApi(this);
            Executions = new ExecutionsApi(this);
            Rules      = new RulesApi(this);
            VSphere    = new VSphere(this);
            Core       = new Core(this);
            Email      = new Email(this);
            AzureGov   = new AzureGov(this);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await ActionsApi.GetActionsAsync(tokenData.AccessToken, Id, new ResultHandler <List <SmartMeApiClient.Containers.Action> >
            {
                OnSuccess = (actions) =>
                {
                    Actions = actions;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Exemplo n.º 4
0
 public void Init()
 {
     instance = new ActionsApi();
 }
        public static async Task ActionsAsync(UserPassword credentials)
        {
            // We will use this device to fetch its details later
            Device sampleDevice;

            // Get all devices
            {
                Helpers.WriteConsoleTitle("Get all devices");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}");
                }

                // Store the first device. Make sure you have at least one device in your smart-me account.
                sampleDevice = devices.First();
            }

            // Get Actions
            {
                Helpers.WriteConsoleTitle("Get Actions");

                List <SmartMeApiClient.Containers.Action> actions = await ActionsApi.GetActionsAsync(credentials, sampleDevice.Id);

                foreach (var action in actions)
                {
                    Console.WriteLine($"Name: {action.Name}, ObisCode: {action.ObisCode}");
                }
            }

            // Run Actions
            {
                Helpers.WriteConsoleTitle("Run Actions");

                await ActionsApi.RunActionsAsync(credentials, new ActionToRun
                {
                    DeviceID = sampleDevice.Id,
                    Actions  = new List <ActionToRunItem>
                    {
                        new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 1.0)
                    }
                });

                Console.WriteLine("Switch on");

                Thread.Sleep(5000);

                await ActionsApi.RunActionsAsync(credentials, new ActionToRun
                {
                    DeviceID = sampleDevice.Id,
                    Actions  = new List <ActionToRunItem>
                    {
                        new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0)
                    }
                });

                Console.WriteLine("Switch off");
            }
        }