// ================================================================================================ public void HSEvent(Enums.HSEvent EventType, object[] parms) { Console.WriteLine("HSEvent: " + EventType.ToString()); switch (EventType) { case Enums.HSEvent.VALUE_CHANGE: break; } }
public bool EvaluateTrigger(Enums.HSEvent eventType, double valueLeft, double valueRight) { if (Type == TriggerType.DeviceValueChanged && eventType != Enums.HSEvent.VALUE_CHANGE) { // We don't need to check DeviceValueSet because it also covers changed cases return(false); } return(EvaluateCondition(valueLeft, valueRight)); }
public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { // TODO: This is where the bulk of the work happens //if (!IsAnyWebHookConfigured()) //{ // Program.WriteLog(LogType.Debug, // "Ignoring event " + eventType + " because no webhook endpoint is configured."); // return; //} Dictionary <string, object> dict = new Dictionary <string, object> { { "eventType", eventType.ToString() } }; try { int devRef; switch (eventType) { case Enums.HSEvent.VALUE_SET: case Enums.HSEvent.VALUE_CHANGE: devRef = (int)parameters[4]; dict.Add("address", (string)parameters[1]); dict.Add("newValue", ((double)parameters[2]).ToString(CultureInfo.InvariantCulture)); dict.Add("oldValue", ((double)parameters[3]).ToString(CultureInfo.InvariantCulture)); dict.Add("ref", devRef); break; case Enums.HSEvent.STRING_CHANGE: devRef = (int)parameters[3]; dict.Add("address", (string)parameters[1]); dict.Add("newValue", (string)parameters[2]); dict.Add("ref", devRef); break; default: HS.WriteLog("Warn", "Unknown event type " + eventType); return; } string json = JsonConvert.SerializeObject(dict); HS.WriteLog("Verbose", json); WebSocketServer.Broadcast(json); } catch (Exception ex) { HS.WriteLog("Error", ex.ToString()); } }
public override void HSEvent(Enums.HSEvent eventType, [AllowNull] object[] parameters) { try { if ((eventType == Enums.HSEvent.VALUE_CHANGE) && (parameters.Length > 4)) { int deviceRefId = Convert.ToInt32(parameters[4]); RecordDeviceValue(deviceRefId).Wait(ShutdownCancellationToken); } } catch (Exception ex) { Trace.TraceWarning(Invariant($"Failed to process HSEvent {eventType} with {ex.GetFullMessage()}")); } }
public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { switch (eventType) { case Enums.HSEvent.CONFIG_CHANGE: int type = (int)parameters[1]; int dac = (int)parameters[4]; Program.WriteLog(LogType.Verbose, "HSEvent triggered " + eventType + " type " + type + " DAC " + dac); if (type == 0 && (dac == 1 || dac == 2)) { // Device was added or deleted cacheDeviceList(); } break; case Enums.HSEvent.VALUE_SET: case Enums.HSEvent.VALUE_CHANGE: int devRef = (int)parameters[4]; Program.WriteLog(LogType.Verbose, "HSEvent triggered " + eventType + " for dev ref " + devRef); // Do any of our triggers reference this device? foreach (TriggerEntry trig in getTriggerList()) { if (trig.Data.DevRefLeft == devRef || trig.Data.DevRefRight == devRef) { // Yep. double valueLeft = hs.DeviceValueEx(trig.Data.DevRefLeft); double valueRight = hs.DeviceValueEx(trig.Data.DevRefRight); if (trig.Data.EvaluateTrigger(eventType, valueLeft, valueRight)) { Program.WriteLog(LogType.Info, "Triggering event " + trig.TrigInfo.evRef + " because " + trig.Data.Type + " and " + valueLeft + " " + trig.Data.Comparison + " " + valueRight); callbacks.TriggerFire(Name, trig.TrigInfo); } } } break; default: Program.WriteLog(LogType.Verbose, "HSEvent triggered " + eventType); break; } }
private async Task HSEventImpl(Enums.HSEvent eventType, object[] parameters) { try { if ((eventType == Enums.HSEvent.VALUE_CHANGE) && (parameters.Length > 4)) { int deviceRefId = Convert.ToInt32(parameters[4], CultureInfo.InvariantCulture); await RecordDeviceValue(deviceRefId, TrackedType.Value).ConfigureAwait(false); } else if ((eventType == Enums.HSEvent.STRING_CHANGE) && (parameters.Length > 3)) { int deviceRefId = Convert.ToInt32(parameters[3], CultureInfo.InvariantCulture); await RecordDeviceValue(deviceRefId, TrackedType.String).ConfigureAwait(false); } } catch (Exception ex) { Trace.TraceWarning(Invariant($"Failed to process HSEvent {eventType} with {ex.GetFullMessage()}")); } }
/// <summary> /// When you wish to have HomeSeer call back in to your plug-in or application when certain events happen in the system, /// call the RegisterEventCB procedure and provide it with event you wish to monitor. /// See RegisterEventCB for more information and an example and event types. /// </summary> public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { if (eventType == Enums.HSEvent.VALUE_CHANGE) { // For HSEvent.VALUE_CHANGE: // 0. eventType // 1. The device's address (string) // 2. The new value of the device (double) // 3. The old value of the device (double) // 4. The device's reference number (integer) // for performace inspect only devices in MonitoredDevices list // as they are registered as "Linked Status Device" int devID = (int)parameters[4]; if (controller.DeviceUsed(devID)) { controller.ValueChanged(parameters: parameters); } } if (eventType == Enums.HSEvent.CONFIG_CHANGE) { // For HSEvent.CONFIG_CHANGE: // 0. eventType // 1. Type: 0=a device was changed 1=an event was changed 2=an event group was changed // 2. deprecated // 3. The device/event/event group reference number. 0 means that the reference is not known. // 4. DAC device/event was 0 = not known, 1 = Added, 2 = Deleted, 3 = Changed // 5. A string describing what changed // So if a used device was deleted: if ((int)parameters[1] == 0 && (int)parameters[4] == 2) { int devID = (int)parameters[3]; if (controller.DeviceUsed(devID)) { (controller as Controller).DeviceDeleted(devID); } } } }
public void HsEvent(Enums.HSEvent eventType, object[] parameters) { //Catch changes to values and store them for the devices we are watching _numberOfEventsReceived++; if (eventType == Enums.HSEvent.VALUE_CHANGE) { //_logging.LogDebug("Got an value changed event. Trying to check if we should store it"); _numberOfValueChanngeEventsReceived++; if (parameters != null && parameters.Length > 4 && parameters[2] != null && parameters[4] != null && parameters[2] is double && parameters[4] is int) { var newValue = (double)parameters[2]; var deviceId = (int)parameters[4]; //Console.WriteLine($"Something happened to a value for deviceId {deviceId} (value: {newValue.ToString()})"); if (DeviceIsWatched(deviceId)) { _logging.LogDebug($"logging an event with data deviceId:{deviceId} value: {newValue}"); _numberOfEventsStored++; _storageHandler.AddDeviceValueToDatabase(newValue, DateTime.Now, deviceId); } } } }
public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { bool canContinue = true; // this.SettingsManager.Settings.IsEventTypeEnabled((int)eventType); if (!canContinue) { return; } BaseDocument document = null; try { switch (eventType) { case Enums.HSEvent.CONFIG_CHANGE: { document = new ConfigChangeEvent(parameters); } break; case Enums.HSEvent.LOG: document = new LogEvent(parameters); break; case Enums.HSEvent.STRING_CHANGE: document = new StringChangeEvent(parameters); break; case Enums.HSEvent.VALUE_CHANGE: { document = new ValueChangeEvent(parameters); } break; case Enums.HSEvent.GENERIC: { document = new GenericEvent(parameters); } break; case Enums.HSEvent.SETUP_CHANGE: { document = new SetupChangeEvent(); } break; default: LogInfo(string.Format("No handler yet for HSEvent type {0}", eventType.ToString())); Console.WriteLine(" - HSEvent {0}: {1}", eventType.ToString(), String.Join(" | ", parameters)); break; } if (document != null) { this.esManager.WriteDocument(document); } } catch (Exception e) { LogError(string.Format("Error while handling HS Event: {0}", e.Message)); } }
public override void HSEvent(Enums.HSEvent eventType, object[] parms) { }
// ================================================================================================ public void HSEvent(Enums.HSEvent EventType, object[] parms) { //Don't need anything }
/// <summary> /// This is called when an event happens, provided you called RegisterEventCB first. /// </summary> /// <param name="eventType">The type of the event that happened</param> /// <param name="parameters">Parameters for the event</param> public virtual void HSEvent(Enums.HSEvent eventType, object[] parameters) { }
public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { _mainPlugin.HsEvent(eventType, parameters); }
public void HSEvent(Enums.HSEvent eventType, object[] parms) { }
public override void HSEvent(Enums.HSEvent eventType, [AllowNull] object[] parameters) { HSEventImpl(eventType, parameters).Wait(ShutdownCancellationToken); }
public override void HSEvent(Enums.HSEvent eventType, [AllowNull] object[] parameters) { }
/// <summary> /// When you wish to have HomeSeer call back in to your plug-in or application when certain events happen in the /// system, /// call the RegisterEventCB procedure and provide it with event you wish to monitor. /// See RegisterEventCB for more information and an example and event types. /// </summary> public abstract void HSEvent(Enums.HSEvent eventType, object[] parameters);
public override void HSEvent(Enums.HSEvent eventType, object[] parameters) { if (!IsAnyWebHookConfigured()) { Program.WriteLog(LogType.Debug, "Ignoring event " + eventType + " because no webhook endpoint is configured."); return; } Dictionary <string, object> dict = new Dictionary <string, object> { { "eventType", eventType.ToString() } }; try { int devRef; switch (eventType) { case Enums.HSEvent.VALUE_SET: case Enums.HSEvent.VALUE_CHANGE: devRef = (int)parameters[4]; if (ignoreUnchangedEvents && (double)parameters[2] == (double)parameters[3]) { Program.WriteLog(LogType.Verbose, $"Suppressing {eventType} for device {devRef} because its value did not change ({(double)parameters[2]} == {(double)parameters[3]})"); return; } dict.Add("address", (string)parameters[1]); dict.Add("newValue", ((double)parameters[2]).ToString(CultureInfo.InvariantCulture)); dict.Add("oldValue", ((double)parameters[3]).ToString(CultureInfo.InvariantCulture)); dict.Add("ref", devRef); break; case Enums.HSEvent.STRING_CHANGE: devRef = (int)parameters[3]; dict.Add("address", (string)parameters[1]); dict.Add("newValue", (string)parameters[2]); dict.Add("ref", devRef); break; default: Program.WriteLog(LogType.Warn, "Unknown event type " + eventType); return; } if (ignoredDeviceRefs.Contains(devRef)) { Program.WriteLog(LogType.Verbose, $"Suppressing {eventType} for device {devRef} because it is ignored."); return; } if (ignoreTimerEvents) { if (!deviceRefTimerState.ContainsKey(devRef)) { // We need to check if this is a timer DeviceClass device = (DeviceClass)hs.GetDeviceByRef(devRef); PlugExtraData.clsPlugExtraData deviceData = device.get_PlugExtraData_Get(hs); deviceRefTimerState[devRef] = deviceData.GetNamed("timername") != null && device.get_Interface(hs) == ""; } if (deviceRefTimerState[devRef]) { // This is a timer. Program.WriteLog(LogType.Verbose, $"Suppressing {eventType} for device {devRef} because it's a timer."); return; } } string json = jsonSerializer.Serialize(dict); Program.WriteLog(LogType.Verbose, json); for (byte i = 0; i < TOTAL_WEBHOOK_SLOTS; i++) { if (webHooks[i] == null) { continue; } WebHook webHook = webHooks[i]; webHook.Execute(new StringContent(json, Encoding.UTF8, "application/json")).ContinueWith((task) => { Program.WriteLog(LogType.Verbose, "Sent WebHook " + webHook + " with status code " + task.Result.StatusCode); if (!task.Result.IsSuccessStatusCode) { Program.WriteLog(LogType.Warn, "Got non-successful response code from WebHook " + webHook + ": " + task.Result.StatusCode); } task.Result.Dispose(); }).ContinueWith((task) => { if (task.Exception?.InnerException != null) { Program.WriteLog(LogType.Error, $"Unable to send WebHook {webHook}: {getInnerExceptionMessage(task.Exception)}"); } }, TaskContinuationOptions.OnlyOnFaulted); } } catch (Exception ex) { Program.WriteLog(LogType.Error, ex.ToString()); } }