-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[satel] Action for reading the event log added #7282
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,10 @@ Example: | |
Bridge satel:ethm-1:home [ host="192.168.0.2", refresh=1000, userCode="1234", encryptionKey="abcdefgh" ] | ||
``` | ||
|
||
**NOTE:** There can be only one client connected to ETHM-1 module. | ||
It does not accept new connections if there is already a connection established. | ||
In case you have troubles connecting to the system using this module, please make sure there is no other client (for example installed 1.x version of the binding) already connected to it. | ||
|
||
### int-rs bridge | ||
|
||
You can configure the following settings for this bridge: | ||
|
@@ -218,6 +222,8 @@ Thing atd-100 KitchenTemp [ id=10, refresh=30 ] | |
|
||
### output | ||
|
||
**NOTE:** You can change state of mono/bistable outputs only. | ||
|
||
| Name | Type | Description | | ||
|---------------|--------|-----------------------------------------------------------| | ||
| state | Switch | State of the output | | ||
|
@@ -243,7 +249,9 @@ Thing atd-100 KitchenTemp [ id=10, refresh=30 ] | |
| grade23_set | Switch | Active when Grade2/Grade3 option is set in the system | | ||
| user_code | String | Accepts string commands that override configured user code. Send empty string to revert user code to the one in the configuration. | | ||
|
||
### event-log | ||
### event-log (deprecated) | ||
|
||
These channels and the thing will be removed in the future release of the binding. Please use `readEvent` rule action instead. | ||
|
||
| Name | Type | Description | | ||
|-------------|----------|----------------------------------------------------------------------------------------| | ||
|
@@ -261,6 +269,31 @@ Thing atd-100 KitchenTemp [ id=10, refresh=30 ] | |
| device_lobatt | Switch | Indicates low battery level in the wireless device | | ||
| device_nocomm | Switch | Indicates communication troubles with the wireless device | | ||
|
||
## Rule Actions | ||
|
||
### readEvent | ||
|
||
This action allows you to read one record from the event log placed at index given by input parameter. | ||
The result of this action is compatible with channels of `event-log` thing and contains following values: | ||
|
||
| Name | Type | Description | | ||
|-------------|---------------|----------------------------------------------------------------------------------------| | ||
| index | Number | Index of this record in the event log. | | ||
| prev_index | Number | Index of the previous record in the event log. Use this value to iterate over the log. | | ||
| timestamp | ZonedDateTime | Date and time when the event happened. | | ||
| description | String | Textual description of the event. | | ||
| details | String | Details about the event, usually list of objects related to the event. | | ||
|
||
Usage: | ||
|
||
``` | ||
val actions = getActions("satel", "satel:event-log:home:EventLog") | ||
val eventRec = actions.readEvent(-1) | ||
logInfo("EventLog", eventRec.get("description")) | ||
``` | ||
|
||
**NOTE:** To have this action available, you must have `event-log` thing configured in openHAB. | ||
|
||
## Full Example | ||
|
||
### satel.things | ||
|
@@ -295,11 +328,6 @@ Rollershutter KITCHEN_BLIND "Kitchen blind" (Satel) { channel="satel:shutter:hom | |
Switch SYSTEM_TROUBLES "Troubles in the system" (Satel) { channel="satel:system:home:System:troubles" } | ||
String KEYPAD_CHAR ">" <none> (Satel) | ||
String USER_CODE "User code" (Satel) { channel="satel:system:home:System:user_code" } | ||
Number EVENT_LOG_IDX "Event log - current index [%d]" (Satel) { channel="satel:event-log:home:EventLog:index" } | ||
Number EVENT_LOG_PREV "Event log - previous index [%d]" (Satel) { channel="satel:event-log:home:EventLog:prev_index" } | ||
DateTime EVENT_LOG_TIME "Event log - time [%1$tF %1$tR]" (Satel) { channel="satel:event-log:home:EventLog:timestamp" } | ||
String EVENT_LOG_DESCR "Event log - description [%s]" (Satel) { channel="satel:event-log:home:EventLog:description" } | ||
String EVENT_LOG_DET "Event log - details [%s]" (Satel) { channel="satel:event-log:home:EventLog:details" } | ||
Switch SIREN_LOBATT "Siren: low battery level" (Satel) { channel="satel:output:home:Siren:device_lobatt" } | ||
Switch SIREN_NOCOMM "Siren: no communication" (Satel) { channel="satel:output:home:Siren:device_nocomm" } | ||
Number:Temperature KITCHEN_TEMP "Kitchen temperature [%.1f °C]" <temperature> (Satel) { channel="satel:atd-100:home:KitchenTemp:temperature" } | ||
|
@@ -344,8 +372,6 @@ Frame label="Alarm system" { | |
var String userCode = "" | ||
var Timer keypadTimer = null | ||
var Timer userCodeTimer = null | ||
var int eventLogCounter = 0 | ||
var String eventLogMsgBody = "" | ||
|
||
rule "Keypad char entered" | ||
when | ||
|
@@ -381,34 +407,30 @@ then | |
] | ||
end | ||
|
||
rule "Send event log start" | ||
rule "Send event log" | ||
when | ||
Item Alarms changed to ON | ||
then | ||
eventLogCounter = 0 | ||
eventLogMsgBody = "" | ||
EVENT_LOG_PREV.postUpdate(NULL) | ||
EVENT_LOG_IDX.sendCommand(-1) | ||
end | ||
|
||
rule "Send event log next" | ||
when | ||
Item EVENT_LOG_PREV changed | ||
then | ||
if (EVENT_LOG_PREV.state == NULL) { | ||
|
||
} else if (eventLogCounter == 30) { | ||
sendMail("[email protected]", "Alarm system log", eventLogMsgBody) | ||
// prevent initiating reading when index item is restored during OH startup | ||
EVENT_LOG_IDX.postUpdate(NULL) | ||
} else { | ||
eventLogMsgBody += "\n" + (EVENT_LOG_TIME.state as DateTimeType).format("%1$tF %1$tR") + ": " + EVENT_LOG_DESCR.state | ||
if (EVENT_LOG_DET.state != NULL && EVENT_LOG_DET.state != "") { | ||
eventLogMsgBody += " - " + EVENT_LOG_DET.state | ||
} | ||
eventLogCounter += 1 | ||
EVENT_LOG_IDX.sendCommand(EVENT_LOG_PREV.state) | ||
val actions = getActions("satel", "satel:event-log:home:EventLog") | ||
if (null === actions) { | ||
logInfo("EventLog", "Actions not found, check thing ID") | ||
return | ||
} | ||
logInfo("EventLog", "Start") | ||
var msgBody = "" | ||
var eventIdx = -1 | ||
(1..10).forEach[ | ||
val eventRec = actions.readEvent(eventIdx) | ||
val details = eventRec.get("details") | ||
msgBody += "\n" + String::format("%1$tF %1$tR", eventRec.get("timestamp")) + ": " + eventRec.get("description") | ||
if (details != NULL && details != "") { | ||
msgBody += " - " + details | ||
} | ||
eventIdx = eventRec.get("prev_index") | ||
] | ||
logInfo("EventLog", "End") | ||
// sending notifications via mail requires the mail binding | ||
getActions("mail","mail:smtp:local").sendMail("[email protected]", "Event log", msgBody) | ||
end | ||
``` | ||
|
||
|
82 changes: 82 additions & 0 deletions
82
...ab.binding.satel/src/main/java/org/openhab/binding/satel/action/SatelEventLogActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.satel.action; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.thing.binding.ThingActions; | ||
import org.eclipse.smarthome.core.thing.binding.ThingActionsScope; | ||
import org.eclipse.smarthome.core.thing.binding.ThingHandler; | ||
import org.openhab.binding.satel.internal.handler.SatelEventLogHandler; | ||
import org.openhab.core.automation.annotation.ActionInput; | ||
import org.openhab.core.automation.annotation.ActionOutput; | ||
import org.openhab.core.automation.annotation.RuleAction; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Automation action handler service for reading Satel event log. | ||
* | ||
* @author Krzysztof Goworek - Initial contribution | ||
* @see SatelEventLogHandler | ||
*/ | ||
@ThingActionsScope(name = "satel") | ||
@NonNullByDefault | ||
public class SatelEventLogActions implements ThingActions { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private @Nullable SatelEventLogHandler handler; | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
if (handler instanceof SatelEventLogHandler) { | ||
this.handler = (SatelEventLogHandler) handler; | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return handler; | ||
} | ||
|
||
@RuleAction(label = "@text/actionReadEventLabel", description = "@text/actionReadEventDesc") | ||
public @ActionOutput(name = "index", type = "java.lang.Integer", label = "@text/actionOutputIndexLabel", description = "@text/actionOutputIndexDesc") @ActionOutput(name = "prev_index", type = "java.lang.Integer", label = "@text/actionOutputPrevIndexLabel", description = "@text/actionOutputPrevIndexDesc") @ActionOutput(name = "timestamp", type = "java.time.ZonedDateTime", label = "@text/actionOutputTimestampLabel", description = "@text/actionOutputTimestampDesc") @ActionOutput(name = "description", type = "java.lang.String", label = "@text/actionOutputDescriptionLabel", description = "@text/actionOutputDescriptionDesc") @ActionOutput(name = "details", type = "java.lang.String", label = "@text/actionOutputDetailsLabel", description = "@text/actionOutputDetailsDesc") Map<String, Object> readEvent( | ||
@ActionInput(name = "index", label = "@text/actionInputIndexLabel", description = "@text/actionInputIndexDesc") @Nullable Number index) { | ||
logger.debug("satel.readEvent called with input: index={}", index); | ||
|
||
Map<String, Object> result = new HashMap<>(); | ||
if (handler != null) { | ||
handler.readEvent(index == null ? -1 : index.intValue()).ifPresent(event -> { | ||
result.put("index", event.getIndex()); | ||
result.put("prev_index", event.getPrevIndex()); | ||
result.put("timestamp", event.getTimestamp()); | ||
result.put("description", event.getDescription()); | ||
result.put("details", event.getDetails()); | ||
}); | ||
} | ||
return result; | ||
} | ||
|
||
public static Map<String, Object> readEvent(@Nullable ThingActions actions, @Nullable Number index) { | ||
if (actions instanceof SatelEventLogActions) { | ||
return ((SatelEventLogActions) actions).readEvent(index); | ||
} else { | ||
throw new IllegalArgumentException("Instance is not a SatelEventLogActions class."); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note seomwhere that this requires the mail binding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an example. The purpose of the action is to read single record from the event log. It does not specify what one should do with the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I was just thinking that someone installs
satel
, adds this example and runs into an error. Maybe a comment in the line above this one likesending notifications via mail requires the mail binding
or something like that would be good.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.