[draytonwiser] Expose Smart Plug Power Metering, Improve null handling (#9706)

* [draytonwiser] Expose Smart Plug Power Metering
* [draytonwiser] Handle null values from offline devices

Signed-off-by: James Melville <jamesmelville@gmail.com>
This commit is contained in:
James Melville 2021-01-06 23:09:11 +00:00 committed by GitHub
parent 6c648c4a4a
commit ae7eb26b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 21 deletions

View File

@ -111,11 +111,13 @@ The `awaySetPoint` defines the temperature in degrees Celsius that will be sent
#### Smart Plug #### Smart Plug
| Channel | Item Type | Description | | Channel | Item Type | Description |
|---------------------|-----------|------------------------------------| |--------------------------|---------------|--------------------------------------------|
| `currentSignalRSSI` | Number | Relative Signal Strength Indicator | | `currentSignalRSSI` | Number | Relative Signal Strength Indicator |
| `currentSignalLQI` | Number | Link Quality Indicator | | `currentSignalLQI` | Number | Link Quality Indicator |
| `zigbeeConnected` | Switch | Is the TRV joined to network | | `zigbeeConnected` | Switch | Is the TRV joined to network |
| `plugInstantaneousPower` | Number:Power | Current Power being drawn through the plug |
| `plugEnergyDelivered` | Number:Energy | Cumulative energy drawn through the plug |
### Command Channels ### Command Channels

View File

@ -18,6 +18,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.types.State; import org.openhab.core.types.State;
@ -105,6 +106,8 @@ public class DraytonWiserBindingConstants {
public static final String CHANNEL_SMARTPLUG_OUTPUT_STATE = "plugOutputState"; public static final String CHANNEL_SMARTPLUG_OUTPUT_STATE = "plugOutputState";
public static final String CHANNEL_SMARTPLUG_AWAY_ACTION = "plugAwayAction"; public static final String CHANNEL_SMARTPLUG_AWAY_ACTION = "plugAwayAction";
public static final String CHANNEL_COMFORT_MODE_STATE = "comfortModeState"; public static final String CHANNEL_COMFORT_MODE_STATE = "comfortModeState";
public static final String CHANNEL_SMARTPLUG_INSTANTANEOUS_POWER = "plugInstantaneousPower";
public static final String CHANNEL_SMARTPLUG_ENERGY_DELIVERED = "plugEnergyDelivered";
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, THING_TYPE_ROOMSTAT, .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, THING_TYPE_ROOMSTAT,
@ -149,11 +152,15 @@ public class DraytonWiserBindingConstants {
this.batteryLevel = batteryLevel; this.batteryLevel = batteryLevel;
} }
public static State toBatteryLevel(final String level) { public static State toBatteryLevel(final @Nullable String level) {
try { if (level != null) {
return new DecimalType(BatteryLevel.valueOf(level.toUpperCase()).batteryLevel); try {
} catch (final IllegalArgumentException e) { return new DecimalType(BatteryLevel.valueOf(level.toUpperCase()).batteryLevel);
// Catch unrecognized values. } catch (final IllegalArgumentException e) {
// Catch unrecognized values.
return UnDefType.UNDEF;
}
} else {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
} }

View File

@ -104,11 +104,13 @@ public class RoomStatHandler extends DraytonWiserThingHandler<RoomStatData> {
} }
private State getSignalRSSI() { private State getSignalRSSI() {
return new DecimalType(getData().device.getRssi()); final Integer rssi = getData().device.getRssi();
return rssi == null ? UnDefType.UNDEF : new QuantityType<>(rssi, Units.DECIBEL_MILLIWATTS);
} }
private State getSignalLQI() { private State getSignalLQI() {
return new DecimalType(getData().device.getLqi()); final Integer lqi = getData().device.getLqi();
return lqi == null ? UnDefType.UNDEF : new DecimalType(lqi);
} }
private State getWiserSignalStrength() { private State getWiserSignalStrength() {
@ -120,7 +122,8 @@ public class RoomStatHandler extends DraytonWiserThingHandler<RoomStatData> {
} }
private State getBatteryVoltage() { private State getBatteryVoltage() {
return new QuantityType<>(getData().device.getBatteryVoltage() / 10.0, Units.VOLT); final Integer voltage = getData().device.getBatteryVoltage();
return voltage == null ? UnDefType.UNDEF : new QuantityType<>(voltage / 10.0, Units.VOLT);
} }
private State getWiserBatteryLevel() { private State getWiserBatteryLevel() {

View File

@ -23,6 +23,8 @@ import org.openhab.binding.draytonwiser.internal.model.DraytonWiserDTO;
import org.openhab.binding.draytonwiser.internal.model.SmartPlugDTO; import org.openhab.binding.draytonwiser.internal.model.SmartPlugDTO;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
import org.openhab.core.types.State; import org.openhab.core.types.State;
@ -79,6 +81,8 @@ public class SmartPlugHandler extends DraytonWiserThingHandler<SmartPlugData> {
updateState(CHANNEL_ZIGBEE_CONNECTED, this::getZigbeeConnected); updateState(CHANNEL_ZIGBEE_CONNECTED, this::getZigbeeConnected);
updateState(CHANNEL_DEVICE_LOCKED, this::getDeviceLocked); updateState(CHANNEL_DEVICE_LOCKED, this::getDeviceLocked);
updateState(CHANNEL_MANUAL_MODE_STATE, this::getManualModeState); updateState(CHANNEL_MANUAL_MODE_STATE, this::getManualModeState);
updateState(CHANNEL_SMARTPLUG_INSTANTANEOUS_POWER, this::getInstantaneousDemand);
updateState(CHANNEL_SMARTPLUG_ENERGY_DELIVERED, this::getCurrentSummationDelivered);
} }
@Override @Override
@ -100,11 +104,13 @@ public class SmartPlugHandler extends DraytonWiserThingHandler<SmartPlugData> {
} }
private State getSignalRSSI() { private State getSignalRSSI() {
return new DecimalType(getData().device.getRssi()); final Integer rssi = getData().device.getRssi();
return rssi == null ? UnDefType.UNDEF : new QuantityType<>(rssi, Units.DECIBEL_MILLIWATTS);
} }
private State getSignalLQI() { private State getSignalLQI() {
return new DecimalType(getData().device.getLqi()); final Integer lqi = getData().device.getLqi();
return lqi == null ? UnDefType.UNDEF : new DecimalType(lqi);
} }
private State getZigbeeConnected() { private State getZigbeeConnected() {
@ -136,6 +142,16 @@ public class SmartPlugHandler extends DraytonWiserThingHandler<SmartPlugData> {
getApi().setSmartPlugAwayAction(getData().smartPlug.getId(), awayAction); getApi().setSmartPlugAwayAction(getData().smartPlug.getId(), awayAction);
} }
private State getInstantaneousDemand() {
final Integer demand = getData().smartPlug.getInstantaneousDemand();
return demand == null ? UnDefType.UNDEF : new QuantityType<>(demand, Units.WATT);
}
private State getCurrentSummationDelivered() {
final Integer delivered = getData().smartPlug.getCurrentSummationDelivered();
return delivered == null ? UnDefType.UNDEF : new QuantityType<>(delivered, Units.WATT_HOUR);
}
static class SmartPlugData { static class SmartPlugData {
public final SmartPlugDTO smartPlug; public final SmartPlugDTO smartPlug;
public final DeviceDTO device; public final DeviceDTO device;

View File

@ -93,7 +93,8 @@ public class TRVHandler extends DraytonWiserThingHandler<SmartValveData> {
} }
private State getDemand() { private State getDemand() {
return new QuantityType<>(getData().smartValve.getPercentageDemand(), Units.PERCENT); final Integer demand = getData().smartValve.getPercentageDemand();
return demand == null ? UnDefType.UNDEF : new QuantityType<>(demand, Units.PERCENT);
} }
private State getTemperature() { private State getTemperature() {
@ -104,11 +105,13 @@ public class TRVHandler extends DraytonWiserThingHandler<SmartValveData> {
} }
private State getSignalRSSI() { private State getSignalRSSI() {
return new DecimalType(getData().device.getRssi()); final Integer rssi = getData().device.getRssi();
return rssi == null ? UnDefType.UNDEF : new QuantityType<>(rssi, Units.DECIBEL_MILLIWATTS);
} }
private State getSignalLQI() { private State getSignalLQI() {
return new DecimalType(getData().device.getLqi()); final Integer lqi = getData().device.getLqi();
return lqi == null ? UnDefType.UNDEF : new DecimalType(lqi);
} }
private State getWiserSignalStrength() { private State getWiserSignalStrength() {
@ -120,7 +123,8 @@ public class TRVHandler extends DraytonWiserThingHandler<SmartValveData> {
} }
private State getBatteryVoltage() { private State getBatteryVoltage() {
return new QuantityType<>(getData().device.getBatteryVoltage() / 10.0, Units.VOLT); final Integer voltage = getData().device.getBatteryVoltage();
return voltage == null ? UnDefType.UNDEF : new QuantityType<>(voltage / 10.0, Units.VOLT);
} }
private State getWiserBatteryLevel() { private State getWiserBatteryLevel() {

View File

@ -88,8 +88,8 @@ public class DeviceDTO {
return displayedSignalStrength; return displayedSignalStrength;
} }
public int getBatteryVoltage() { public Integer getBatteryVoltage() {
return batteryVoltage == null ? Integer.MIN_VALUE : batteryVoltage; return batteryVoltage;
} }
public String getBatteryLevel() { public String getBatteryLevel() {

View File

@ -31,6 +31,8 @@ public class SmartPlugDTO {
private String targetState; private String targetState;
private Integer debounceCount; private Integer debounceCount;
private String overrideState; private String overrideState;
private Integer currentSummationDelivered;
private Integer instantaneousDemand;
public Integer getId() { public Integer getId() {
return id; return id;
@ -75,4 +77,12 @@ public class SmartPlugDTO {
public String getMode() { public String getMode() {
return mode; return mode;
} }
public Integer getCurrentSummationDelivered() {
return currentSummationDelivered;
}
public Integer getInstantaneousDemand() {
return instantaneousDemand;
}
} }

View File

@ -219,6 +219,8 @@
<channel id="zigbeeConnected" typeId="zigbeeConnected-channel"/> <channel id="zigbeeConnected" typeId="zigbeeConnected-channel"/>
<channel id="deviceLocked" typeId="deviceLocked-channel"/> <channel id="deviceLocked" typeId="deviceLocked-channel"/>
<channel id="manualModeState" typeId="manualModeState-channel"/> <channel id="manualModeState" typeId="manualModeState-channel"/>
<channel id="plugInstantaneousPower" typeId="plugInstantaneousPower-channel"/>
<channel id="plugEnergyDelivered" typeId="plugEnergyDelivered-channel"/>
</channels> </channels>
<representation-property>serialNumber</representation-property> <representation-property>serialNumber</representation-property>
@ -429,4 +431,18 @@
<description>Should the room pre-heat to achieve the desired temperature</description> <description>Should the room pre-heat to achieve the desired temperature</description>
</channel-type> </channel-type>
<channel-type id="plugInstantaneousPower-channel">
<item-type>Number:Power</item-type>
<label>Plug Instantaneous Power</label>
<description>Current Power being drawn through the plug</description>
<state readOnly="true" pattern="%d %unit%"/>
</channel-type>
<channel-type id="plugEnergyDelivered-channel">
<item-type>Number:Energy</item-type>
<label>Plug Energy Delivered</label>
<description>Cumulative energy drawn through the plug</description>
<state readOnly="true" pattern="%d %unit%"/>
</channel-type>
</thing:thing-descriptions> </thing:thing-descriptions>