コード例 #1
0
        private bool ToggleDeviceSwitchLevel()
        {
            var deviceCurrentStatus = new Dictionary <string, AttributeState>();

            if (this.smartThingsClient.TryGetDeviceCapabilityStatus(this.device.DeviceId, this.device.Components[0].Id, "switchLevel", out deviceCurrentStatus) &&
                deviceCurrentStatus.Count > 0)
            {
                string currentLevel = deviceCurrentStatus["level"].Value.ToString();

                var commandArgs = new List <object>()
                {
                    { currentLevel == "0" ? 100 : 0 }
                };
                var command = new DeviceCommand(capability: "switchLevel", command: "setLevel", arguments: commandArgs);

                var commandsRequest = new DeviceCommandsRequest()
                {
                    Commands = new List <DeviceCommand>()
                };
                commandsRequest.Commands.Add(command);
                this.smartThingsClient.ExecuteDevicecommand(this.device.DeviceId, commandsRequest);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        private bool ToggleDeviceSwitch()
        {
            var deviceCurrentStatus = new Dictionary <string, AttributeState>();

            if (this.smartThingsClient.TryGetDeviceCapabilityStatus(this.device.DeviceId, this.device.Components[0].Id, "switch", out deviceCurrentStatus) &&
                deviceCurrentStatus.Count > 0)
            {
                string state    = deviceCurrentStatus["switch"].Value.ToString().ToLower();
                string newState = state == "on" ? "off" : "on";

                DeviceCommandsRequest commandsRequest = new DeviceCommandsRequest()
                {
                    Commands = new List <DeviceCommand>()
                };
                DeviceCommand command = new DeviceCommand(capability: "switch", command: newState);
                commandsRequest.Commands.Add(command);
                this.smartThingsClient.ExecuteDevicecommand(this.device.DeviceId, commandsRequest);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        private void UpdateComponentStatus()
        {
            if (SelectedItem != null && _componentFrame != null)
            {
                Device selectedDevice = (Device)SelectedItem;
                try
                {
                    var componentCapabilityStatus = JsonConvert.DeserializeObject <AttributeState>(_capabilitiesStatusJsonView.Text.ToString());

                    var commandsRequest = new DeviceCommandsRequest()
                    {
                        Commands = new List <DeviceCommand>()
                    };

                    //foreach (var statusUpdate in componentCapabilityStatus)
                    //{
                    //    var command = new DeviceCommand(
                    //  capability: statusUpdate.Key, // selectedDevice.Components.FirstOrDefault().Capabilities[_selectedCapabilityIndex].Id,
                    //  command: statusUpdate.Value);

                    //    commandsRequest.Commands.Add(command);
                    //}

                    var command = new DeviceCommand(
                        capability: selectedDevice.Components.FirstOrDefault().Capabilities[_selectedCapabilityIndex].Id,
                        command: (string)componentCapabilityStatus.Value);

                    commandsRequest.Commands.Add(command);
                    object response = STClient.ExecuteDevicecommand(selectedDevice.DeviceId, commandsRequest);
                    ShowStatusBarMessage($"Executed: {DateTime.UtcNow.ToLongTimeString()}");
                }
                catch (SmartThingsNet.Client.ApiException exp)
                {
                    ShowErrorMessage($"Error {exp.ErrorCode}{Environment.NewLine}{exp.Message}");
                }
                catch (Exception exp)
                {
                    ShowErrorMessage($"Error {exp.Message}");
                }
            }
        }
コード例 #4
0
        private void ToggleDeviceSwitch()
        {
            if (SelectedItem != null)
            {
                Device selectedDevice = (Device)SelectedItem;
                try
                {
                    var deviceCurrentStatus = STClient.GetDeviceCapabilityStatus(selectedDevice.DeviceId, selectedDevice.Components[0].Id, "switch");

                    if (deviceCurrentStatus.Count > 0)
                    {
                        string state    = deviceCurrentStatus["switch"].Value.ToString().ToLower();
                        string newState = state == "on" ? "off" : "on";

                        DeviceCommandsRequest commandsRequest = new DeviceCommandsRequest()
                        {
                            Commands = new List <DeviceCommand>()
                        };
                        DeviceCommand command = new DeviceCommand(capability: "switch", command: newState);
                        commandsRequest.Commands.Add(command);
                        STClient.ExecuteDevicecommand(selectedDevice.DeviceId, commandsRequest);
                        //ShowStatusBarMessage($"Switch {newState} at {DateTime.UtcNow.ToLongTimeString()}");
                    }
                    else
                    {
                        ShowErrorMessage($"{selectedDevice.Name} has no switch capability");
                    }
                }
                catch (SmartThingsNet.Client.ApiException exp)
                {
                    ShowErrorMessage($"Error {exp.ErrorCode}{Environment.NewLine}{exp.Message}");
                }
                catch (Exception exp)
                {
                    ShowErrorMessage($"Error {exp.Message}");
                }
            }
        }
コード例 #5
0
 public object ExecuteDevicecommand(string deviceId, DeviceCommandsRequest commandRequest)
 {
     return(_devicesApi.ExecuteDeviceCommands(_accessToken, deviceId, commandRequest));
 }