Skip to content

Commit

Permalink
Merge branch 'openhab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuesel committed Dec 11, 2021
2 parents 496a1d3 + f2996aa commit 5ebba0b
Show file tree
Hide file tree
Showing 28 changed files with 692 additions and 116 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.ahawastecollection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
<version>1.14.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<feature name="openhab-binding-ahawastecollection" description="aha Waste Collection Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.jsoup/jsoup/1.8.3</bundle>
<bundle dependency="true">mvn:org.jsoup/jsoup/1.14.3</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.ahawastecollection/${project.version}</bundle>
</feature>
</features>
14 changes: 8 additions & 6 deletions bundles/org.openhab.binding.hdpowerview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ However, the configuration parameters are described below:

### Channels for PowerView Hub

Scene and scene group channels will be added dynamically to the binding as they are discovered in the hub.
Each scene/scene group channel will have an entry in the hub as shown below, whereby different scenes/scene groups
Scene, scene group and automation channels will be added dynamically to the binding as they are discovered in the hub.
Each will have an entry in the hub as shown below, whereby different scenes, scene groups and automations
have different `id` values:

| Channel | Item Type | Description |
|----------|-----------| ------------|
| id | Switch | Turning this to ON will activate the scene/scene group. Scenes/scene groups are stateless in the PowerView hub; they have no on/off state. Note: include `{autoupdate="false"}` in the item configuration to avoid having to reset it to off after use. |
| Channel Group | Channel | Item Type | Description |
|---------------|---------|-----------|-------------|
| scenes | id | Switch | Setting this to ON will activate the scene. Scenes are stateless in the PowerView hub; they have no on/off state. Note: include `{autoupdate="false"}` in the item configuration to avoid having to reset it to off after use. |
| sceneGroups | id | Switch | Setting this to ON will activate the scene group. Scene groups are stateless in the PowerView hub; they have no on/off state. Note: include `{autoupdate="false"}` in the item configuration to avoid having to reset it to off after use. |
| automations | id | Switch | Setting this to ON will enable the automation, while OFF will disable it. |

### Channels for PowerView Shade

Expand Down Expand Up @@ -181,7 +183,7 @@ Switch Living_Room_Shade_Battery_Low_Alarm "Living Room Shade Battery Low Alarm
Scene items:

```
Switch Living_Room_Shades_Scene_Heart "Living Room Shades Scene Heart" <blinds> (g_Shades_Scene_Trigger) {channel="hdpowerview:hub:g24:22663", autoupdate="false"}
Switch Living_Room_Shades_Scene_Heart "Living Room Shades Scene Heart" <blinds> (g_Shades_Scene_Trigger) {channel="hdpowerview:hub:g24:scenes#22663", autoupdate="false"}
```

### `demo.sitemap` File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Andy Lintner - Initial contribution
* @author Andrew Fiddian-Green - Added support for secondary rail positions
* @author Jacob Laursen - Add support for scene groups
* @author Jacob Laursen - Add support for scene groups and automations
*/
@NonNullByDefault
public class HDPowerViewBindingConstants {
Expand All @@ -46,8 +46,13 @@ public class HDPowerViewBindingConstants {
public static final String CHANNEL_SHADE_BATTERY_VOLTAGE = "batteryVoltage";
public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength";

public static final String CHANNEL_GROUP_SCENES = "scenes";
public static final String CHANNEL_GROUP_SCENE_GROUPS = "sceneGroups";
public static final String CHANNEL_GROUP_AUTOMATIONS = "automations";

public static final String CHANNELTYPE_SCENE_ACTIVATE = "scene-activate";
public static final String CHANNELTYPE_SCENE_GROUP_ACTIVATE = "scene-group-activate";
public static final String CHANNELTYPE_AUTOMATION_ENABLED = "automation-enabled";

public static final List<String> NETBIOS_NAMES = Arrays.asList("PDBU-Hub3.0", "PowerView-Hub");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.hdpowerview.internal;

import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.i18n.LocaleProvider;
Expand Down Expand Up @@ -44,4 +46,8 @@ public String getText(String key, @Nullable Object... arguments) {
}
return key;
}

public Locale getLocale() {
return localeProvider.getLocale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop;
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents;
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;

/**
* JAX-RS targets for communicating with an HD PowerView hub
*
* @author Andy Lintner - Initial contribution
* @author Andrew Fiddian-Green - Added support for secondary rail positions
* @author Jacob Laursen - Add support for scene groups
* @author Jacob Laursen - Add support for scene groups and automations
*/
@NonNullByDefault
public class HDPowerViewWebTargets {
Expand All @@ -65,6 +68,7 @@ public class HDPowerViewWebTargets {
private final String scenes;
private final String sceneCollectionActivate;
private final String sceneCollections;
private final String scheduledEvents;

private final Gson gson = new Gson();
private final HttpClient httpClient;
Expand Down Expand Up @@ -107,6 +111,7 @@ public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
scenes = base + "scenes/";
sceneCollectionActivate = base + "sceneCollections";
sceneCollections = base + "sceneCollections/";
scheduledEvents = base + "scheduledevents";
this.httpClient = httpClient;
}

Expand Down Expand Up @@ -189,6 +194,41 @@ public void activateSceneCollection(int sceneCollectionId) throws HubProcessingE
Query.of("sceneCollectionId", Integer.toString(sceneCollectionId)), null);
}

/**
* Fetches a JSON package that describes all scheduled events in the hub, and wraps it in
* a ScheduledEvents class instance
*
* @return ScheduledEvents class instance
* @throws JsonParseException if there is a JSON parsing error
* @throws HubProcessingException if there is any processing error
* @throws HubMaintenanceException if the hub is down for maintenance
*/
public @Nullable ScheduledEvents getScheduledEvents()
throws JsonParseException, HubProcessingException, HubMaintenanceException {
String json = invoke(HttpMethod.GET, scheduledEvents, null, null);
return gson.fromJson(json, ScheduledEvents.class);
}

/**
* Enables or disables a scheduled event in the hub.
*
* @param scheduledEventId id of the scheduled event to be enabled or disabled
* @param enable true to enable scheduled event, false to disable
* @throws JsonParseException if there is a JSON parsing error
* @throws JsonSyntaxException if there is a JSON syntax error
* @throws HubProcessingException if there is any processing error
* @throws HubMaintenanceException if the hub is down for maintenance
*/
public void enableScheduledEvent(int scheduledEventId, boolean enable)
throws JsonParseException, HubProcessingException, HubMaintenanceException {
String uri = scheduledEvents + "/" + scheduledEventId;
String json = invoke(HttpMethod.GET, uri, null, null);
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
JsonObject scheduledEventObject = jsonObject.get("scheduledEvent").getAsJsonObject();
scheduledEventObject.addProperty("enabled", enable);
invoke(HttpMethod.PUT, uri, null, jsonObject.toString());
}

/**
* Invoke a call on the hub server to retrieve information or send a command
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.jdt.annotation.Nullable;

/**
* State of all Scenes in an HD PowerView hub
* State of all Scene Collections in an HD PowerView hub
*
* @author Jacob Laursen - Initial contribution
*/
Expand All @@ -38,13 +38,45 @@ public class SceneCollections {
*/
@SuppressWarnings("null")
@NonNullByDefault
public static class SceneCollection {
public static class SceneCollection implements Comparable<SceneCollection> {
public int id;
public @Nullable String name;
public int order;
public int colorId;
public int iconId;

@Override
public boolean equals(@Nullable Object o) {
if (o == this) {
return true;
}
if (!(o instanceof SceneCollection)) {
return false;
}
SceneCollection other = (SceneCollection) o;

return this.id == other.id && this.name.equals(other.name) && this.order == other.order
&& this.colorId == other.colorId && this.iconId == other.iconId;
}

@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + order;
result = prime * result + colorId;
result = prime * result + iconId;

return result;
}

@Override
public int compareTo(SceneCollection other) {
return Integer.compare(order, other.order);
}

public String getName() {
return new String(Base64.getDecoder().decode(name), StandardCharsets.UTF_8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,47 @@ public class Scenes {
*/
@SuppressWarnings("null")
@NonNullByDefault
public static class Scene {
public static class Scene implements Comparable<Scene> {
public int id;
public @Nullable String name;
public int roomId;
public int order;
public int colorId;
public int iconId;

@Override
public boolean equals(@Nullable Object o) {
if (o == this) {
return true;
}
if (!(o instanceof Scene)) {
return false;
}
Scene other = (Scene) o;

return this.id == other.id && this.name.equals(other.name) && this.roomId == other.roomId
&& this.order == other.order && this.colorId == other.colorId && this.iconId == other.iconId;
}

@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + roomId;
result = prime * result + order;
result = prime * result + colorId;
result = prime * result + iconId;

return result;
}

@Override
public int compareTo(Scene other) {
return Integer.compare(order, other.order);
}

public String getName() {
return new String(Base64.getDecoder().decode(name), StandardCharsets.UTF_8);
}
Expand Down
Loading

0 comments on commit 5ebba0b

Please sign in to comment.