[gardena] eliminate ClassCastException (quick fix) (#13004)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2022-06-24 17:25:43 +01:00 committed by GitHub
parent e80b39916c
commit b5d7d22c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseBridgeHandler; import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerService; import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType; import org.openhab.core.types.RefreshType;
@ -166,20 +167,26 @@ public class GardenaAccountHandler extends BaseBridgeHandler implements GardenaS
@Override @Override
public void onDeviceUpdated(Device device) { public void onDeviceUpdated(Device device) {
for (ThingUID thingUID : UidUtils.getThingUIDs(device, getThing())) { for (ThingUID thingUID : UidUtils.getThingUIDs(device, getThing())) {
final Thing gardenaThing; final Thing gardenaThing = getThing().getThing(thingUID);
final GardenaThingHandler gardenaThingHandler; if (gardenaThing == null) {
if ((gardenaThing = getThing().getThing(thingUID)) != null logger.debug("No thing exists for thingUID:{}", thingUID);
&& (gardenaThingHandler = (GardenaThingHandler) gardenaThing.getHandler()) != null) { continue;
try { }
gardenaThingHandler.updateProperties(device); final ThingHandler thingHandler = gardenaThing.getHandler();
for (Channel channel : gardenaThing.getChannels()) { if (!(thingHandler instanceof GardenaThingHandler)) {
gardenaThingHandler.updateChannel(channel.getUID()); logger.debug("Handler for thingUID:{} is not a 'GardenaThingHandler' ({})", thingUID, thingHandler);
} continue;
gardenaThingHandler.updateStatus(device); }
} catch (GardenaException ex) { final GardenaThingHandler gardenaThingHandler = (GardenaThingHandler) thingHandler;
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, ex.getMessage()); try {
} catch (AccountHandlerNotAvailableException ignore) { gardenaThingHandler.updateProperties(device);
for (Channel channel : gardenaThing.getChannels()) {
gardenaThingHandler.updateChannel(channel.getUID());
} }
gardenaThingHandler.updateStatus(device);
} catch (GardenaException ex) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, ex.getMessage());
} catch (AccountHandlerNotAvailableException ignore) {
} }
} }
} }