示例#1
0
        public void RecordDeviceState(string deviceId)
        {
            using (var context = new WeMoContext())
            {
                var device = context.WeMoDevices.First(x => x.DeviceId == deviceId);

                var client = new WeMoClient(device);
                var binaryState = client.GetBinaryState();

                var state = new WeMoDeviceState
                {
                    Device = device,
                    CurrentState = binaryState,
                    Timestamp = DateTime.Now
                };

                context.WeMoStates.Add(state);
                context.SaveChanges();
            }
        }
示例#2
0
        public IHttpActionResult GetSwitchStatus(string deviceId)
        {
            var device = _provider.Get(deviceId);

            if (device != null)
            {
                var client = new WeMoClient(device);
                var results = client.GetBinaryState();
                if (results == BinaryState.Error)
                {
                    return BadRequest();
                }
                return Ok(results);
            }

            return NotFound();
        }