]> git.basschouten.com Git - openhab-addons.git/blob
5d0a1378453008ea9a403e85c5601bedaf80ba18
[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
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jetty.client.HttpClient;
21 import org.openhab.binding.wled.internal.WLedHandler;
22 import org.openhab.core.library.types.StringType;
23 import org.openhab.core.thing.Channel;
24
25 /**
26  * The {@link WledApiV0130} is the json Api methods for firmware version 0.13.0 and newer
27  * as newer firmwares come out with breaking changes, extend this class into a newer firmware version class.
28  *
29  * @author Matthew Skinner - Initial contribution
30  */
31 @NonNullByDefault
32 public class WledApiV0130 extends WledApiV0110 {
33
34     public WledApiV0130(WLedHandler handler, HttpClient httpClient) {
35         super(handler, httpClient);
36     }
37
38     @Override
39     public void initialize() throws ApiException {
40         super.initialize();
41         ArrayList<Channel> removeChannels = new ArrayList<>();
42         // This version of firmware removed these channels
43         Channel channel = handler.getThing().getChannel(CHANNEL_PRESET_DURATION);
44         if (channel != null) {
45             removeChannels.add(channel);
46         }
47         channel = handler.getThing().getChannel(CHANNEL_PRESET_CYCLE);
48         if (channel != null) {
49             removeChannels.add(channel);
50         }
51         handler.removeChannels(removeChannels);
52     }
53
54     @Override
55     protected void processState() throws ApiException {
56         super.processState();
57         handler.update(CHANNEL_PLAYLISTS, new StringType(Integer.toString(state.stateResponse.pl)));
58     }
59 }