示例#1
0
        /// <summary>
        /// Sets the color of the target lamp to the given RGB value
        /// </summary>
        /// <param name="lampId">Target device ID</param>
        /// <param name="rgb">Desired color value by RGB</param>
        /// <returns>Controller response object</returns>
        public static ControllerResponse SetColorByRGB(int lampId, string rgb)
        {
            if (CheckDevice(lampId) == false)
            {
                return(new ControllerResponse(StatusCode.DeviceUnreachable));
            }

            _coapClient.UriPath = $"{CommandConstants.UniqueDevices}/{lampId}";
            var result = new ControllerResponse(_coapClient.Put("{ \"3311\":[{ \"5706\": \"" + rgb + "\"}]}"));

            if (result.StatusCode == StatusCode.Changed)
            {
                return((GetDevice(lampId) as Lamp)?.Color.ValueRgb == rgb ? result : new ControllerResponse(StatusCode.NotModified));
            }
            else
            {
                return(result);
            }
        }
示例#2
0
        /// <summary>
        /// Sets the state of the target lamp
        /// </summary>
        /// <param name="lampId">Target device ID</param>
        /// <param name="newState">Desired lamp state</param>
        /// <returns>Controller response object</returns>
        public static ControllerResponse SetState(int lampId, LampState newState)
        {
            if (CheckDevice(lampId) == false)
            {
                return(new ControllerResponse(StatusCode.DeviceUnreachable));
            }

            _coapClient.UriPath = $"{CommandConstants.UniqueDevices}/{lampId}";
            var result = new ControllerResponse(_coapClient.Put("{ \"3311\":[{ \"5850\": " + (int)newState + "}]}"));

            if (result.StatusCode == StatusCode.Changed)
            {
                return((GetDevice(lampId) as Lamp)?.State == newState ? result : new ControllerResponse(StatusCode.NotModified));
            }
            else
            {
                return(result);
            }
        }
示例#3
0
        /// <summary>
        /// Sets the color of the target lamp to the given color value
        /// </summary>
        /// <param name="lampId">Target device ID</param>
        /// <param name="newColor">Desired color</param>
        /// <returns>Controller response object</returns>
        public static ControllerResponse SetColor(int lampId, Color newColor)
        {
            if (CheckDevice(lampId) == false)
            {
                return(new ControllerResponse(StatusCode.DeviceUnreachable));
            }

            _coapClient.UriPath = $"{CommandConstants.UniqueDevices}/{lampId}";
            var result = new ControllerResponse(_coapClient.Put("{ \"3311\":[{ \"5709\": " + newColor.Value5709 + ", \"5710\": " + newColor.Value5710 + "}]}"));

            if (result.StatusCode == StatusCode.Changed)
            {
                return((GetDevice(lampId) as Lamp)?.Color == newColor ? result : new ControllerResponse(StatusCode.NotModified));
            }
            else
            {
                return(result);
            }
        }