mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[gardena] Fix close all valves command (#15390)
* Fix #15039 * codestyle Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
1fd7280c51
commit
6ace1548b8
@ -199,8 +199,8 @@ public class GardenaSmartImpl implements GardenaSmart, GardenaSmartWebSocketList
|
||||
AbstractTypedContentProvider contentProvider = null;
|
||||
String contentType = "application/vnd.api+json";
|
||||
if (content != null) {
|
||||
if (content instanceof Fields) {
|
||||
contentProvider = new FormContentProvider((Fields) content);
|
||||
if (content instanceof Fields contentAsFields) {
|
||||
contentProvider = new FormContentProvider(contentAsFields);
|
||||
contentType = "application/x-www-form-urlencoded";
|
||||
} else {
|
||||
contentProvider = new StringContentProvider(gson.toJson(content));
|
||||
|
@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class GardenaSmartWebSocket {
|
||||
private final Logger logger = LoggerFactory.getLogger(GardenaSmartWebSocket.class);
|
||||
private final GardenaSmartWebSocketListener socketEventListener;
|
||||
private final int MAX_UNANSWERED_PINGS = 5;
|
||||
private static final int MAX_UNANSWERED_PINGS = 5;
|
||||
|
||||
private WebSocketSession session;
|
||||
private WebSocketClient webSocketClient;
|
||||
|
@ -62,8 +62,8 @@ public class GardenaDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof GardenaAccountHandler) {
|
||||
this.accountHandler = (GardenaAccountHandler) handler;
|
||||
if (handler instanceof GardenaAccountHandler gardenaAccountHandler) {
|
||||
this.accountHandler = gardenaAccountHandler;
|
||||
this.accountHandler.setDiscoveryService(this);
|
||||
}
|
||||
}
|
||||
|
@ -279,11 +279,10 @@ public class GardenaAccountHandler extends BaseBridgeHandler implements GardenaS
|
||||
continue;
|
||||
}
|
||||
final ThingHandler thingHandler = gardenaThing.getHandler();
|
||||
if (!(thingHandler instanceof GardenaThingHandler)) {
|
||||
if (!(thingHandler instanceof GardenaThingHandler gardenaThingHandler)) {
|
||||
logger.debug("Handler for thingUID:{} is not a 'GardenaThingHandler' ({})", thingUID, thingHandler);
|
||||
continue;
|
||||
}
|
||||
final GardenaThingHandler gardenaThingHandler = (GardenaThingHandler) thingHandler;
|
||||
try {
|
||||
gardenaThingHandler.updateProperties(device);
|
||||
for (Channel channel : gardenaThing.getChannels()) {
|
||||
|
@ -261,14 +261,14 @@ public class GardenaThingHandler extends BaseThingHandler {
|
||||
String commandName = channelUID.getIdWithoutGroup().toUpperCase();
|
||||
String groupId = channelUID.getGroupId();
|
||||
if (groupId != null) {
|
||||
if (groupId.startsWith("valve") && groupId.endsWith("_commands")) {
|
||||
if ("valveSet_commands".equals(groupId)) {
|
||||
return new ValveSetCommand(ValveSetControl.valueOf(commandName));
|
||||
} else if (groupId.startsWith("valve") && groupId.endsWith("_commands")) {
|
||||
return new ValveCommand(ValveControl.valueOf(commandName),
|
||||
getDevice().getLocalService(dataItemProperty).commandDuration);
|
||||
} else if ("mower_commands".equals(groupId)) {
|
||||
return new MowerCommand(MowerControl.valueOf(commandName),
|
||||
getDevice().getLocalService(dataItemProperty).commandDuration);
|
||||
} else if ("valveSet_commands".equals(groupId)) {
|
||||
return new ValveSetCommand(ValveSetControl.valueOf(commandName));
|
||||
} else if ("powerSocket_commands".equals(groupId)) {
|
||||
return new PowerSocketCommand(PowerSocketControl.valueOf(commandName),
|
||||
getDevice().getLocalService(dataItemProperty).commandDuration);
|
||||
|
@ -113,38 +113,37 @@ public class Device {
|
||||
public void setDataItem(DataItem<?> dataItem) throws GardenaException {
|
||||
if (dataItem instanceof DeviceDataItem) {
|
||||
// ignore
|
||||
} else if (dataItem instanceof LocationDataItem) {
|
||||
LocationDataItem locationDataItem = (LocationDataItem) dataItem;
|
||||
} else if (dataItem instanceof LocationDataItem locationDataItem) {
|
||||
Location locationAttributes = locationDataItem.attributes;
|
||||
if (locationAttributes != null) {
|
||||
location = locationAttributes.name;
|
||||
}
|
||||
} else if (dataItem instanceof CommonServiceDataItem) {
|
||||
common = (CommonServiceDataItem) dataItem;
|
||||
} else if (dataItem instanceof MowerServiceDataItem) {
|
||||
mower = (MowerServiceDataItem) dataItem;
|
||||
} else if (dataItem instanceof PowerSocketServiceDataItem) {
|
||||
powerSocket = (PowerSocketServiceDataItem) dataItem;
|
||||
} else if (dataItem instanceof SensorServiceDataItem) {
|
||||
sensor = (SensorServiceDataItem) dataItem;
|
||||
} else if (dataItem instanceof ValveSetServiceDataItem) {
|
||||
valveSet = (ValveSetServiceDataItem) dataItem;
|
||||
} else if (dataItem instanceof ValveServiceDataItem) {
|
||||
} else if (dataItem instanceof CommonServiceDataItem commonServiceItem) {
|
||||
common = commonServiceItem;
|
||||
} else if (dataItem instanceof MowerServiceDataItem mowerServiceItemm) {
|
||||
mower = mowerServiceItemm;
|
||||
} else if (dataItem instanceof PowerSocketServiceDataItem powerSocketItem) {
|
||||
powerSocket = powerSocketItem;
|
||||
} else if (dataItem instanceof SensorServiceDataItem sensorServiceItem) {
|
||||
sensor = sensorServiceItem;
|
||||
} else if (dataItem instanceof ValveSetServiceDataItem valveSetServiceItem) {
|
||||
valveSet = valveSetServiceItem;
|
||||
} else if (dataItem instanceof ValveServiceDataItem valveServiceItem) {
|
||||
String valveNumber = StringUtils.substringAfterLast(dataItem.id, ":");
|
||||
if ("".equals(valveNumber) || "wc".equals(valveNumber) || "0".equals(valveNumber)) {
|
||||
valve = (ValveServiceDataItem) dataItem;
|
||||
valve = valveServiceItem;
|
||||
} else if ("1".equals(valveNumber)) {
|
||||
valveOne = (ValveServiceDataItem) dataItem;
|
||||
valveOne = valveServiceItem;
|
||||
} else if ("2".equals(valveNumber)) {
|
||||
valveTwo = (ValveServiceDataItem) dataItem;
|
||||
valveTwo = valveServiceItem;
|
||||
} else if ("3".equals(valveNumber)) {
|
||||
valveThree = (ValveServiceDataItem) dataItem;
|
||||
valveThree = valveServiceItem;
|
||||
} else if ("4".equals(valveNumber)) {
|
||||
valveFour = (ValveServiceDataItem) dataItem;
|
||||
valveFour = valveServiceItem;
|
||||
} else if ("5".equals(valveNumber)) {
|
||||
valveFive = (ValveServiceDataItem) dataItem;
|
||||
valveFive = valveServiceItem;
|
||||
} else if ("6".equals(valveNumber)) {
|
||||
valveSix = (ValveServiceDataItem) dataItem;
|
||||
valveSix = valveServiceItem;
|
||||
} else {
|
||||
throw new GardenaException("Unknown valveNumber in dataItem with id: " + dataItem.id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user