public IHttpActionResult GetSignalStrength(string deviceId)
        {
            var device = _provider.Get(deviceId);

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

            return NotFound();
        }
Beispiel #2
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();
            }
        }
Beispiel #3
0
        public WeMoDevice Update(string deviceId, string location)
        {
            using (var context = new WeMoContext())
            {
                var url = new Uri(location);
                var device = context.WeMoDevices
                    .First(x => x.DeviceId == deviceId);

                device.Host = url.Host;
                device.Port = url.Port;
                device.Location = location;
                device.Disabled = false;

                var client = new WeMoClient(device);
                client.EnumerateDeviceInfo();

                context.SaveChanges();

                return device;
            }
        }
Beispiel #4
0
        public WeMoDevice Create(string location)
        {
            using (var context = new WeMoContext())
            {
                var url = new Uri(location);
                var device = new WeMoDevice
                {
                    Host = url.Host,
                    Port = url.Port,
                    Location = location
                };

                var client = new WeMoClient(device);
                client.EnumerateDeviceInfo();

                context.WeMoDevices
                    .Add(device);
                context.SaveChanges();

                return device;
            }
        }
        public IHttpActionResult EnumerateDevice(string deviceId)
        {
            var device = _provider.Get(deviceId);

            if (device != null)
            {
                var client = new WeMoClient(device);
                client.EnumerateDeviceInfo();
                return Ok(device);
            }

            return NotFound();
        }
        public IHttpActionResult SetName(string deviceId, [FromBody] string name)
        {
            var device = _provider.Get(deviceId);

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

            return NotFound();
        }
        public IHttpActionResult SetOn(string deviceId)
        {
            var device = _provider.Get(deviceId);

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

            return NotFound();
        }
        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();
        }