-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration of Pushover OH1 action to OH3 binding
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
- Loading branch information
Showing
24 changed files
with
2,286 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
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,13 @@ | ||
This content is produced and maintained by the openHAB project. | ||
|
||
* Project home: https://www.openhab.org | ||
|
||
== Declared Project Licenses | ||
|
||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
|
||
== Source Code | ||
|
||
https://github.com/openhab/openhab-addons |
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,56 @@ | ||
# Pushover Binding | ||
|
||
_Give some details about what this binding is meant for - a protocol, system, specific device._ | ||
|
||
_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._ | ||
|
||
## Supported Things | ||
|
||
_Please describe the different supported things / devices within this section._ | ||
_Which different types are supported, which models were tested etc.?_ | ||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._ | ||
|
||
## Discovery | ||
|
||
_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._ | ||
|
||
## Binding Configuration | ||
|
||
_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```<bindingId>.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_ | ||
|
||
``` | ||
# Configuration for the Philips Hue Binding | ||
# | ||
# Default secret key for the pairing of the Philips Hue Bridge. | ||
# It has to be between 10-40 (alphanumeric) characters | ||
# This may be changed by the user for security reasons. | ||
secret=openHABSecret | ||
``` | ||
|
||
_Note that it is planned to generate some part of this based on the information that is available within ```src/main/resources/ESH-INF/binding``` of your binding._ | ||
|
||
_If your binding does not offer any generic configurations, you can remove this section completely._ | ||
|
||
## Thing Configuration | ||
|
||
_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_ | ||
|
||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._ | ||
|
||
## Channels | ||
|
||
_Here you should provide information about available channel types, what their meaning is and how they can be used._ | ||
|
||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._ | ||
|
||
| channel | type | description | | ||
|----------|--------|------------------------------| | ||
| control | Switch | This is the control channel | | ||
|
||
## Full Example | ||
|
||
_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._ | ||
|
||
## Any custom content here! | ||
|
||
_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_ |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.addons.bundles</groupId> | ||
<artifactId>org.openhab.addons.reactor.bundles</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.binding.pushover</artifactId> | ||
|
||
<name>openHAB Add-ons :: Bundles :: Pushover Binding</name> | ||
|
||
</project> |
9 changes: 9 additions & 0 deletions
9
bundles/org.openhab.binding.pushover/src/main/feature/feature.xml
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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<features name="org.openhab.binding.pushover-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"> | ||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository> | ||
|
||
<feature name="openhab-binding-pushover" description="Pushover Binding" version="${project.version}"> | ||
<feature>openhab-runtime-base</feature> | ||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.pushover/${project.version}</bundle> | ||
</feature> | ||
</features> |
221 changes: 221 additions & 0 deletions
221
...ing.pushover/src/main/java/org/openhab/binding/pushover/actions/PushoverThingActions.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,221 @@ | ||
/** | ||
* 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.pushover.actions; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.pushover.internal.actions.IPushoverThingActions; | ||
import org.openhab.binding.pushover.internal.connection.PushoverMessageBuilder; | ||
import org.openhab.binding.pushover.internal.handler.PushoverAccountHandler; | ||
import org.openhab.core.automation.annotation.ActionInput; | ||
import org.openhab.core.automation.annotation.ActionOutput; | ||
import org.openhab.core.automation.annotation.RuleAction; | ||
import org.openhab.core.thing.binding.ThingActions; | ||
import org.openhab.core.thing.binding.ThingActionsScope; | ||
import org.openhab.core.thing.binding.ThingHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Some automation actions to be used with a {@link PushoverAccountHandler}. | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
@ThingActionsScope(name = "pushover") | ||
@NonNullByDefault | ||
public class PushoverThingActions implements ThingActions, IPushoverThingActions { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(PushoverThingActions.class); | ||
|
||
private @NonNullByDefault({}) PushoverAccountHandler accountHandler; | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription") | ||
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessage( | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title) { | ||
logger.trace("ThingAction 'sendMessage' called with value(s): message='{}', title='{}'", message, title); | ||
return send(getDefaultPushoverMessageBuilder(message), title); | ||
} | ||
|
||
public static Boolean sendMessage(@Nullable ThingActions actions, String message, @Nullable String title) { | ||
return invokeMethodOf(actions).sendMessage(message, title); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription") | ||
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendHtmlMessage( | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title) { | ||
logger.trace("ThingAction 'sendHtmlMessage' called with value(s): message='{}', title='{}'", message, title); | ||
return send(getDefaultPushoverMessageBuilder(message).withHtmlFormatting(), title); | ||
} | ||
|
||
public static Boolean sendHtmlMessage(@Nullable ThingActions actions, String message, @Nullable String title) { | ||
return invokeMethodOf(actions).sendHtmlMessage(message, title); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendMonospaceMessageActionLabel", description = "@text/sendMonospaceMessageActionDescription") | ||
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMonospaceMessage( | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title) { | ||
logger.trace("ThingAction 'sendMonospaceMessage' called with value(s): message='{}', title='{}'", message, | ||
title); | ||
return send(getDefaultPushoverMessageBuilder(message).withMonospaceFormatting(), title); | ||
} | ||
|
||
public static Boolean sendMonospaceMessage(@Nullable ThingActions actions, String message, @Nullable String title) { | ||
return invokeMethodOf(actions).sendMonospaceMessage(message, title); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendAttachmentMessageActionLabel", description = "@text/sendAttachmentMessageActionDescription") | ||
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendAttachmentMessage( | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title, | ||
@ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String", required = true) String attachment, | ||
@ActionInput(name = "contentType", label = "@text/sendMessageActionInputContentTypeLabel", description = "@text/sendMessageActionInputContentTypeDescription", type = "java.lang.String") @Nullable String contentType) { | ||
logger.trace( | ||
"ThingAction 'sendAttachmentMessage' called with value(s): message='{}', title='{}', attachment='{}', contentType='{}'", | ||
message, title, attachment, contentType); | ||
if (attachment == null) { | ||
throw new IllegalArgumentException("Skip sending message as 'attachment' is null."); | ||
} | ||
|
||
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withAttachment(attachment); | ||
if (contentType != null) { | ||
builder.withContentType(contentType); | ||
} | ||
return send(builder, title); | ||
} | ||
|
||
public static Boolean sendAttachmentMessage(@Nullable ThingActions actions, String message, @Nullable String title, | ||
String attachment, @Nullable String contentType) { | ||
return invokeMethodOf(actions).sendAttachmentMessage(message, title, attachment, contentType); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendPriorityMessageActionLabel", description = "@text/sendPriorityMessageActionDescription") | ||
public @ActionOutput(name = "receipt", label = "@text/sendPriorityMessageActionOutputLabel", description = "@text/sendPriorityMessageActionOutputDescription", type = "java.lang.String") String sendPriorityMessage( | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title, | ||
@ActionInput(name = "priority", label = "@text/sendMessageActionInputPriorityLabel", description = "@text/sendMessageActionInputPriorityDescription") int priority) { | ||
logger.trace("ThingAction 'sendPriorityMessage' called with value(s): message='{}', title='{}', priority='{}'", | ||
message, title, priority); | ||
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withPriority(priority); | ||
|
||
if (title != null) { | ||
builder.withTitle(title); | ||
} | ||
return accountHandler.sendPriorityMessage(builder); | ||
} | ||
|
||
public static String sendPriorityMessage(@Nullable ThingActions actions, String message, @Nullable String title, | ||
int priority) { | ||
return invokeMethodOf(actions).sendPriorityMessage(message, title, priority); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/cancelPriorityMessageActionLabel", description = "@text/cancelPriorityMessageActionDescription") | ||
public @ActionOutput(name = "Canceled", label = "@text/cancelPriorityMessageActionOutputLabel", description = "@text/cancelPriorityMessageActionOutputDescription", type = "java.lang.Boolean") Boolean cancelPriorityMessage( | ||
@ActionInput(name = "receipt", label = "@text/cancelPriorityMessageActionInputReceiptLabel", description = "@text/cancelPriorityMessageActionInputReceiptDescription", type = "java.lang.String", required = true) String receipt) { | ||
logger.trace("ThingAction 'cancelPriorityMessage' called with value(s): '{}'", receipt); | ||
if (accountHandler == null) { | ||
throw new RuntimeException("PushoverAccountHandler is null!"); | ||
} | ||
|
||
if (receipt == null) { | ||
throw new IllegalArgumentException("Skip canceling message as 'receipt' is null."); | ||
} | ||
|
||
return accountHandler.cancelPriorityMessage(receipt); | ||
} | ||
|
||
public static Boolean cancelPriorityMessage(@Nullable ThingActions actions, String receipt) { | ||
return invokeMethodOf(actions).cancelPriorityMessage(receipt); | ||
} | ||
|
||
@Override | ||
@RuleAction(label = "@text/sendMessageToDeviceActionLabel", description = "@text/sendMessageToDeviceActionDescription") | ||
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessageToDevice( | ||
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String", required = true) String device, | ||
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message, | ||
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title) { | ||
logger.trace("ThingAction 'sendMessageToDevice' called with value(s): device='{}', message='{}', title='{}'", | ||
device, message, title); | ||
if (device == null) { | ||
throw new IllegalArgumentException("Skip sending message as 'device' is null."); | ||
} | ||
|
||
return send(getDefaultPushoverMessageBuilder(message).withDevice(device), title); | ||
} | ||
|
||
public static Boolean sendMessageToDevice(@Nullable ThingActions actions, String device, String message, | ||
@Nullable String title) { | ||
return invokeMethodOf(actions).sendMessageToDevice(device, message, title); | ||
} | ||
|
||
private PushoverMessageBuilder getDefaultPushoverMessageBuilder(String message) { | ||
if (accountHandler == null) { | ||
throw new RuntimeException("PushoverAccountHandler is null!"); | ||
} | ||
|
||
if (message == null) { | ||
throw new IllegalArgumentException("Skip sending message as 'message' is null."); | ||
} | ||
|
||
return accountHandler.getDefaultPushoverMessageBuilder(message); | ||
} | ||
|
||
private Boolean send(PushoverMessageBuilder builder, @Nullable String title) { | ||
if (title != null) { | ||
builder.withTitle(title); | ||
} | ||
return accountHandler.sendMessage(builder); | ||
} | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
if (handler instanceof PushoverAccountHandler) { | ||
this.accountHandler = (PushoverAccountHandler) handler; | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return accountHandler; | ||
} | ||
|
||
private static IPushoverThingActions invokeMethodOf(@Nullable ThingActions actions) { | ||
if (actions == null) { | ||
throw new IllegalArgumentException("Actions cannot be null"); | ||
} | ||
if (actions.getClass().getName().equals(PushoverThingActions.class.getName())) { | ||
if (actions instanceof IPushoverThingActions) { | ||
return (IPushoverThingActions) actions; | ||
} else { | ||
return (IPushoverThingActions) Proxy.newProxyInstance(IPushoverThingActions.class.getClassLoader(), | ||
new Class[] { IPushoverThingActions.class }, (Object proxy, Method method, Object[] args) -> { | ||
Method m = actions.getClass().getDeclaredMethod(method.getName(), | ||
method.getParameterTypes()); | ||
return m.invoke(actions, args); | ||
}); | ||
} | ||
} | ||
throw new IllegalArgumentException("Actions is not an instance of PushoverThingActions"); | ||
} | ||
} |
Oops, something went wrong.