Avoid ClassCastExceptions (#12960)

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2022-06-18 15:03:02 -04:00 committed by GitHub
parent 4182595c19
commit 9e3ee5b294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,6 +56,7 @@ import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.ConfigStatusBridgeHandler; import org.openhab.core.thing.binding.ConfigStatusBridgeHandler;
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.slf4j.Logger; import org.slf4j.Logger;
@ -314,10 +315,12 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
for (Thing th : getThing().getThings()) { for (Thing th : getThing().getThings()) {
if (th.isEnabled()) { if (th.isEnabled()) {
String deviceId = th.getUID().getId(); String deviceId = th.getUID().getId();
OrbitBhyveSprinklerHandler handler = (OrbitBhyveSprinklerHandler) th.getHandler(); ThingHandler handler = th.getHandler();
for (OrbitBhyveDevice device : devices) { if (handler instanceof OrbitBhyveSprinklerHandler) {
if (deviceId.equals(th.getUID().getId())) { for (OrbitBhyveDevice device : devices) {
updateDeviceStatus(device, handler); if (deviceId.equals(th.getUID().getId())) {
updateDeviceStatus(device, (OrbitBhyveSprinklerHandler) handler);
}
} }
} }
} }
@ -336,9 +339,11 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
private void updateDeviceStatus(String deviceId) { private void updateDeviceStatus(String deviceId) {
for (Thing th : getThing().getThings()) { for (Thing th : getThing().getThings()) {
if (deviceId.equals(th.getUID().getId())) { if (deviceId.equals(th.getUID().getId())) {
OrbitBhyveSprinklerHandler handler = (OrbitBhyveSprinklerHandler) th.getHandler(); ThingHandler handler = th.getHandler();
OrbitBhyveDevice device = getDevice(deviceId); if (handler instanceof OrbitBhyveSprinklerHandler) {
updateDeviceStatus(device, handler); OrbitBhyveDevice device = getDevice(deviceId);
updateDeviceStatus(device, (OrbitBhyveSprinklerHandler) handler);
}
} }
} }
} }
@ -346,9 +351,9 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
private void updateDeviceProgramStatus(OrbitBhyveProgram program) { private void updateDeviceProgramStatus(OrbitBhyveProgram program) {
for (Thing th : getThing().getThings()) { for (Thing th : getThing().getThings()) {
if (program.getDeviceId().equals(th.getUID().getId())) { if (program.getDeviceId().equals(th.getUID().getId())) {
OrbitBhyveSprinklerHandler handler = (OrbitBhyveSprinklerHandler) th.getHandler(); ThingHandler handler = th.getHandler();
if (handler != null) { if (handler instanceof OrbitBhyveSprinklerHandler) {
handler.updateProgram(program); ((OrbitBhyveSprinklerHandler) handler).updateProgram(program);
} }
} }
} }