public async Task UpdateDevicesList(DiscoverDeviceRsp response, IMiCommunication communication) { var device = _devices.FirstOrDefault(x => x.Sid == response.sid); if (device != null) { device.UpdateDevice(response.data); return; } if (response.model == "gateway") { Gateway g = new Gateway(response, null, communication); g.UpdateDevice(response.data); _devices.Add(g); return; } if (response.model == "sensor_ht") { TemperatureSensor g = new TemperatureSensor(response, null, communication); g.UpdateDevice(response.data); _devices.Add(g); return; } }
private async Task UpdateDevice(DiscoverDeviceRsp response) { await _devicesKeeper.UpdateDevicesList(response, _communication); Interlocked.Decrement(ref _awaitedDevices); if (_awaitedDevices == 0) { _waitHandle.Set(); } }
public ICommandResponse ParseCommand(string commandString) { if (commandString.Contains("get_id_list_ack")) { DiscoverGatewayRsp resp = JsonConvert.DeserializeObject <DiscoverGatewayRsp>(commandString); return(resp); } else if (commandString.Contains("read_ack") || commandString.Contains("write_ack")) { DiscoverDeviceRsp resp = JsonConvert.DeserializeObject <DiscoverDeviceRsp>(commandString); return(resp); } else if (commandString.Contains("heartbeat")) { HeartBeatRsp resp = JsonConvert.DeserializeObject <HeartBeatRsp>(commandString); return(resp); } return(null); }
public Gateway(DiscoverDeviceRsp response, string name, IMiCommunication communication) : base(response.sid, DeviceTypes.Gateway, response.short_id, name, response.model, communication) { }
public TemperatureSensor(DiscoverDeviceRsp response, string name, IMiCommunication communication) : base(response.sid, DeviceTypes.TemperatureHumiditySensor, response.short_id, name, response.model, communication) { }