Exemplo n.º 1
0
 public async Task SetPowerState(LightPowerState newState)
 {
     try {
         await parent.SetLightPowerState(this, newState);
     } catch (Exception e) {
         Console.WriteLine(e);
     }
 }
Exemplo n.º 2
0
 public CachedControlPair(LightControlPair light)
 {
     this.Properties      = light.Properties.DeepClone();
     this.PowerState      = light.PowerState;
     this.AppControlState = light.AppControlState;
     this.NetworkLight    = new AppLightState(light.NetworkLight);
     this.ExpectedLight   = light.ExpectedLight.DeepClone();
     if (light.Transition != null)
     {
         this.Transition = light.Transition.DeepClone();
     }
     this.ResetOccurred = light.ResetOccurred;
 }
Exemplo n.º 3
0
        private void PeriodicOnOffSender()
        {
            LightPowerState nextState = LightPowerState.On;

            while (!shouldStop)
            {
                foreach (var observer in observers)
                {
                    observer.OnNext(new ToggleLightAction(nextState));
                }

                nextState = nextState == LightPowerState.On ? LightPowerState.Off : LightPowerState.On;

                Thread.Sleep(500);
            }
        }
Exemplo n.º 4
0
 public ToggleLightAction(LightPowerState newState)
 {
     NewState = newState;
 }
Exemplo n.º 5
0
        internal async Task <LightPowerState> SetLightPowerState(PhilipsHueLight light, LightPowerState newState)
        {
            var lightStateRequest = new RestRequest(string.Format("{0}/lights/{1}/state", credentials.Username, light.BridgeLocalID), Method.PUT);

            lightStateRequest.AddJsonBody(
                new {
                on             = newState == LightPowerState.On,
                transitiontime = 1
            }
                );

            var stateSettingResponse = (await client.PutAsync <HueAPIResponse <IDictionary <string, object> >[]>(lightStateRequest))[0];

            if (stateSettingResponse.error != null)
            {
                // TODO Better error handling.
                throw new Exception(stateSettingResponse.error.description);
            }

            return(newState);
        }