예제 #1
0
        private async void UpdateBridgeName(string newName)
        {
            Bridge currentBridge = BridgeManager.Instance.CurrentBridge;

            if (newName.Trim().Length == 0)
            {
                // Revert to original name
                NameInput.Text = currentBridge.Name;
            }
            else
            {
                // The API allows no longer than 16 characters for the name, and no less than 4
                string truncatedName;
                if(newName.Length < 4)
                {
                    truncatedName = currentBridge.Name;
                }
                else if(newName.Length > 16)
                {
                    truncatedName = newName.Substring(0, 16);
                }
                else
                {
                    truncatedName = newName;
                }

                var attrs = new { name = truncatedName };
                await HueAPI.Instance.SetBridgeConfigurationsAsync(attrs);

                currentBridge.Name = truncatedName;
                BridgeManager.Instance.InvalidateBridgeProperties();
            }
        }
예제 #2
0
        private void BrightnessSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            LightSource.Brightness = (int)BrightnessSlider.Value;
            BridgeManager.Instance.InvalidateLightProperties(LightSource);

            SaturationSliderHighlightBrush.Color = HSBColor.FromHSB(LightSource.Hue, LightSource.Saturation, LightSource.Brightness);

            var attrs = new { bri = LightSource.Brightness };
            UpdateLightStateAsync(attrs);
        }
예제 #3
0
        private void OnHueValueChanged(object sender, EventArgs e)
        {
            LightSource.Hue = HueDialer.CurrentValue;
            BridgeManager.Instance.InvalidateLightProperties(LightSource);

            var attrs = new { hue = HueDialer.CurrentValue };
            UpdateLightStateAsync(attrs);

            SaturationSliderHighlightBrush.Color = HSBColor.FromHSB(LightSource.Hue, LightSource.Saturation, LightSource.Brightness);
        }
예제 #4
0
        public static Schedule newAllOnSchedule()
        {
            Schedule schedule = new Schedule();
            schedule.Name = Schedule.DefaultAllOnScheduleName;
            schedule.Description = "Turn all the lights on";
            schedule.AppName = HueAPI.Instance.AppKey;
            schedule.Type = ScheduleType.Recurring;

            var address = "/api/" + HueAPI.Instance.AppKey + "/groups/0/action";
            var bodyParams = new { on = true };
            var commandBody = new { address = address, method = "PUT", body = bodyParams };
            schedule.Command = commandBody;

            return schedule;
        }
        private async void ToggleLightAsync()
        {
            var newValue = !LightSource.IsOn;
            var attrs = new { on = newValue };
            await HueAPI.Instance.SetLightStateAsync(LightSource.LightId, attrs);

            LightSource.IsOn = newValue;
            BridgeManager.Instance.InvalidateLightProperties(LightSource);
            BridgeManager.Instance.InvalidateAllLightsOnOffState();
        }
        private async void UpdateScheduleAsync()
        {
            if (ScheduleSource.ScheduleId == null)
            {
                return;
            }

            var attrs = new { localtime = ScheduleSource.LocalTime };
            await HueAPI.Instance.CreateScheduleAsync(attrs);               
        }
        private async void CreateScheduleAsync()
        {
            if (ScheduleSource.ScheduleId != null)
            {
                return;
            }

            var attrs = new { name = ScheduleSource.Name, description = ScheduleSource.Description, command = ScheduleSource.Command, localtime = ScheduleSource.LocalTime };
            
            // scheduleId can be null
            string scheduleId = await HueAPI.Instance.CreateScheduleAsync(attrs);
            
            ScheduleSource.ScheduleId = scheduleId;
        }
예제 #8
0
        private async void ToggleLightAsync()
        {
            var attrs = new { on = LightSource.IsOn };
            await HueAPI.Instance.SetLightStateAsync(LightSource.LightId, attrs);

            BridgeManager.Instance.InvalidateAllLightsOnOffState();
        }
예제 #9
0
        private async void UpdateLightName(string newName)
        {
            if (newName.Trim().Length == 0)
            {
                // Revert to original name
                NameInput.Text = LightSource.Name;
            }
            else
            {
                // The API allows no longer than 32 characters for the name
                var truncatedName = newName.Length > 32 ? newName.Substring(0, 32) : newName;
                var attrs = new { name = truncatedName };
                await HueAPI.Instance.SetLightAttributesAsync(LightSource.LightId, attrs);

                LightSource.Name = truncatedName;
                BridgeManager.Instance.InvalidateLightProperties(LightSource);
            }
        }