]> git.basschouten.com Git - openhab-addons.git/blob
74daca7cb064719329bef223f108c768f82ea8a6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.wled.internal.api;
14
15 import static org.openhab.binding.wled.internal.WLedBindingConstants.*;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.openhab.binding.wled.internal.WledState.SegmentState;
23 import org.openhab.binding.wled.internal.handlers.WLedBridgeHandler;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.thing.Channel;
26
27 /**
28  * The {@link WledApiV0130} is the json Api methods for firmware version 0.13.0 and newer
29  * as newer firmwares come out with breaking changes, extend this class into a newer firmware version class.
30  *
31  * @author Matthew Skinner - Initial contribution
32  */
33 @NonNullByDefault
34 public class WledApiV0130 extends WledApiV0110 {
35
36     public WledApiV0130(WLedBridgeHandler handler, HttpClient httpClient) {
37         super(handler, httpClient);
38     }
39
40     @Override
41     public void initialize() throws ApiException {
42         super.initialize();
43         ArrayList<Channel> removeChannels = new ArrayList<>();
44         // This version of firmware removed these channels
45         Channel channel = handler.getThing().getChannel(CHANNEL_PRESET_DURATION);
46         if (channel != null) {
47             removeChannels.add(channel);
48         }
49         channel = handler.getThing().getChannel(CHANNEL_PRESET_CYCLE);
50         if (channel != null) {
51             removeChannels.add(channel);
52         }
53         if (!removeChannels.isEmpty()) {
54             handler.removeBridgeChannels(removeChannels);
55         }
56     }
57
58     @Override
59     protected void processState(int segmentIndex) throws ApiException {
60         super.processState(segmentIndex);
61         handler.update(CHANNEL_PLAYLISTS, new StringType(Integer.toString(state.stateResponse.pl)));
62     }
63
64     @Override
65     public List<String> getSegmentNames() {
66         // segment names was only first added in 0.13.0 firmware
67         List<String> segmentNames = new ArrayList<>(state.stateResponse.seg.length);
68         for (SegmentState state : state.stateResponse.seg) {
69             segmentNames.add(state.n);
70         }
71         return segmentNames;
72     }
73 }