[networkupstools] Some sat improvements (#10017)
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
committed by
GitHub
parent
c4a3b1e6ba
commit
ff9454596e
@@ -14,17 +14,10 @@ package org.openhab.binding.networkupstools.internal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.measure.Unit;
|
||||
import javax.measure.quantity.Power;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||
|
||||
import tec.uom.se.format.SimpleUnitFormat;
|
||||
import tec.uom.se.unit.ProductUnit;
|
||||
|
||||
/**
|
||||
* The {@link NUTBindingConstants} class defines common constants, which are
|
||||
* used across the whole binding.
|
||||
@@ -46,14 +39,6 @@ public class NUTBindingConstants {
|
||||
public static final URI DYNAMIC_CHANNEL_CONFIG_QUANTITY_TYPE = URI
|
||||
.create("channel-type:ups:dynamic-channel-config-quantity-type");
|
||||
|
||||
public static final Unit<Power> AMPERE_PER_HOUR = new ProductUnit<>(Units.AMPERE.divide(Units.HOUR));
|
||||
public static final Unit<Power> VOLT_AMPERE = new ProductUnit<>(Units.VOLT.multiply(Units.AMPERE));
|
||||
|
||||
static {
|
||||
SimpleUnitFormat.getInstance().label(AMPERE_PER_HOUR, "Ah");
|
||||
SimpleUnitFormat.getInstance().label(VOLT_AMPERE, "VA");
|
||||
}
|
||||
|
||||
private static final String PARAMETER_PREFIX_UPS = "ups.";
|
||||
|
||||
/**
|
||||
@@ -71,7 +56,7 @@ public class NUTBindingConstants {
|
||||
|
||||
private final String nutName;
|
||||
|
||||
private Parameters(final String nutName) {
|
||||
Parameters(final String nutName) {
|
||||
this.nutName = nutName;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class NUTDynamicChannelFactory {
|
||||
|
||||
private final NUTChannelTypeProvider channelTypeProvider;
|
||||
|
||||
public NUTDynamicChannelFactory(final NUTChannelTypeProvider channelTypeProvider) {
|
||||
NUTDynamicChannelFactory(final NUTChannelTypeProvider channelTypeProvider) {
|
||||
this.channelTypeProvider = channelTypeProvider;
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ public class NUTHandler extends BaseThingHandler {
|
||||
* @param nutApiFunction function that will be called
|
||||
* @return the value returned by the api call or null in case of an error
|
||||
*/
|
||||
private <T> T wrappedNutApiCall(final NutFunction<String, T> nutApiFunction, String logging) {
|
||||
private @Nullable <T> T wrappedNutApiCall(final NutFunction<String, T> nutApiFunction, String logging) {
|
||||
try {
|
||||
final NUTConfiguration localConfig = config;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import javax.measure.Unit;
|
||||
|
||||
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.PercentType;
|
||||
@@ -35,11 +36,12 @@ import org.openhab.core.types.UnDefType;
|
||||
* @author Hilbrand Bouwkamp - Initial contribution
|
||||
* @see https://github.com/networkupstools/nut/blob/master/docs/nut-names.txt
|
||||
*/
|
||||
@NonNullByDefault
|
||||
enum NutName {
|
||||
// UPS
|
||||
UPS_ALARM("upsAlarm", "ups.alarm", StringType.class),
|
||||
UPS_LOAD("upsLoad", "ups.load", Units.PERCENT),
|
||||
UPS_POWER("upsPower", "ups.power", NUTBindingConstants.VOLT_AMPERE),
|
||||
UPS_POWER("upsPower", "ups.power", Units.VOLT_AMPERE),
|
||||
UPS_REALPOWER("upsRealpower", "ups.realpower", Units.WATT),
|
||||
UPS_STATUS("upsStatus", "ups.status", StringType.class),
|
||||
UPS_TEMPERATURE("upsTemperature", "ups.temperature", SIUnits.CELSIUS),
|
||||
@@ -64,13 +66,14 @@ enum NutName {
|
||||
BATTERY_RUNTIME("batteryRuntime", "battery.runtime", Units.SECOND),
|
||||
BATTERY_VOLTAGE("batteryVoltage", "battery.voltage", Units.VOLT);
|
||||
|
||||
private static final Map<String, NutName> NUT_NAME_MAP = Stream.of(NutName.values())
|
||||
static final Map<String, NutName> NUT_NAME_MAP = Stream.of(NutName.values())
|
||||
.collect(Collectors.toMap(NutName::getChannelId, Function.identity()));
|
||||
|
||||
private final String channelId;
|
||||
private final String name;
|
||||
private final Class<? extends State> stateClass;
|
||||
private final Unit<?> unit;
|
||||
// unit only as a value if using a QuantityType.
|
||||
private final @NonNullByDefault({}) Unit<?> unit;
|
||||
|
||||
NutName(final String channelId, final String name, final Class<? extends State> stateClass) {
|
||||
this(channelId, name, stateClass, null);
|
||||
@@ -80,7 +83,8 @@ enum NutName {
|
||||
this(channelId, name, QuantityType.class, unit);
|
||||
}
|
||||
|
||||
NutName(final String channelId, final String name, final Class<? extends State> stateClass, final Unit<?> unit) {
|
||||
NutName(final String channelId, final String name, final Class<? extends State> stateClass,
|
||||
final @Nullable Unit<?> unit) {
|
||||
this.channelId = channelId;
|
||||
this.name = name;
|
||||
this.stateClass = stateClass;
|
||||
|
||||
@@ -57,7 +57,7 @@ class NutConnector {
|
||||
* @param username username
|
||||
* @param password password
|
||||
*/
|
||||
public NutConnector(final String host, final int port, final String username, final String password) {
|
||||
NutConnector(final String host, final int port, final String username, final String password) {
|
||||
this.login = username.isEmpty() ? "" : String.format(USERNAME, username);
|
||||
this.password = password.isEmpty() ? "" : String.format(PASSWORD, password);
|
||||
inetSocketAddress = new InetSocketAddress(host, port);
|
||||
@@ -73,8 +73,8 @@ class NutConnector {
|
||||
* @return the data read from the NUT server
|
||||
* @throws NutException Exception thrown related to the NUT server connection and/or data.
|
||||
*/
|
||||
public synchronized <R> R read(final String command, final NutFunction<NutSupplier<String>, R> readFunction)
|
||||
throws NutException {
|
||||
public synchronized <R> R read(final String command,
|
||||
final NutFunction<NutSupplier<String>, @Nullable R> readFunction) throws NutException {
|
||||
int retry = 0;
|
||||
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user