public bool PutDeviceUpdate(Device device) { if (device.Status == DeviceStatus.Unknown) return false; string path = string.Format("{0}zone/{1}/{2}", rootPath, device.ZoneId, (int)device.Status); var request = new RestRequest(path, Method.PUT) { RequestFormat = DataFormat.Json }; request.AddQueryParameter("access_token", settings.AccessToken); var response = client.Execute(request); return response.Content.Contains("ok"); }
public void PutDeviceUpdate(Device device) { if (device.Status == DeviceStatus.Unknown) return; try { lock (this) { string topic = string.Format("{0}/zone/{1}/state", settings.RootTopic, device.ZoneId); client.Publish(topic, Encoding.UTF8.GetBytes(device.Status.ToString()), settings.QosLevel, settings.Retain); logger.DebugFormat("{0}[{1}]", topic, device.Status); } } catch (System.Exception exception) { logger.Error(exception); } }
private void ProcessAreaAndZoneInformation(List<string> areas, List<object> zones) { int usedAreas = 0; int zoneNum = 1; for (int i = 0; i < zones.Count(); i++) { var partition = Convert.ToInt32(zones[i]); if (partition == 0) break; usedAreas = Math.Max(usedAreas, partition); var device = new Device() { DeviceType = DeviceType.Unknown, Name = zones[++i].ToString(), Partition = (PartitionNumber)(partition - 1), Status = DeviceStatus.Unknown, PreviousStatus = DeviceStatus.Unknown, ZoneId = zoneNum }; zoneNum++; device.DeviceType = ParseDeviceType(device.Name); Devices.Add(device); } Partitions = new List<Partition>(); for (int i = 0; i < usedAreas; i++) { var p = new Partition() { Name = areas[i], Id = (PartitionNumber)i, PreviousStatus = PartitionStatus.Unknown, Status = PartitionStatus.Unknown }; Partitions.Add(p); } }
public DeviceUpdateEventArgs(Device device) { Device = device; }