2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bticinosmarther.internal.api.dto;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherIllegalPropertyValueException;
19 import org.openhab.core.types.State;
20 import org.openhab.core.types.UnDefType;
23 * The {@code Sensor} class defines the dto for Smarther API sensor object.
25 * @author Fabio Possieri - Initial contribution
29 private List<Measure> measures;
32 * Returns the list of measures this sensor takes.
34 * @return the measures this sensor takes, may be {@code null}
36 public @Nullable List<Measure> getMeasures() {
41 * Returns the measure taken by this sensor at the given index.
44 * the index to get the measure for
46 * @return the requested measure, or {@code null} in case of no measure found at given index
48 public @Nullable Measure getMeasure(int index) {
49 return (measures != null && measures.size() > index) ? measures.get(index) : null;
53 * Returns the overall state of the sensor.
55 * @return a {@link State} object representing the overall state of the sensor
57 * @throws SmartherIllegalPropertyValueException if the sensor internal raw state cannot be mapped to any valid
60 public State toState() throws SmartherIllegalPropertyValueException {
61 final Measure measure = getMeasure(0);
62 return (measure != null) ? measure.toState() : UnDefType.UNDEF;
66 public String toString() {
67 return String.format("measures=%s", measures);