2 * Copyright (c) 2010-2022 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.wled.internal.api;
15 import static org.openhab.binding.wled.internal.WLedBindingConstants.*;
17 import java.util.ArrayList;
18 import java.util.List;
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;
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.
31 * @author Matthew Skinner - Initial contribution
34 public class WledApiV0130 extends WledApiV0110 {
36 public WledApiV0130(WLedBridgeHandler handler, HttpClient httpClient) {
37 super(handler, httpClient);
41 public void initialize() throws ApiException {
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);
49 channel = handler.getThing().getChannel(CHANNEL_PRESET_CYCLE);
50 if (channel != null) {
51 removeChannels.add(channel);
53 if (!removeChannels.isEmpty()) {
54 handler.removeBridgeChannels(removeChannels);
59 protected void processState(int segmentIndex) throws ApiException {
60 super.processState(segmentIndex);
61 handler.update(CHANNEL_PLAYLISTS, new StringType(Integer.toString(state.stateResponse.pl)));
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);