[homeconnect] Factorize handling of power command (#10747)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
19029b7358
commit
fe11c115ea
@ -1172,6 +1172,14 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handlePowerCommand(final ChannelUID channelUID, final Command command,
|
||||||
|
final HomeConnectApiClient apiClient, String stateNotOn)
|
||||||
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
|
if (command instanceof OnOffType && CHANNEL_POWER_STATE.equals(channelUID.getId())) {
|
||||||
|
apiClient.setPowerState(getThingHaId(), OnOffType.ON.equals(command) ? STATE_POWER_ON : stateNotOn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int getCurrentBrightness(final ChannelUID channelUID, final HomeConnectApiClient apiClient)
|
private int getCurrentBrightness(final ChannelUID channelUID, final HomeConnectApiClient apiClient)
|
||||||
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
String id = channelUID.getId();
|
String id = channelUID.getId();
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflin
|
|||||||
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
|
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
|
||||||
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
|
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
|
||||||
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
@ -87,10 +86,7 @@ public class HomeConnectCoffeeMakerHandler extends AbstractHomeConnectThingHandl
|
|||||||
super.handleCommand(channelUID, command, apiClient);
|
super.handleCommand(channelUID, command, apiClient);
|
||||||
|
|
||||||
// turn coffee maker on and standby
|
// turn coffee maker on and standby
|
||||||
if (command instanceof OnOffType && CHANNEL_POWER_STATE.equals(channelUID.getId())) {
|
handlePowerCommand(channelUID, command, apiClient, STATE_POWER_STANDBY);
|
||||||
apiClient.setPowerState(getThingHaId(),
|
|
||||||
OnOffType.ON.equals(command) ? STATE_POWER_ON : STATE_POWER_STANDBY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -17,8 +17,14 @@ import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstan
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient;
|
||||||
|
import org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflineException;
|
||||||
|
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
|
||||||
|
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
|
||||||
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
||||||
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,6 +72,15 @@ public class HomeConnectCooktopHandler extends AbstractHomeConnectThingHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleCommand(final ChannelUID channelUID, final Command command,
|
||||||
|
final HomeConnectApiClient apiClient)
|
||||||
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
|
super.handleCommand(channelUID, command, apiClient);
|
||||||
|
|
||||||
|
handlePowerCommand(channelUID, command, apiClient, STATE_POWER_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "HomeConnectCooktopHandler [haId: " + getThingHaId() + "]";
|
return "HomeConnectCooktopHandler [haId: " + getThingHaId() + "]";
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflin
|
|||||||
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
|
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
|
||||||
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
|
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
|
||||||
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
@ -81,12 +80,7 @@ public class HomeConnectDishwasherHandler extends AbstractHomeConnectThingHandle
|
|||||||
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
super.handleCommand(channelUID, command, apiClient);
|
super.handleCommand(channelUID, command, apiClient);
|
||||||
|
|
||||||
if (command instanceof OnOffType) {
|
handlePowerCommand(channelUID, command, apiClient, STATE_POWER_OFF);
|
||||||
if (CHANNEL_POWER_STATE.equals(channelUID.getId())) {
|
|
||||||
apiClient.setPowerState(getThingHaId(),
|
|
||||||
OnOffType.ON.equals(command) ? STATE_POWER_ON : STATE_POWER_OFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleLightCommands(channelUID, command, apiClient);
|
handleLightCommands(channelUID, command, apiClient);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,12 +145,7 @@ public class HomeConnectHoodHandler extends AbstractHomeConnectThingHandler {
|
|||||||
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
super.handleCommand(channelUID, command, apiClient);
|
super.handleCommand(channelUID, command, apiClient);
|
||||||
|
|
||||||
if (command instanceof OnOffType) {
|
handlePowerCommand(channelUID, command, apiClient, STATE_POWER_OFF);
|
||||||
if (CHANNEL_POWER_STATE.equals(channelUID.getId())) {
|
|
||||||
apiClient.setPowerState(getThingHaId(),
|
|
||||||
OnOffType.ON.equals(command) ? STATE_POWER_ON : STATE_POWER_OFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// light commands
|
// light commands
|
||||||
handleLightCommands(channelUID, command, apiClient);
|
handleLightCommands(channelUID, command, apiClient);
|
||||||
|
|||||||
@ -159,11 +159,7 @@ public class HomeConnectOvenHandler extends AbstractHomeConnectThingHandler {
|
|||||||
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
super.handleCommand(channelUID, command, apiClient);
|
super.handleCommand(channelUID, command, apiClient);
|
||||||
|
|
||||||
// turn coffee maker on and standby
|
handlePowerCommand(channelUID, command, apiClient, STATE_POWER_STANDBY);
|
||||||
if (command instanceof OnOffType && CHANNEL_POWER_STATE.equals(channelUID.getId())) {
|
|
||||||
apiClient.setPowerState(getThingHaId(),
|
|
||||||
OnOffType.ON.equals(command) ? STATE_POWER_ON : STATE_POWER_STANDBY);
|
|
||||||
}
|
|
||||||
|
|
||||||
String operationState = getOperationState();
|
String operationState = getOperationState();
|
||||||
if (operationState != null && INACTIVE_STATE.contains(operationState) && command instanceof QuantityType) {
|
if (operationState != null && INACTIVE_STATE.contains(operationState) && command instanceof QuantityType) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user