[jeelink] adapt to core StringUtils (#15771)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
5395de2548
commit
e9431a55bd
|
@ -20,13 +20,13 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler;
|
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler;
|
||||||
import org.openhab.binding.jeelink.internal.ReadingPublisher;
|
import org.openhab.binding.jeelink.internal.ReadingPublisher;
|
||||||
import org.openhab.binding.jeelink.internal.RollingAveragePublisher;
|
import org.openhab.binding.jeelink.internal.RollingAveragePublisher;
|
||||||
import org.openhab.binding.jeelink.internal.RollingReadingAverage;
|
import org.openhab.binding.jeelink.internal.RollingReadingAverage;
|
||||||
import org.openhab.binding.jeelink.internal.config.LaCrosseTemperatureSensorConfig;
|
import org.openhab.binding.jeelink.internal.config.LaCrosseTemperatureSensorConfig;
|
||||||
import org.openhab.binding.jeelink.internal.util.StringUtils;
|
|
||||||
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.types.QuantityType;
|
||||||
import org.openhab.core.library.unit.SIUnits;
|
import org.openhab.core.library.unit.SIUnits;
|
||||||
|
@ -38,6 +38,7 @@ import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||||
|
import org.openhab.core.util.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -93,7 +94,8 @@ public class LaCrosseTemperatureSensorHandler extends JeeLinkSensorHandler<LaCro
|
||||||
missingChannels.add(ChannelBuilder
|
missingChannels.add(ChannelBuilder
|
||||||
.create(new ChannelUID(getThing().getUID(), channelName + idSuffix), "Number")
|
.create(new ChannelUID(getThing().getUID(), channelName + idSuffix), "Number")
|
||||||
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), channelName))
|
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), channelName))
|
||||||
.withLabel(StringUtils.capitalize(channelName + labelSuffix)).build());
|
.withLabel(Objects.requireNonNull(StringUtils.capitalize(channelName + labelSuffix)))
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
missingChannels.addAll(getThing().getChannels());
|
missingChannels.addAll(getThing().getChannels());
|
||||||
|
|
|
@ -17,11 +17,11 @@ import static org.openhab.core.library.unit.MetricPrefix.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler;
|
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler;
|
||||||
import org.openhab.binding.jeelink.internal.ReadingPublisher;
|
import org.openhab.binding.jeelink.internal.ReadingPublisher;
|
||||||
import org.openhab.binding.jeelink.internal.util.StringUtils;
|
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.unit.SIUnits;
|
import org.openhab.core.library.unit.SIUnits;
|
||||||
import org.openhab.core.library.unit.Units;
|
import org.openhab.core.library.unit.Units;
|
||||||
|
@ -31,6 +31,7 @@ import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||||
|
import org.openhab.core.util.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -78,7 +79,8 @@ public class LgwSensorHandler extends JeeLinkSensorHandler<LgwReading> {
|
||||||
.create(new ChannelUID(getThing().getUID(), HUMIDITY_CHANNEL), "Number:Humidity")
|
.create(new ChannelUID(getThing().getUID(), HUMIDITY_CHANNEL), "Number:Humidity")
|
||||||
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(),
|
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(),
|
||||||
HUMIDITY_CHANNEL))
|
HUMIDITY_CHANNEL))
|
||||||
.withLabel(StringUtils.capitalize(HUMIDITY_CHANNEL)).build());
|
.withLabel(Objects.requireNonNull(StringUtils.capitalize(HUMIDITY_CHANNEL)))
|
||||||
|
.build());
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
|
|
||||||
hasHumidityChannel = true;
|
hasHumidityChannel = true;
|
||||||
|
@ -94,7 +96,8 @@ public class LgwSensorHandler extends JeeLinkSensorHandler<LgwReading> {
|
||||||
.create(new ChannelUID(getThing().getUID(), PRESSURE_CHANNEL), "Number:Pressure")
|
.create(new ChannelUID(getThing().getUID(), PRESSURE_CHANNEL), "Number:Pressure")
|
||||||
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(),
|
.withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(),
|
||||||
PRESSURE_CHANNEL))
|
PRESSURE_CHANNEL))
|
||||||
.withLabel(StringUtils.capitalize(PRESSURE_CHANNEL)).build());
|
.withLabel(Objects.requireNonNull(StringUtils.capitalize(PRESSURE_CHANNEL)))
|
||||||
|
.build());
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
|
|
||||||
hasPressureChannel = true;
|
hasPressureChannel = true;
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2010-2023 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.jeelink.internal.util;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for strings
|
|
||||||
*
|
|
||||||
* @author Leo Siepel - Initial contribution
|
|
||||||
*/
|
|
||||||
@NonNullByDefault
|
|
||||||
public final class StringUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Capitalizes a String changing the first character to title case.
|
|
||||||
* No other characters are changed.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* StringUtils.capitalize(null) = null
|
|
||||||
* StringUtils.capitalize("") = ""
|
|
||||||
* StringUtils.capitalize("cat") = "Cat"
|
|
||||||
* StringUtils.capitalize("cAt") = "CAt"
|
|
||||||
* StringUtils.capitalize("'cat'") = "'cat'"
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param val the String to capitalize, may not be null
|
|
||||||
* @return the capitalized String
|
|
||||||
*/
|
|
||||||
public static String capitalize(String val) {
|
|
||||||
if (val.length() == 0) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return val.substring(0, 1).toUpperCase() + val.substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue