Skip to content

Commit e1c1e59

Browse files
authored
[pushbullet] Remove unimplemented channels and thing parameters (openhab#17482)
* [pushbullet] Remove unimplemented channels and thing parameters Signed-off-by: jsetton <[email protected]>
1 parent 6a6c7f6 commit e1c1e59

File tree

8 files changed

+63
-198
lines changed

8 files changed

+63
-198
lines changed
+33-116
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
11
# Pushbullet Binding
22

3-
The Pushbullet binding allows you to notify iOS, Android & Windows 10 Phone & Desktop devices of a message using the Pushbullet API web service.
3+
The Pushbullet binding allows you to notify supported devices of a message using the [Pushbullet API](https://docs.pushbullet.com).
4+
To get started you need to [create an account](#creating-an-account) and [obtain an access token](#obtaining-an-access-token).
45

56
## Supported Things
67

7-
This binding supports a generic "bot" which is a representation of the client.
8-
9-
## Discovery
10-
11-
This binding provides no discovery.
12-
The desired bots must be configured manually or via a things file.
13-
14-
## Binding Configuration
15-
16-
The binding has no configuration options itself, all configuration is done at 'Things' level.
8+
| Thing | Type | Description |
9+
| ----- | ----- | ------------------------- |
10+
| bot | Thing | Bot to send messages with |
1711

1812
## Thing Configuration
1913

20-
### Bot (`bot`)
21-
22-
The bot thing is used to send messages to other recipients.
23-
It has the following parameters:
14+
### `bot`
2415

25-
| Config | Description | Required | Advanced |
26-
|------------|------------------------------------------------------------------|----------|----------|
27-
| token | Pushbullet [API token](#obtaining-an-api-key) to send to devices | Yes | False |
28-
| name | Explicit Name, for later use when the bot can receive messages | No | True |
29-
| apiUrlBase | Address of own Pushbullet server, for testing purposes | No | True |
30-
31-
```java
32-
Thing pushbullet:bot:r2d2 "R2D2" @ "Somewhere" [ token = "verysecretwonttellyou" ]
33-
34-
```
16+
| Parameter | Required | Description |
17+
| --------- | :------: | ---------------------------------------------------- |
18+
| token | Yes | Access token obtained from the account settings page |
3519

3620
## Channels
3721

38-
| Channel ID | Channel Description | Supported item type | Advanced |
39-
|------------|-------------------------------------------------|----------------------|----------|
40-
| recipient | for later use when the bot can receive messages | String | False |
41-
| title | for later use when the bot can receive messages | String | False |
42-
| message | for later use when the bot can receive messages | String | False |
22+
Currently the binding does not support any channels.
4323

4424
## Rule Action
4525

@@ -71,110 +51,47 @@ For the `sendPushbulletNote` action, parameter `message` is required.
7151
Likewise, for `sendPushbulletLink`, `url` and for `sendPushbulletFile`, `content` parameters are required.
7252
Any other parameters for these actions are optional and can be set to `null`.
7353

74-
Examples:
75-
76-
```java
77-
val actions = getActions("pushbullet", "pushbullet:bot:r2d2")
78-
actions.sendPushbulletNote("[email protected]", "Note Example", "This is the pushed note.")
79-
actions.sendPushbulletLink("[email protected]", "Link Example", "This is the pushed link", "https://example.com")
80-
actions.sendPushbulletFile("[email protected]", "File Example", "This is the pushed file", "https://example.com/image.png")
81-
actions.sendPushbulletFile("[email protected]", null, null, "/path/to/somefile.pdf", "document.pdf")
82-
actions.sendPushbulletFile("[email protected]", ImageItem.state.toFullString)
83-
```
84-
8554
## Full Example
8655

87-
_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._
88-
89-
pushbullet.things:
90-
91-
```java
92-
Thing pushbullet:bot:r2d2 "R2D2" @ "Somewhere" [ token = "verysecretwonttellyou" ]
93-
94-
```
95-
96-
pushbullet.items
56+
demo.things:
9757

9858
```java
99-
Switch Pushbullet_R2D2_Button "Pushbullet Action bot R2D2"
100-
```
101-
102-
pushbullet.sitemap
59+
Thing pushbullet:bot:r2d2 [ token="<ACCESS_TOKEN>" ]
10360

104-
```java
105-
sitemap pushbullet label="Pushbullet"
106-
{
107-
Switch item=Pushbullet_R2D2_Button
108-
}
10961
```
11062

111-
pushbullet.rules
63+
demo.rules
11264

11365
```java
114-
rule "Pushbullet R2D2 changed"
115-
when
116-
Item Pushbullet_R2D2_Button changed
117-
then
118-
logInfo(filename, "Button R2D2 changed - OH2...")
119-
120-
if (Pushbullet_R2D2_Button.state == ON)
121-
{
122-
sendCommand(Pushbullet_R2D2_Button, OFF)
123-
124-
val actions = getActions("pushbullet", "pushbullet:bot:r2d2")
125-
logInfo(filename, "Actions for 'R2D2' are: " + actions)
126-
127-
if (actions != null)
128-
{
129-
val result = actions.sendPushbulletNote("[email protected]", "Title R2D2 OH2", "This has been sent by the new R2D2 bot")
130-
logInfo(filename, "Result of send action is: " + result)
131-
}
132-
}
133-
end
66+
val actions = getActions("pushbullet", "pushbullet:bot:r2d2")
67+
// push a note
68+
actions.sendPushbulletNote("[email protected]", "Note Example", "This is the pushed note.")
69+
// push a link
70+
actions.sendPushbulletLink("[email protected]", "Link Example", "This is the pushed link", "https://example.com")
71+
// push a file
72+
actions.sendPushbulletFile("[email protected]", "File Example", "This is the pushed file", "https://example.com/image.png")
73+
actions.sendPushbulletFile("[email protected]", null, null, "/path/to/somefile.pdf", "document.pdf")
74+
// use toFullString method to push the content of an Image item
75+
actions.sendPushbulletFile("[email protected]", ImageItem.state.toFullString)
13476
```
13577

136-
## Creating an account for your bot(s)
78+
## Creating an account
13779

138-
The pushbullet accounts are bound to either Google or Facebook accounts.
80+
A Pushbullet account is linked to either a Google or Facebook account.
13981

140-
- Create a bot account with either Facebook or Google
141-
- Go to "<https://www.pushbullet.com/>"
142-
- Chose to either "Sign up with Google" or "Sign up with Facebook".
82+
- Go to the [Pushbullet](https://www.pushbullet.com) website.
83+
- Select either "Sign up with Google" or "Sign up with Facebook".
14384
- Complete the signup process as guided by the pushbullet web site.
144-
- Continue with "Obtaining an API key".
14585

146-
## Obtaining an API key
86+
## Obtaining an access token
14787

148-
The API keys are bound to the pushbullet account.
88+
An access token is linked to a Pushbullet account.
14989

150-
- Go to the pushbullet site.
151-
- Log in with either your personal account or the one you created for your bot.
152-
- Go to "<https://www.pushbullet.com/#settings/account>"
90+
- Go to your [Pushbullet account settings](https://www.pushbullet.com/#settings/account) page.
15391
- Click on "Create Access Token".
154-
- Copy the token created on the site.
155-
156-
You must at least provide an API token (Private or Alias Key from Pushbullet.com) and a message in some manner before a message can be pushed.
157-
All other parameters are optional.
158-
If you use an alias key, the parameters (device, icon, sound, vibration) are overwritten by the alias setting on pushbullet.
92+
- Copy the created access token.
15993

16094
## Rate limits
16195

162-
As of 2019, free accounts have a limit of 100 pushes per month.
163-
This action does not evaluate the rate limiting headers though.
164-
165-
## Translation
166-
167-
This project is being translated on transifex.
168-
If you want to help, please join the project at the URL:
169-
170-
- <https://www.transifex.com/hakan42/openhab-binding-pushbullet/dashboard/>
171-
172-
## Libraries
173-
174-
This action has been written without using libraries as jpushbullet or jpushbullet2.
175-
Both of those libraries use various libraries themselves which makes integrating them into openHAB a challenge.
176-
177-
## pushbullet API
178-
179-
- <https://docs.pushbullet.com/>
180-
- <https://docs.pushbullet.com/#push-limit>
96+
As of 2024, free accounts are [limited](https://docs.pushbullet.com/#limits) to 500 pushes per month.
97+
Going over will result in a warning message being logged indicating when your account rate limit will reset.

bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/PushbulletBindingConstants.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,19 @@ public class PushbulletBindingConstants {
3434

3535
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BOT);
3636

37-
// List of all Channel ids
38-
public static final String RECIPIENT = "recipient";
39-
public static final String TITLE = "title";
40-
public static final String MESSAGE = "message";
41-
4237
// Thing properties
4338
public static final String PROPERTY_EMAIL = "email";
4439
public static final String PROPERTY_NAME = "name";
4540

4641
// Binding logic constants
42+
public static final String API_BASE_URL = "https://api.pushbullet.com/v2";
43+
4744
public static final String API_ENDPOINT_PUSHES = "/pushes";
4845
public static final String API_ENDPOINT_UPLOAD_REQUEST = "/upload-request";
4946
public static final String API_ENDPOINT_USERS_ME = "/users/me";
5047

48+
public static final String HEADER_RATELIMIT_RESET = "X-Ratelimit-Reset";
49+
5150
public static final String IMAGE_FILE_NAME = "image.jpg";
5251

5352
public static final int MAX_UPLOAD_SIZE = 26214400;

bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/PushbulletConfiguration.java

-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.openhab.binding.pushbullet.internal;
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
16-
import org.eclipse.jdt.annotation.Nullable;
1716

1817
/**
1918
* The {@link PushbulletConfiguration} class contains fields mapping thing configuration parameters.
@@ -24,21 +23,9 @@
2423
@NonNullByDefault
2524
public class PushbulletConfiguration {
2625

27-
private @Nullable String name;
28-
2926
private String token = "";
3027

31-
private String apiUrlBase = "https://api.pushbullet.com/v2";
32-
33-
public @Nullable String getName() {
34-
return name;
35-
}
36-
3728
public String getAccessToken() {
3829
return token;
3930
}
40-
41-
public String getApiUrlBase() {
42-
return apiUrlBase;
43-
}
4431
}

bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/PushbulletHttpClient.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.binding.pushbullet.internal;
1414

15+
import static org.openhab.binding.pushbullet.internal.PushbulletBindingConstants.*;
16+
1517
import java.time.Instant;
1618
import java.util.Objects;
1719
import java.util.concurrent.ExecutionException;
@@ -49,11 +51,10 @@
4951
*/
5052
@NonNullByDefault
5153
public class PushbulletHttpClient {
52-
private static final String AGENT = "openHAB/" + OpenHAB.getVersion();
5354

54-
private static final int TIMEOUT = 30; // in seconds
55+
private static final String USER_AGENT = "openHAB/" + OpenHAB.getVersion();
5556

56-
private static final String HEADER_RATELIMIT_RESET = "X-Ratelimit-Reset";
57+
private static final int TIMEOUT = 30; // in seconds
5758

5859
private final Logger logger = LoggerFactory.getLogger(PushbulletHttpClient.class);
5960

@@ -95,7 +96,7 @@ public <T> T executeRequest(String apiEndpoint, Class<T> responseType) throws Pu
9596
*/
9697
public <T> T executeRequest(String apiEndpoint, @Nullable Object body, Class<T> responseType)
9798
throws PushbulletApiException {
98-
String url = config.getApiUrlBase() + apiEndpoint;
99+
String url = API_BASE_URL + apiEndpoint;
99100
String accessToken = config.getAccessToken();
100101

101102
Request request = newRequest(url).header("Access-Token", accessToken);
@@ -142,7 +143,7 @@ public void uploadFile(String url, RawType data) throws PushbulletApiException {
142143
* @return the new Request object with default parameters
143144
*/
144145
private Request newRequest(String url) {
145-
return httpClient.newRequest(url).agent(AGENT).timeout(TIMEOUT, TimeUnit.SECONDS);
146+
return httpClient.newRequest(url).agent(USER_AGENT).timeout(TIMEOUT, TimeUnit.SECONDS);
146147
}
147148

148149
/**

bundles/org.openhab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/handler/PushbulletHandler.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ public PushbulletHandler(Thing thing, HttpClient httpClient) {
7878

7979
@Override
8080
public void handleCommand(ChannelUID channelUID, Command command) {
81-
logger.debug("About to handle {} on {}", command, channelUID);
82-
83-
// Future improvement: If recipient is already set, send a push on a command channel change
84-
// check reconnect channel of the unifi binding for that
85-
86-
logger.debug("The Pushbullet binding is a read-only binding and cannot handle command '{}'.", command);
81+
// do nothing
8782
}
8883

8984
@Override

bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/i18n/pushbullet.properties

+1-16
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,8 @@ thing-type.pushbullet.bot.label = Pushbullet Bot
77
thing-type.pushbullet.bot.description = Bot to send messages with.
88

99
# thing types config
10-
thing-type.config.pushbullet.bot.name.label = Name
11-
thing-type.config.pushbullet.bot.name.description = Explicit Name of Bot, if wanted
1210
thing-type.config.pushbullet.bot.token.label = Access Token
13-
thing-type.config.pushbullet.bot.token.description = Access token obtained from the account settings page
14-
thing-type.config.pushbullet.bot.apiUrlBase.label = API Server
15-
thing-type.config.pushbullet.bot.apiUrlBase.description = The Pushbullet API Server to use, for local testing
16-
17-
# channel types
18-
channel-type.pushbullet.recipient-channel.label = Recipient
19-
channel-type.pushbullet.recipient-channel.description = Mail address or Channel Name
20-
channel-type.pushbullet.title-channel.label = Title
21-
channel-type.pushbullet.title-channel.description = Title of the message
22-
channel-type.pushbullet.message-channel.label = Message
23-
channel-type.pushbullet.message-channel.description = The text that is to be sent
11+
thing-type.config.pushbullet.bot.token.description = Access token obtained from the account settings page.
2412

2513
# action
2614
actionSendPushbulletNoteLabel = publish a Pushbullet message
@@ -42,6 +30,3 @@ actionSendPushbulletFileInputContent = File Content
4230
actionSendPushbulletFileInputContentDesc = The File Content to publish
4331
actionSendPushbulletFileInputName = File Name
4432
actionSendPushbulletFileInputNameDesc = The File Name to publish
45-
46-
# error texts
47-
offline.conf-error-httpresponseexception = The pushbullet server reported an error, possibly an expired token. Check on web site

bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/thing/thing-types.xml

+4-37
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,18 @@
88
<label>Pushbullet Bot</label>
99
<description>Bot to send messages with.</description>
1010

11-
<channels>
12-
<channel id="recipient" typeId="recipient-channel"/>
13-
<channel id="title" typeId="title-channel"/>
14-
<channel id="message" typeId="message-channel"/>
15-
</channels>
11+
<properties>
12+
<property name="thingTypeVersion">1</property>
13+
</properties>
1614

1715
<config-description>
18-
<parameter name="name" type="text" required="false">
19-
<label>Name</label>
20-
<description>Explicit Name of Bot, if wanted</description>
21-
<advanced>true</advanced>
22-
</parameter>
23-
2416
<parameter name="token" type="text" required="true">
2517
<label>Access Token</label>
26-
<description>Access token obtained from the account settings page</description>
27-
</parameter>
28-
29-
<parameter name="apiUrlBase" type="text" required="true">
30-
<label>API Server</label>
31-
<description>The Pushbullet API Server to use, for local testing</description>
32-
<default>https://api.pushbullet.com/v2</default>
33-
<advanced>true</advanced>
18+
<description>Access token obtained from the account settings page.</description>
3419
</parameter>
3520

3621
</config-description>
3722

3823
</thing-type>
3924

40-
<channel-type id="recipient-channel">
41-
<item-type>String</item-type>
42-
<label>Recipient</label>
43-
<description>Mail address or Channel Name</description>
44-
</channel-type>
45-
46-
<channel-type id="title-channel">
47-
<item-type>String</item-type>
48-
<label>Title</label>
49-
<description>Title of the message</description>
50-
</channel-type>
51-
52-
<channel-type id="message-channel">
53-
<item-type>String</item-type>
54-
<label>Message</label>
55-
<description>The text that is to be sent</description>
56-
</channel-type>
57-
5825
</thing:thing-descriptions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
4+
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
5+
6+
<thing-type uid="pushbullet:bot">
7+
<instruction-set targetVersion="1">
8+
<remove-channel id="recipient"/>
9+
<remove-channel id="title"/>
10+
<remove-channel id="message"/>
11+
</instruction-set>
12+
</thing-type>
13+
14+
</update:update-descriptions>

0 commit comments

Comments
 (0)