Example #1
0
        public DeviceInfo Parse(TuyaBaseResponse baseResponse)
        {
            if (baseResponse.Payload == null)
            {
                State = EDeviceState.NoConnection;

                return(this);
            }

            dynamic devInfo = JObject.Parse(
                Encoding.UTF8.GetString(baseResponse.Payload.ToArray()));

            try
            {
                if ((bool)devInfo.dps["1"])
                {
                    State = EDeviceState.On;
                }
                else
                {
                    State = EDeviceState.Off;
                }
            }
            catch (Exception)
            {
                State = EDeviceState.NoResponse;
            }

            return(this);
        }
Example #2
0
        public InfoRequest(TuyaDevice device)
        {
            var payload = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(
                    new
            {
                gwId  = device.Id,
                devId = device.Id
            }
                    ));

            BaseResponse = TuyaNetwork.SendRequest(device, payload);
        }