Skip to content

Commit

Permalink
close #29 Downgrade to 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed Jun 3, 2019
1 parent f9c350f commit df4b792
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ public static class Channels {
public static final String HUMIDITY_CHANNEL_ID = "humidity-channel";
public static final String DIMMER_CHANNEL_ID = "dimmer-channel";
public static final String TOGGLE_GAT_CHANNEL_ID = "toggle-gate-channel";
public static final String EXTRA_LIGHT_ACTIONS_CHANNEL_ID = "extra-light-actions-channel";
public static final String UNKNOWN_CHANNEL_ID = "unknown-channel";
}

public static class Commands {
public static final String OPEN_CLOSE_GATE_COMMAND = "open-close";
public static final String WHITE_LIGHT_COMMAND = "light-white";
public static final String OFF_LIGHT_COMMAND = "light-off";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.CONFIGURATION_ERROR;
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.NONE;
import static org.eclipse.smarthome.core.types.RefreshType.REFRESH;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
import static org.openhab.binding.supla.internal.cloud.ChannelFunctionDispatcher.DISPATCHER;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
Expand Down Expand Up @@ -242,8 +238,9 @@ protected void handleOnOffCommand(final ChannelUID channelUID, final OnOffType c
switch (channel.getFunction().getName()) {
case CONTROLLINGTHEGATE:
case CONTROLLINGTHEGARAGEDOOR:
handleOneZeroCommand(channelId, command == ON, OPEN, CLOSE);
return;
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
channelsApi.executeAction(action, channelId);
break;
default:
handleOneZeroCommand(channelId, command == ON, TURN_ON, TURN_OFF);
}
Expand Down Expand Up @@ -361,31 +358,7 @@ private void handleStopMoveTypeCommandOnRollerShutter(

@Override
protected void handleStringCommand(final ChannelUID channelUID, final StringType command) throws ApiException {
final ChannelInfo channelInfo = ChannelInfoParser.PARSER.parse(channelUID);
final int channelId = channelInfo.getChannelId();
final pl.grzeslowski.jsupla.api.generated.model.Channel channel = queryForChannel(channelId);
switch (channel.getFunction().getName()) {
case CONTROLLINGTHEGATE:
case CONTROLLINGTHEGARAGEDOOR:
if (command.toFullString().equals(OPEN_CLOSE_GATE_COMMAND)) {
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
channelsApi.executeAction(action, channelId);
}
break;
case RGBLIGHTING:
case DIMMERANDRGBLIGHTING:
if (EXTRA_LIGHT_ACTIONS.equals(channelInfo.getAdditionalChannelType())) {
final ChannelUID mainLightChannel = new ChannelUID(channelUID.getThingUID(), String.valueOf(channelId));
if (command.toFullString().equals(WHITE_LIGHT_COMMAND)) {
changeColorOfRgb(HSBType.WHITE, mainLightChannel);
} else if (command.toFullString().equals(OFF_LIGHT_COMMAND)) {
changeColorOfRgb(HSBType.BLACK, mainLightChannel);
}
}
break;
default:
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
}
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
}

private void changeColorOfRgb(HSBType hsbType, ChannelUID rgbChannelUid) throws ApiException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand All @@ -20,7 +21,6 @@
import static java.util.Objects.requireNonNull;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DECIMAL_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DIMMER_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.EXTRA_LIGHT_ACTIONS_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.HUMIDITY_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.LIGHT_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.RGB_CHANNEL_ID;
Expand All @@ -29,7 +29,6 @@
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.SWITCH_CHANNEL_RO_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TEMPERATURE_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TOGGLE_GAT_CHANNEL_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.HUMIDITY;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.TEMPERATURE;

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

private List<Channel> createToggleGateChannel(pl.grzeslowski.jsupla.api.generated.model.Channel channel) {
return singletonList(createChannel(channel, TOGGLE_GAT_CHANNEL_ID, "String"));
return singletonList(createChannel(channel, TOGGLE_GAT_CHANNEL_ID, "Switch"));
}

private List<Channel> createLedChannels(final pl.grzeslowski.jsupla.api.generated.model.Channel channel) {
return asList(
createChannel(channel, RGB_CHANNEL_ID, "Color"),
createChannel(EXTRA_LIGHT_ACTIONS_CHANNEL_ID, "String", channel.getId() + EXTRA_LIGHT_ACTIONS.getSuffix(), "Extra Actions"));
return Collections.singletonList(
createChannel(channel, RGB_CHANNEL_ID, "Color"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,8 @@
</channel-type>

<channel-type id="toggle-gate-channel">
<item-type>String</item-type>
<item-type>Switch</item-type>
<label>Open/Close Gate</label>
<command>
<options>
<option value="open-close">Open/Close</option>
</options>
</command>
</channel-type>

<channel-type id="extra-light-actions-channel">
<item-type>String</item-type>
<label>Quick Actions</label>
<command>
<options>
<option value="light-white">Set White</option>
<option value="light-off">Turn OFF</option>
</options>
</command>
</channel-type>

<channel-type id="unknown-channel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
Expand Down Expand Up @@ -69,15 +68,11 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN_CLOSE;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL_PARTIALLY;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.SHUT;
Expand Down Expand Up @@ -435,60 +430,6 @@ void moveRollerShutter() throws Exception {
verify(channelsCloudApi, times(0)).executeAction(channelExecuteActionRequestCaptor.capture(), eq(rollerShutterChannelId));
}

@ParameterizedTest
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
@DisplayName("show send request to Supla CLoud to OPEN/CLOSE gate or garage door")
void openCloseGateAndGarage(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id);

// when
handler.handleStringCommand(channelUID, new StringType(OPEN_CLOSE_GATE_COMMAND));

// then
verify(channelsCloudApi).executeAction(channelExecuteActionRequestCaptor.capture(), eq(id));
ChannelExecuteActionRequest value = channelExecuteActionRequestCaptor.getValue();
assertThat(value.getAction()).isEqualTo(OPEN_CLOSE);
}

@ParameterizedTest
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
@DisplayName("should send request to LedExecutor to change color to white")
void setLightColorToWhite(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
final ChannelUID parentChannelUID = buildChannelUID(id);

// when
handler.handleStringCommand(channelUID, new StringType(WHITE_LIGHT_COMMAND));

// then
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.WHITE);
verify(callback).stateUpdated(parentChannelUID, HSBType.WHITE);
}

@ParameterizedTest
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
@DisplayName("should send request to LedExecutor to change color to black")
void turnOffRgbLights(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
final ChannelUID parentChannelUID = buildChannelUID(id);

// when
handler.handleStringCommand(channelUID, new StringType(OFF_LIGHT_COMMAND));

// then
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.BLACK);
verify(callback).stateUpdated(parentChannelUID, HSBType.BLACK);
}

@ParameterizedTest
@ValueSource(strings = {"lightChannelId", "powerSwitchChannelId"})
@DisplayName("should refresh light and set ON")
Expand Down

0 comments on commit df4b792

Please sign in to comment.