示例#1
0
        private void ParseSocketMsg(ResponseMessage msg)
        {
            GHUBMsg ghubmsg = JsonConvert.DeserializeObject <GHUBMsg>(msg.Text);

            if (ghubmsg.path == "/devices/state/changed")
            {
                LoadDevicesAsync().Wait();
            }
            else if (ghubmsg.path == "/devices/list")
            {
                _loadDevices(ghubmsg.payload);
            }
            //else if (ghubmsg.path.StartsWith("/battery_state/"))
            else if (Regex.IsMatch(ghubmsg.path, @"\/battery\/dev[0-9]+\/state"))
            {
                if (ghubmsg.result["code"]?.ToString() == "SUCCESS")
                {
                    _UpdateDevice(ghubmsg.payload);
                }
                else if (ghubmsg.result["code"]?.ToString() == "NO_SUCH_PATH")
                {
                    _FreezeDevice(ghubmsg);
                }
            }
            else if (ghubmsg.path == "/battery/state/changed")
            {
                _UpdateDevice(ghubmsg.payload);
            }
            else
            {
            }
            //Debug.WriteLine(msg);
        }
示例#2
0
        private void _FreezeDevice(GHUBMsg msg)
        {
            var            match  = Regex.Match(msg.path, ".+?(dev[0-9]+).+");
            LogiDeviceGHUB device = _LogiDevices.FirstOrDefault(x => x.DeviceID == match.Groups[1].Value) as LogiDeviceGHUB;

            if (device == null)
            {
                return;
            }

            device.HasBattery = false;
        }