public void Land(LandEventArgs eventArgs)
        {
            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>("GlassBreak");
            var file            = _random.Pick(soundCollection.PickFiles);

            EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner);

            State = LightBulbState.Broken;
        }
Esempio n. 2
0
        /// <summary>
        ///     Set a new state for a light bulb (broken, burned) and raise event about change
        /// </summary>
        public void SetState(EntityUid uid, LightBulbState state, LightBulbComponent?bulb = null)
        {
            if (!Resolve(uid, ref bulb))
            {
                return;
            }

            bulb.State = state;
            UpdateAppearance(uid, bulb);
        }
Esempio n. 3
0
        public void Land(LandEventArgs eventArgs)
        {
            if (State == LightBulbState.Broken)
            {
                return;
            }

            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>("glassbreak");
            var file            = _random.Pick(soundCollection.PickFiles);

            IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <AudioSystem>().Play(file, Owner);

            State = LightBulbState.Broken;
        }
Esempio n. 4
0
        /// <summary>
        /// Method that will change a single light bulb state.
        /// </summary>
        /// <param name="lightBulbToChange">The id of the light bulb to change.</param>
        /// <param name="newState">True in order to turn the light bulb on. False otherwise.</param>
        public async Task ChangeLightBulbState(int lightBulbToChange, bool newState)
        {
            // Generate the method invocation with the payload, and send it with the service client.
            var methodInvocation = new CloudToDeviceMethod("ChangeLightBulbState")
            {
                ResponseTimeout = TimeSpan.FromSeconds(30)
            };
            LightBulbState payload = new LightBulbState {
                Id = lightBulbToChange, State = newState
            };

            methodInvocation.SetPayloadJson(JsonConvert.SerializeObject(payload));
            var response = await _serviceClient.InvokeDeviceMethodAsync(_deviceToControl, methodInvocation);

            if (response.Status != 200)
            {
                throw new ApplicationException($"There was an error when processing your request. The server returned http {response.Status}\n{response.ToString()}");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Method that will return the state of all configured light bulbs.
        /// </summary>
        /// <param name="methodRequest">The request that was sent from the server.</param>
        /// <param name="userContext">The user context</param>
        /// <returns>A list of LightBulbState with the information of the status of each light bulb.</returns>
        public Task <MethodResponse> GetLightBulbStatus(MethodRequest methodRequest, object userContext)
        {
            // Print message to the console of the message that was received.
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Getting a request from Hub for Light Status.");
            Console.ResetColor();

            // Construct the response with the current state.
            LightBulbState[] result = new LightBulbState[]
            {
                new LightBulbState {
                    Id = 1, State = _lightsStatus[1]
                },
                new LightBulbState {
                    Id = 3, State = _lightsStatus[3]
                }
            };
            var resultString = JsonConvert.SerializeObject(result);

            return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes(resultString), 200)));
        }
#pragma warning disable RCS1213 // Remove unused member declaration.
        private static async Task Main2()
#pragma warning restore RCS1213 // Remove unused member declaration.
        {
            using (var client = new SmartHomeClient())
            {
                client.Start();

                await Task.Delay(1000).ConfigureAwait(false);

                Console.WriteLine("Client initialized.");

                while (true)
                {
                    Console.Write("Command: ");
                    string command = Console.ReadLine();
                    if (command?.ToLower() == "exit")
                    {
                        return;
                    }

                    foreach (Device device in client.GetDevices())
                    {
                        if (device is LightBulb lb)
                        {
                            SwitchState state = string.Equals(command, "x", StringComparison.CurrentCultureIgnoreCase) ? SwitchState.On : SwitchState.Off;

                            await lb.TransitionStateAsync(state).ConfigureAwait(false);

                            LightBulbState state2 = lb.State;

                            Console.WriteLine($"{lb.Alias} ({lb.DeviceId}): {state2.PowerState}");
                        }
                    }
                }
            }
        }
 public void OnBreak(BreakageEventArgs eventArgs)
 {
     State = LightBulbState.Broken;
 }
 void ILand.Land(LandEventArgs eventArgs)
 {
     PlayBreakSound();
     State = LightBulbState.Broken;
 }