private void OnMessage(InsteonMessage message) { if (message.Properties.ContainsKey(PropertyKey.FromAddress)) { int address = message.Properties[PropertyKey.FromAddress]; if (network.Devices.ContainsKey(address)) { logger.DebugFormat("Device {0} received message {1}", InsteonAddress.Format(address), message.ToString()); InsteonDevice device = network.Devices.Find(address); device.OnMessage(message); } else if (message.MessageType == InsteonMessageType.SetButtonPressed) { // don't warn about SetButtonPressed message from unknown devices, because it may be from a device about to be added } else if (network.AutoAdd) { logger.DebugFormat("Unknown device {0} received message {1}, adding device", InsteonAddress.Format(address), message.ToString()); //note: due to how messages are handled and how devices cannot receive new messages while pending sends (I think) we should only add on certain message types. // right now I've only tested devices where we get broadcast messages. Thus, we wait until the last message received. if (message.MessageType == InsteonMessageType.SuccessBroadcast) { InsteonIdentity?id; // TODO: probably shouldn't be in a while loop. Need a better way to address this while (!network.Controller.TryGetLinkIdentity(new InsteonAddress(address), out id)) { if (id != null) { InsteonDevice device = network.Devices.Add(new InsteonAddress(address), id.Value); device.OnMessage(message); } } } } else { logger.WarnFormat("Unknown device {0} received message {1}. Could be Identification process.", InsteonAddress.Format(address), message.ToString()); } } else { logger.DebugFormat("Controller received message {0}", message.ToString()); network.Controller.OnMessage(message); } }
public bool PushDeviceStatusUpdate(InsteonDevice device, InsteonDeviceStatus status) { //note: because the parent caller of this event is an InsteonDevice which is processing a current message received event, it's not been "reset" and we cannot //make a call to GetOnLevel for dimmable devices as no response will be handled. We must "ask" ST to make another rest call to obtain current state. All we can //do here is tell it there is an update. string path = $"{rootPath}deviceupdate/{device.Address}/{status}"; var request = new RestRequest(path, Method.PUT) { RequestFormat = DataFormat.Json }; request.AddQueryParameter("access_token", settings.AccessToken); var response = client.Execute(request); logger.InfoFormat("Content Returend from ST: {0}", response.Content); return(response.Content.Contains("ok")); }
private void OnDeviceUnlinked(InsteonDevice device) { DeviceUnlinked?.Invoke(this, new InsteonDeviceEventArgs(device)); }
internal InsteonDeviceStatusChangedEventArgs(InsteonDevice device, InsteonDeviceStatus status) { Device = device; DeviceStatus = status; }
internal InsteonDeviceStatusChangedEventArgs(InsteonDevice device, InsteonDeviceStatus status) { Device = device; DeviceStatus = status; }