[hdpowerview] Add firmware information properties for hub and shade. (#11980)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
1280a0e11b
commit
05ebeea86b
@ -54,10 +54,19 @@ public class HDPowerViewBindingConstants {
|
|||||||
public static final String CHANNELTYPE_SCENE_GROUP_ACTIVATE = "scene-group-activate";
|
public static final String CHANNELTYPE_SCENE_GROUP_ACTIVATE = "scene-group-activate";
|
||||||
public static final String CHANNELTYPE_AUTOMATION_ENABLED = "automation-enabled";
|
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_TYPE = "type";
|
||||||
public static final String PROPERTY_SHADE_CAPABILITIES = "capabilities";
|
public static final String PROPERTY_SHADE_CAPABILITIES = "capabilities";
|
||||||
public static final String PROPERTY_SECONDARY_RAIL_DETECTED = "secondaryRailDetected";
|
public static final String PROPERTY_SECONDARY_RAIL_DETECTED = "secondaryRailDetected";
|
||||||
public static final String PROPERTY_TILT_ANYWHERE_DETECTED = "tiltAnywhereDetected";
|
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");
|
public static final List<String> NETBIOS_NAMES = Arrays.asList("PDBU-Hub3.0", "PowerView-Hub");
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
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.ShadeMove;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop;
|
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.SceneCollections;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
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.ScheduledEvents;
|
||||||
@ -64,6 +65,7 @@ public class HDPowerViewWebTargets {
|
|||||||
private Instant maintenanceScheduledEnd = Instant.now().minusSeconds(2 * maintenancePeriod);
|
private Instant maintenanceScheduledEnd = Instant.now().minusSeconds(2 * maintenancePeriod);
|
||||||
|
|
||||||
private final String base;
|
private final String base;
|
||||||
|
private final String firmwareVersion;
|
||||||
private final String shades;
|
private final String shades;
|
||||||
private final String sceneActivate;
|
private final String sceneActivate;
|
||||||
private final String scenes;
|
private final String scenes;
|
||||||
@ -113,6 +115,7 @@ public class HDPowerViewWebTargets {
|
|||||||
public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
|
public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
|
||||||
base = "http://" + ipAddress + "/api/";
|
base = "http://" + ipAddress + "/api/";
|
||||||
shades = base + "shades/";
|
shades = base + "shades/";
|
||||||
|
firmwareVersion = base + "fwversion/";
|
||||||
sceneActivate = base + "scenes";
|
sceneActivate = base + "scenes";
|
||||||
scenes = base + "scenes/";
|
scenes = base + "scenes/";
|
||||||
|
|
||||||
@ -124,6 +127,20 @@ public class HDPowerViewWebTargets {
|
|||||||
this.httpClient = httpClient;
|
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
|
* Fetches a JSON package that describes all shades in the hub, and wraps it in
|
||||||
* a Shades class instance
|
* a Shades class instance
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
@ -17,6 +17,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +53,8 @@ public class Shades {
|
|||||||
public @Nullable Boolean timedOut;
|
public @Nullable Boolean timedOut;
|
||||||
public int signalStrength;
|
public int signalStrength;
|
||||||
public @Nullable Integer capabilities;
|
public @Nullable Integer capabilities;
|
||||||
|
public @Nullable Firmware firmware;
|
||||||
|
public @Nullable Firmware motor;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return new String(Base64.getDecoder().decode(name));
|
return new String(Base64.getDecoder().decode(name));
|
||||||
|
|||||||
@ -36,6 +36,9 @@ import org.openhab.binding.hdpowerview.internal.HDPowerViewTranslationProvider;
|
|||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
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;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
||||||
@ -95,6 +98,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
private List<Scene> sceneCache = new CopyOnWriteArrayList<>();
|
private List<Scene> sceneCache = new CopyOnWriteArrayList<>();
|
||||||
private List<SceneCollection> sceneCollectionCache = new CopyOnWriteArrayList<>();
|
private List<SceneCollection> sceneCollectionCache = new CopyOnWriteArrayList<>();
|
||||||
private List<ScheduledEvent> scheduledEventCache = new CopyOnWriteArrayList<>();
|
private List<ScheduledEvent> scheduledEventCache = new CopyOnWriteArrayList<>();
|
||||||
|
private @Nullable FirmwareVersions firmwareVersions;
|
||||||
private Boolean deprecatedChannelsCreated = false;
|
private Boolean deprecatedChannelsCreated = false;
|
||||||
|
|
||||||
private final ChannelTypeUID sceneChannelTypeUID = new ChannelTypeUID(HDPowerViewBindingConstants.BINDING_ID,
|
private final ChannelTypeUID sceneChannelTypeUID = new ChannelTypeUID(HDPowerViewBindingConstants.BINDING_ID,
|
||||||
@ -254,6 +258,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
private synchronized void poll() {
|
private synchronized void poll() {
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling for state");
|
logger.debug("Polling for state");
|
||||||
|
updateFirmwareProperties();
|
||||||
pollShades();
|
pollShades();
|
||||||
|
|
||||||
List<Scene> scenes = updateSceneChannels();
|
List<Scene> scenes = updateSceneChannels();
|
||||||
@ -273,6 +278,39 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
private void pollShades() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
||||||
HDPowerViewWebTargets webTargets = this.webTargets;
|
HDPowerViewWebTargets webTargets = this.webTargets;
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
|||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;
|
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.ShadePosition;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
@ -180,6 +181,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||||||
if (shadeData != null) {
|
if (shadeData != null) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
updateSoftProperties(shadeData);
|
updateSoftProperties(shadeData);
|
||||||
|
updateFirmwareProperties(shadeData);
|
||||||
updateBindingStates(shadeData.positions);
|
updateBindingStates(shadeData.positions);
|
||||||
updateBatteryLevel(shadeData.batteryStatus);
|
updateBatteryLevel(shadeData.batteryStatus);
|
||||||
updateState(CHANNEL_SHADE_BATTERY_VOLTAGE,
|
updateState(CHANNEL_SHADE_BATTERY_VOLTAGE,
|
||||||
@ -242,6 +244,19 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
* After a hard refresh, update the Thing's properties based on the contents of the provided ShadeData.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user