[netatmo] Removed useless class MeasurableChannels (#9136)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>pull/9183/head
parent
1e47d42186
commit
23131b446c
|
@ -287,8 +287,6 @@ public class NetatmoBindingConstants {
|
|||
.concat(SUPPORTED_DEVICE_THING_TYPES_UIDS.stream(), Stream.of(APIBRIDGE_THING_TYPE))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
public static final Set<String> MEASURABLE_CHANNELS = Stream.of(new String[] {}).collect(Collectors.toSet());
|
||||
|
||||
public static final Set<EventTypeEnum> HOME_EVENTS = Stream.of(EventTypeEnum.PERSON_AWAY)
|
||||
.collect(Collectors.toSet());
|
||||
public static final Set<EventTypeEnum> WELCOME_EVENTS = Stream
|
||||
|
|
|
@ -74,7 +74,6 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
|
|||
private final Logger logger = LoggerFactory.getLogger(AbstractNetatmoThingHandler.class);
|
||||
|
||||
protected final TimeZoneProvider timeZoneProvider;
|
||||
protected final MeasurableChannels measurableChannels = new MeasurableChannels();
|
||||
private @Nullable RadioHelper radioHelper;
|
||||
private @Nullable BatteryHelper batteryHelper;
|
||||
protected @Nullable Configuration config;
|
||||
|
@ -133,9 +132,7 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
|
|||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
}
|
||||
result = measurableChannels.getNAThingProperty(channelId);
|
||||
|
||||
return result.orElse(UnDefType.UNDEF);
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
|
||||
protected void updateChannels() {
|
||||
|
@ -177,18 +174,6 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
|
|||
protected void triggerChannelIfRequired(String channelId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelLinked(ChannelUID channelUID) {
|
||||
super.channelLinked(channelUID);
|
||||
measurableChannels.addChannel(channelUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelUnlinked(ChannelUID channelUID) {
|
||||
super.channelUnlinked(channelUID);
|
||||
measurableChannels.removeChannel(channelUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (command == RefreshType.REFRESH) {
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2020 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.netatmo.internal.handler;
|
||||
|
||||
import static org.openhab.binding.netatmo.internal.APIUtils.*;
|
||||
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.MEASURABLE_CHANNELS;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.netatmo.internal.ChannelTypeUtils;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.types.State;
|
||||
|
||||
import io.swagger.client.model.NAMeasureBodyElem;
|
||||
import io.swagger.client.model.NAMeasureResponse;
|
||||
|
||||
/**
|
||||
* {@link MeasurableChannels} is a helper class designed to handle
|
||||
* manipulation of requests and responses provided by calls to
|
||||
* someNetatmoApi.getMeasures(....)
|
||||
*
|
||||
* @author Gaël L'hopital - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class MeasurableChannels {
|
||||
protected @Nullable NAMeasureResponse measures;
|
||||
protected List<String> measuredChannels = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* If this channel value is provided as a measure, then add it
|
||||
* in the getMeasure parameter list
|
||||
*/
|
||||
protected void addChannel(ChannelUID channelUID) {
|
||||
String channel = channelUID.getId();
|
||||
if (MEASURABLE_CHANNELS.contains(channel)) {
|
||||
measuredChannels.add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If this channel value is provided as a measure, then delete
|
||||
* it in the getMeasure parameter list
|
||||
*/
|
||||
protected void removeChannel(ChannelUID channelUID) {
|
||||
String channel = channelUID.getId();
|
||||
measuredChannels.remove(channel);
|
||||
}
|
||||
|
||||
protected Optional<State> getNAThingProperty(String channelId) {
|
||||
int index = measuredChannels.indexOf(channelId);
|
||||
NAMeasureResponse theMeasures = measures;
|
||||
if (index != -1 && theMeasures != null) {
|
||||
List<NAMeasureBodyElem> body = nonNullList(theMeasures.getBody());
|
||||
if (!body.isEmpty()) {
|
||||
List<List<Float>> valueList = nonNullList(body.get(0).getValue());
|
||||
if (!valueList.isEmpty()) {
|
||||
List<Float> values = nonNullList(valueList.get(0));
|
||||
if (values.size() >= index) {
|
||||
Float value = values.get(index);
|
||||
return Optional.of(ChannelTypeUtils.toDecimalType(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<List<String>> getMeasuredChannels() {
|
||||
if (!measuredChannels.isEmpty()) {
|
||||
return Optional.of(measuredChannels);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void setMeasures(NAMeasureResponse measures) {
|
||||
this.measures = measures;
|
||||
}
|
||||
}
|
|
@ -48,7 +48,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.client.api.ThermostatApi;
|
||||
import io.swagger.client.model.NAMeasureResponse;
|
||||
import io.swagger.client.model.NASetpoint;
|
||||
import io.swagger.client.model.NAThermProgram;
|
||||
import io.swagger.client.model.NAThermostat;
|
||||
|
@ -80,18 +79,7 @@ public class NATherm1Handler extends NetatmoModuleHandler<NAThermostat> {
|
|||
|
||||
@Override
|
||||
public void updateChannels(Object moduleObject) {
|
||||
if (isRefreshRequired()) {
|
||||
measurableChannels.getMeasuredChannels().ifPresent(csvParams -> {
|
||||
getApi().ifPresent(api -> {
|
||||
NAMeasureResponse measures = api.getmeasure(getParentId(), "max", csvParams, getId(), null, null, 1,
|
||||
true, true);
|
||||
measurableChannels.setMeasures(measures);
|
||||
});
|
||||
});
|
||||
setRefreshRequired(false);
|
||||
}
|
||||
super.updateChannels(moduleObject);
|
||||
|
||||
getModule().ifPresent(this::updateStateDescription);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue