]> git.basschouten.com Git - openhab-addons.git/blob
84c2d1e81e58a943e87d247502287be46c1d82a4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.loxone.internal.controls;
14
15 import static org.openhab.binding.loxone.internal.LxBindingConstants.*;
16
17 import org.openhab.binding.loxone.internal.types.LxCategory;
18 import org.openhab.binding.loxone.internal.types.LxTags;
19 import org.openhab.binding.loxone.internal.types.LxUuid;
20 import org.openhab.core.thing.ChannelUID;
21 import org.openhab.core.thing.type.ChannelTypeUID;
22 import org.openhab.core.types.StateDescriptionFragmentBuilder;
23
24 /**
25  * An InfoOnlyAnalog type of control on Loxone Miniserver.
26  * <p>
27  * According to Loxone API documentation, this control covers analog virtual states only. This control does not send any
28  * commands to the Miniserver. It can be used to read a formatted representation of an analog virtual state.
29  *
30  * @author Pawel Pieczul - initial contribution
31  *
32  */
33 class LxControlInfoOnlyAnalog extends LxControl {
34
35     static class Factory extends LxControlInstance {
36         @Override
37         LxControl create(LxUuid uuid) {
38             return new LxControlInfoOnlyAnalog(uuid);
39         }
40
41         @Override
42         String getType() {
43             return "infoonlyanalog";
44         }
45     }
46
47     /**
48      * InfoOnlyAnalog state with current value
49      */
50     private static final String STATE_VALUE = "value";
51
52     private LxControlInfoOnlyAnalog(LxUuid uuid) {
53         super(uuid);
54     }
55
56     @Override
57     public void initialize(LxControlConfig config) {
58         super.initialize(config);
59         LxCategory category = getCategory();
60         if (category != null && category.getType() == LxCategory.CategoryType.TEMPERATURE) {
61             tags.addAll(LxTags.TEMPERATURE);
62         }
63         ChannelUID cid = addChannel("Number", new ChannelTypeUID(BINDING_ID, MINISERVER_CHANNEL_TYPE_RO_ANALOG),
64                 defaultChannelLabel, "Analog virtual state", tags, null, () -> getStateDecimalValue(STATE_VALUE));
65         String format;
66         if (details != null && details.format != null) {
67             format = details.format;
68         } else {
69             format = "%.1f";
70         }
71         addChannelStateDescriptionFragment(cid,
72                 StateDescriptionFragmentBuilder.create().withPattern(format).withReadOnly(true).build());
73     }
74 }