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.tradfri.internal.model;
15 import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.library.types.PercentType;
21 import com.google.gson.JsonElement;
22 import com.google.gson.JsonPrimitive;
25 * The {@link TradfriBlindData} class is a Java wrapper for the raw JSON data about the blinds state.
27 * @author Manuel Raffel - Initial contribution
30 public class TradfriBlindData extends TradfriWirelessDeviceData {
31 public TradfriBlindData() {
35 public TradfriBlindData(JsonElement json) {
39 public TradfriBlindData setPosition(PercentType position) {
40 attributes.add(POSITION, new JsonPrimitive(position.intValue()));
44 public TradfriBlindData stop() {
45 attributes.add(STOP_TRIGGER, new JsonPrimitive(0));
49 public @Nullable PercentType getPosition() {
50 PercentType result = null;
52 JsonElement position = attributes.get(POSITION);
53 if (position != null) {
54 int percent = position.getAsInt();
55 percent = Math.max(percent, 0);
56 percent = Math.min(100, percent);
57 result = new PercentType(percent);
63 public String getJsonString() {
64 return root.toString();