Skip to content

Commit df4b792

Browse files
committed
close #29 Downgrade to 2.4
1 parent f9c350f commit df4b792

File tree

5 files changed

+9
-120
lines changed

5 files changed

+9
-120
lines changed

Diff for: bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/SuplaBindingConstants.java

-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ public static class Channels {
6969
public static final String HUMIDITY_CHANNEL_ID = "humidity-channel";
7070
public static final String DIMMER_CHANNEL_ID = "dimmer-channel";
7171
public static final String TOGGLE_GAT_CHANNEL_ID = "toggle-gate-channel";
72-
public static final String EXTRA_LIGHT_ACTIONS_CHANNEL_ID = "extra-light-actions-channel";
7372
public static final String UNKNOWN_CHANNEL_ID = "unknown-channel";
7473
}
75-
76-
public static class Commands {
77-
public static final String OPEN_CLOSE_GATE_COMMAND = "open-close";
78-
public static final String WHITE_LIGHT_COMMAND = "light-white";
79-
public static final String OFF_LIGHT_COMMAND = "light-off";
80-
}
8174
}

Diff for: bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/CloudDeviceHandler.java

+4-31
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@
5454
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.CONFIGURATION_ERROR;
5555
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.NONE;
5656
import static org.eclipse.smarthome.core.types.RefreshType.REFRESH;
57-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
58-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
59-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
6057
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
61-
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
6258
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
6359
import static org.openhab.binding.supla.internal.cloud.ChannelFunctionDispatcher.DISPATCHER;
6460
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
@@ -242,8 +238,9 @@ protected void handleOnOffCommand(final ChannelUID channelUID, final OnOffType c
242238
switch (channel.getFunction().getName()) {
243239
case CONTROLLINGTHEGATE:
244240
case CONTROLLINGTHEGARAGEDOOR:
245-
handleOneZeroCommand(channelId, command == ON, OPEN, CLOSE);
246-
return;
241+
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
242+
channelsApi.executeAction(action, channelId);
243+
break;
247244
default:
248245
handleOneZeroCommand(channelId, command == ON, TURN_ON, TURN_OFF);
249246
}
@@ -361,31 +358,7 @@ private void handleStopMoveTypeCommandOnRollerShutter(
361358

362359
@Override
363360
protected void handleStringCommand(final ChannelUID channelUID, final StringType command) throws ApiException {
364-
final ChannelInfo channelInfo = ChannelInfoParser.PARSER.parse(channelUID);
365-
final int channelId = channelInfo.getChannelId();
366-
final pl.grzeslowski.jsupla.api.generated.model.Channel channel = queryForChannel(channelId);
367-
switch (channel.getFunction().getName()) {
368-
case CONTROLLINGTHEGATE:
369-
case CONTROLLINGTHEGARAGEDOOR:
370-
if (command.toFullString().equals(OPEN_CLOSE_GATE_COMMAND)) {
371-
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
372-
channelsApi.executeAction(action, channelId);
373-
}
374-
break;
375-
case RGBLIGHTING:
376-
case DIMMERANDRGBLIGHTING:
377-
if (EXTRA_LIGHT_ACTIONS.equals(channelInfo.getAdditionalChannelType())) {
378-
final ChannelUID mainLightChannel = new ChannelUID(channelUID.getThingUID(), String.valueOf(channelId));
379-
if (command.toFullString().equals(WHITE_LIGHT_COMMAND)) {
380-
changeColorOfRgb(HSBType.WHITE, mainLightChannel);
381-
} else if (command.toFullString().equals(OFF_LIGHT_COMMAND)) {
382-
changeColorOfRgb(HSBType.BLACK, mainLightChannel);
383-
}
384-
}
385-
break;
386-
default:
387-
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
388-
}
361+
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
389362
}
390363

391364
private void changeColorOfRgb(HSBType hsbType, ChannelUID rgbChannelUid) throws ApiException {

Diff for: bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/functionswitch/CreateChannelFunctionSwitch.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.LoggerFactory;
1212

1313
import java.util.ArrayList;
14+
import java.util.Collections;
1415
import java.util.List;
1516

1617
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -20,7 +21,6 @@
2021
import static java.util.Objects.requireNonNull;
2122
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DECIMAL_CHANNEL_ID;
2223
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DIMMER_CHANNEL_ID;
23-
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.EXTRA_LIGHT_ACTIONS_CHANNEL_ID;
2424
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.HUMIDITY_CHANNEL_ID;
2525
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.LIGHT_CHANNEL_ID;
2626
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.RGB_CHANNEL_ID;
@@ -29,7 +29,6 @@
2929
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.SWITCH_CHANNEL_RO_ID;
3030
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TEMPERATURE_CHANNEL_ID;
3131
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TOGGLE_GAT_CHANNEL_ID;
32-
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
3332
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.HUMIDITY;
3433
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.TEMPERATURE;
3534

@@ -238,12 +237,11 @@ private List<Channel> createSwitchChannel(pl.grzeslowski.jsupla.api.generated.mo
238237
}
239238

240239
private List<Channel> createToggleGateChannel(pl.grzeslowski.jsupla.api.generated.model.Channel channel) {
241-
return singletonList(createChannel(channel, TOGGLE_GAT_CHANNEL_ID, "String"));
240+
return singletonList(createChannel(channel, TOGGLE_GAT_CHANNEL_ID, "Switch"));
242241
}
243242

244243
private List<Channel> createLedChannels(final pl.grzeslowski.jsupla.api.generated.model.Channel channel) {
245-
return asList(
246-
createChannel(channel, RGB_CHANNEL_ID, "Color"),
247-
createChannel(EXTRA_LIGHT_ACTIONS_CHANNEL_ID, "String", channel.getId() + EXTRA_LIGHT_ACTIONS.getSuffix(), "Extra Actions"));
244+
return Collections.singletonList(
245+
createChannel(channel, RGB_CHANNEL_ID, "Color"));
248246
}
249247
}

Diff for: bundles/org.openhab.binding.supla/src/main/resources/ESH-INF/thing/thing-types.xml

+1-17
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,8 @@
9292
</channel-type>
9393

9494
<channel-type id="toggle-gate-channel">
95-
<item-type>String</item-type>
95+
<item-type>Switch</item-type>
9696
<label>Open/Close Gate</label>
97-
<command>
98-
<options>
99-
<option value="open-close">Open/Close</option>
100-
</options>
101-
</command>
102-
</channel-type>
103-
104-
<channel-type id="extra-light-actions-channel">
105-
<item-type>String</item-type>
106-
<label>Quick Actions</label>
107-
<command>
108-
<options>
109-
<option value="light-white">Set White</option>
110-
<option value="light-off">Turn OFF</option>
111-
</options>
112-
</command>
11397
</channel-type>
11498

11599
<channel-type id="unknown-channel">

Diff for: bundles/org.openhab.binding.supla/src/test/java/org/openhab/binding/supla/handler/CloudDeviceHandlerTest.java

-59
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.eclipse.smarthome.core.library.types.OpenClosedType;
1010
import org.eclipse.smarthome.core.library.types.PercentType;
1111
import org.eclipse.smarthome.core.library.types.StopMoveType;
12-
import org.eclipse.smarthome.core.library.types.StringType;
1312
import org.eclipse.smarthome.core.library.types.UpDownType;
1413
import org.eclipse.smarthome.core.thing.Bridge;
1514
import org.eclipse.smarthome.core.thing.ChannelUID;
@@ -69,15 +68,11 @@
6968
import static org.mockito.Mockito.doAnswer;
7069
import static org.mockito.Mockito.times;
7170
import static org.mockito.Mockito.verify;
72-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
73-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
74-
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
7571
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
7672
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
7773
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
7874
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
7975
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN;
80-
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN_CLOSE;
8176
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL;
8277
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL_PARTIALLY;
8378
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.SHUT;
@@ -435,60 +430,6 @@ void moveRollerShutter() throws Exception {
435430
verify(channelsCloudApi, times(0)).executeAction(channelExecuteActionRequestCaptor.capture(), eq(rollerShutterChannelId));
436431
}
437432

438-
@ParameterizedTest
439-
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
440-
@DisplayName("show send request to Supla CLoud to OPEN/CLOSE gate or garage door")
441-
void openCloseGateAndGarage(String idFieldName) throws Exception {
442-
443-
// given
444-
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
445-
final ChannelUID channelUID = buildChannelUID(id);
446-
447-
// when
448-
handler.handleStringCommand(channelUID, new StringType(OPEN_CLOSE_GATE_COMMAND));
449-
450-
// then
451-
verify(channelsCloudApi).executeAction(channelExecuteActionRequestCaptor.capture(), eq(id));
452-
ChannelExecuteActionRequest value = channelExecuteActionRequestCaptor.getValue();
453-
assertThat(value.getAction()).isEqualTo(OPEN_CLOSE);
454-
}
455-
456-
@ParameterizedTest
457-
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
458-
@DisplayName("should send request to LedExecutor to change color to white")
459-
void setLightColorToWhite(String idFieldName) throws Exception {
460-
461-
// given
462-
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
463-
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
464-
final ChannelUID parentChannelUID = buildChannelUID(id);
465-
466-
// when
467-
handler.handleStringCommand(channelUID, new StringType(WHITE_LIGHT_COMMAND));
468-
469-
// then
470-
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.WHITE);
471-
verify(callback).stateUpdated(parentChannelUID, HSBType.WHITE);
472-
}
473-
474-
@ParameterizedTest
475-
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
476-
@DisplayName("should send request to LedExecutor to change color to black")
477-
void turnOffRgbLights(String idFieldName) throws Exception {
478-
479-
// given
480-
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
481-
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
482-
final ChannelUID parentChannelUID = buildChannelUID(id);
483-
484-
// when
485-
handler.handleStringCommand(channelUID, new StringType(OFF_LIGHT_COMMAND));
486-
487-
// then
488-
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.BLACK);
489-
verify(callback).stateUpdated(parentChannelUID, HSBType.BLACK);
490-
}
491-
492433
@ParameterizedTest
493434
@ValueSource(strings = {"lightChannelId", "powerSwitchChannelId"})
494435
@DisplayName("should refresh light and set ON")

0 commit comments

Comments
 (0)