/// <summary>
        /// Turns a specific light on or off
        /// </summary>
        /// <param name="id">Id of the device</param>
        /// <param name="state">On (True) or Off(false)</param>
        /// <returns></returns>
        public async Task SetLight(long id, bool state)
        {
            SwitchStateLightRequest set = new SwitchStateLightRequest()
            {
                Options = new[]
                {
                    new SwitchStateLightRequestOption()
                    {
                        IsOn = state ? 1 : 0
                    }
                }
            };

            await HandleRequest($"/{(int)TradfriConstRoot.Devices}/{id}", Call.PUT, content : set);
        }
Esempio n. 2
0
        /// <summary>
        /// Set Dimmer for Light Device
        /// </summary>
        /// <param name="id">Id of the device</param>
        /// <param name="value">Dimmer intensity (0-255)</param>
        /// <returns></returns>
        public async Task SetDimmer(long id, int value)
        {
            SwitchStateLightRequest set = new SwitchStateLightRequest()
            {
                Options = new[]
                {
                    new SwitchStateLightRequestOption()
                    {
                        LightIntensity = value
                    }
                }
            };

            await HandleRequest($"/{(int)TradfriConstRoot.Devices}/{id}", Call.PUT, content : set, statusCode : System.Net.HttpStatusCode.NoContent);
        }
        /// <summary>
        /// Changes the color of the light device
        /// </summary>
        /// <param name="id">Id of the device</param>
        /// <param name="value">A color from the <see cref="TradfriColors"/> class</param>
        /// <param name="transition">An optional transition duration, defaults to null (no transition)</param>
        /// <returns></returns>
        public async Task SetColor(long id, string value, int?transition = null)
        {
            SwitchStateLightRequest set = new SwitchStateLightRequest()
            {
                Options = new[]
                {
                    new SwitchStateLightRequestOption()
                    {
                        Color          = value,
                        TransitionTime = transition
                    }
                }
            };

            await HandleRequest($"/{(int)TradfriConstRoot.Devices}/{id}", Call.PUT, content : set, statusCode : System.Net.HttpStatusCode.NoContent);
        }
Esempio n. 4
0
        /// <summary>
        /// Set Dimmer for Light Device
        /// </summary>
        /// <param name="id">Id of the device</param>
        /// <param name="value">Dimmer intensity (0-255)</param>
        /// <param name="transition">An optional transition duration, defaults to null (no transition)</param>
        /// <returns></returns>
        public async Task SetDimmer(long id, int value, int?transition = null)
        {
            SwitchStateLightRequest set = new SwitchStateLightRequest()
            {
                Options = new[]
                {
                    new SwitchStateLightRequestOption()
                    {
                        LightIntensity = value,
                        TransitionTime = transition
                    }
                }
            };

            await MakeRequest($"/{(int)TradfriConstRoot.Devices}/{id}", Call.PUT, content : set);
        }