Skip to content

Commit

Permalink
[hdpowerview] Add firmware information properties for hub and shade. (o…
Browse files Browse the repository at this point in the history
…penhab#11980)

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
  • Loading branch information
jlaur authored and andrasU committed Nov 12, 2022
1 parent c99a161 commit 2ce2e04
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ public class HDPowerViewBindingConstants {
public static final String CHANNELTYPE_SCENE_GROUP_ACTIVATE = "scene-group-activate";
public static final String CHANNELTYPE_AUTOMATION_ENABLED = "automation-enabled";

// Hub properties
public static final String PROPERTY_FIRMWARE_NAME = "firmwareName";
public static final String PROPERTY_RADIO_FIRMWARE_VERSION = "radioFirmwareVersion";

// Hub/shade properties
public static final String PROPERTY_FIRMWARE_VERSION = "firmwareVersion";

// Shade properties
public static final String PROPERTY_SHADE_TYPE = "type";
public static final String PROPERTY_SHADE_CAPABILITIES = "capabilities";
public static final String PROPERTY_SECONDARY_RAIL_DETECTED = "secondaryRailDetected";
public static final String PROPERTY_TILT_ANYWHERE_DETECTED = "tiltAnywhereDetected";
public static final String PROPERTY_MOTOR_FIRMWARE_VERSION = "motorFirmwareVersion";

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 @@ -28,6 +28,7 @@
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeMove;
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop;
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersion;
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;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class HDPowerViewWebTargets {
private Instant maintenanceScheduledEnd = Instant.now().minusSeconds(2 * maintenancePeriod);

private final String base;
private final String firmwareVersion;
private final String shades;
private final String sceneActivate;
private final String scenes;
Expand Down Expand Up @@ -113,6 +115,7 @@ public String toString() {
public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
base = "http://" + ipAddress + "/api/";
shades = base + "shades/";
firmwareVersion = base + "fwversion/";
sceneActivate = base + "scenes";
scenes = base + "scenes/";

Expand All @@ -124,6 +127,20 @@ public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
this.httpClient = httpClient;
}

/**
* Fetches a JSON package with firmware information for the hub.
*
* @return FirmwareVersion 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 FirmwareVersion getFirmwareVersion()
throws JsonParseException, HubProcessingException, HubMaintenanceException {
String json = invoke(HttpMethod.GET, firmwareVersion, null, null);
return gson.fromJson(json, FirmwareVersion.class);
}

/**
* Fetches a JSON package that describes all shades in the hub, and wraps it in
* a Shades class instance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2010-2022 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.hdpowerview.internal.api;

/**
* Firmware version information for HD PowerView components
*
* @author Jacob Laursen - Initial contribution
*/
public class Firmware {
public String name;
public int revision;
public int subRevision;
public int build;

@Override
public String toString() {
return String.format("%d.%d.%d", revision, subRevision, build);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2010-2022 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.hdpowerview.internal.api.responses;

/**
* Firmware information for an HD PowerView hub
*
* @author Jacob Laursen - Initial contribution
*/
public class FirmwareVersion {
public FirmwareVersions firmware;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2010-2022 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.hdpowerview.internal.api.responses;

import org.openhab.binding.hdpowerview.internal.api.Firmware;

/**
* Firmware information for an HD PowerView hub
*
* @author Jacob Laursen - Initial contribution
*/
public class FirmwareVersions {
public Firmware mainProcessor;
public Firmware radio;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hdpowerview.internal.api.Firmware;
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;

/**
Expand Down Expand Up @@ -52,6 +53,8 @@ public static class ShadeData {
public @Nullable Boolean timedOut;
public int signalStrength;
public @Nullable Integer capabilities;
public @Nullable Firmware firmware;
public @Nullable Firmware motor;

public String getName() {
return new String(Base64.getDecoder().decode(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
import org.openhab.binding.hdpowerview.internal.api.Firmware;
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersion;
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersions;
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
Expand Down Expand Up @@ -95,6 +98,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
private List<Scene> sceneCache = new CopyOnWriteArrayList<>();
private List<SceneCollection> sceneCollectionCache = new CopyOnWriteArrayList<>();
private List<ScheduledEvent> scheduledEventCache = new CopyOnWriteArrayList<>();
private @Nullable FirmwareVersions firmwareVersions;
private Boolean deprecatedChannelsCreated = false;

private final ChannelTypeUID sceneChannelTypeUID = new ChannelTypeUID(HDPowerViewBindingConstants.BINDING_ID,
Expand Down Expand Up @@ -254,6 +258,7 @@ private synchronized void stopPoll() {
private synchronized void poll() {
try {
logger.debug("Polling for state");
updateFirmwareProperties();
pollShades();

List<Scene> scenes = updateSceneChannels();
Expand All @@ -273,6 +278,39 @@ private synchronized void poll() {
}
}

private void updateFirmwareProperties() throws JsonParseException, HubProcessingException, HubMaintenanceException {
if (firmwareVersions != null) {
return;
}
HDPowerViewWebTargets webTargets = this.webTargets;
if (webTargets == null) {
throw new ProcessingException("Web targets not initialized");
}
FirmwareVersion firmwareVersion = webTargets.getFirmwareVersion();
if (firmwareVersion == null || firmwareVersion.firmware == null) {
logger.warn("Unable to get firmware version.");
return;
}
this.firmwareVersions = firmwareVersion.firmware;
Firmware mainProcessor = firmwareVersion.firmware.mainProcessor;
if (mainProcessor == null) {
logger.warn("Main processor firmware version missing in response.");
return;
}
logger.debug("Main processor firmware version received: {}, {}", mainProcessor.name, mainProcessor.toString());
Map<String, String> properties = editProperties();
if (mainProcessor.name != null) {
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_NAME, mainProcessor.name);
}
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_VERSION, mainProcessor.toString());
Firmware radio = firmwareVersion.firmware.radio;
if (radio != null) {
logger.debug("Radio firmware version received: {}", radio.toString());
properties.put(HDPowerViewBindingConstants.PROPERTY_RADIO_FIRMWARE_VERSION, radio.toString());
}
updateProperties(properties);
}

private void pollShades() throws JsonParseException, HubProcessingException, HubMaintenanceException {
HDPowerViewWebTargets webTargets = this.webTargets;
if (webTargets == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;
import org.openhab.binding.hdpowerview.internal.api.Firmware;
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
Expand Down Expand Up @@ -180,6 +181,7 @@ protected void onReceiveUpdate(@Nullable ShadeData shadeData) {
if (shadeData != null) {
updateStatus(ThingStatus.ONLINE);
updateSoftProperties(shadeData);
updateFirmwareProperties(shadeData);
updateBindingStates(shadeData.positions);
updateBatteryLevel(shadeData.batteryStatus);
updateState(CHANNEL_SHADE_BATTERY_VOLTAGE,
Expand Down Expand Up @@ -242,6 +244,19 @@ private void updateSoftProperties(ShadeData shadeData) {
}
}

private void updateFirmwareProperties(ShadeData shadeData) {
Map<String, String> properties = editProperties();
Firmware shadeFirmware = shadeData.firmware;
Firmware motorFirmware = shadeData.motor;
if (shadeFirmware != null) {
properties.put(PROPERTY_FIRMWARE_VERSION, shadeFirmware.toString());
}
if (motorFirmware != null) {
properties.put(PROPERTY_MOTOR_FIRMWARE_VERSION, motorFirmware.toString());
}
updateProperties(properties);
}

/**
* After a hard refresh, update the Thing's properties based on the contents of the provided ShadeData.
*
Expand Down

0 comments on commit 2ce2e04

Please sign in to comment.