Beispiel #1
0
        /// <summary>
        /// Parse the incoming data
        /// </summary>
        /// <returns></returns>
        private bool ParseResponse()
        {
            if (_data != null && _data.Length > 0)
            {
                using (var content = new ByteList(_data))
                {
                    // Receive the device id from the response
                    DeviceId = content.Skip(8).Take(4).ToArray();

                    var timestamp = content.ReadInt32LE(12, 4);
                    if (timestamp > 0)
                    {
                        Timestamp = new ServerTimestamp(timestamp);
                    }

                    var encrypted = content.Skip(32);
                    if (encrypted.Count() > 0)
                    {
                        var decrypted = AESHelper.Decrypt(_miToken.Key, _miToken.InitializationVector, encrypted.ToArray());
                        ResponseText = ASCIIEncoding.ASCII.GetString(decrypted);
                    }
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
 internal MiHomeRequest(MiHomeToken token, byte[] deviceId, ServerTimestamp ts, NetworkOptions options, string jsonBody)
 {
     _payload       = JsonConvert.DeserializeObject(jsonBody);
     _token         = token;
     _deviceId      = deviceId;
     _serverStamp   = ts;
     NetworkOptions = options;
 }
Beispiel #3
0
 internal MiHomeRequest(MiHomeToken token, byte[] deviceId, ServerTimestamp ts, NetworkOptions options, object objectBody)
 {
     _payload       = objectBody;
     _token         = token;
     _deviceId      = deviceId;
     _serverStamp   = ts;
     NetworkOptions = options;
 }
Beispiel #4
0
 internal void UpdateTimestamp(ServerTimestamp stamp)
 {
     _serverStamp = stamp;
 }