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;
if (result.isPresent()) {
return result.get();
}
- result = measurableChannels.getNAThingProperty(channelId);
-
- return result.orElse(UnDefType.UNDEF);
+ return UnDefType.UNDEF;
}
protected void updateChannels() {
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) {
+++ /dev/null
-/**
- * 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;
- }
-}
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;
@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);
}