diff --git a/backend/src/main/java/ch/akop/homesystem/services/impl/DeviceService.java b/backend/src/main/java/ch/akop/homesystem/services/impl/DeviceService.java index 36a906a..b573e49 100644 --- a/backend/src/main/java/ch/akop/homesystem/services/impl/DeviceService.java +++ b/backend/src/main/java/ch/akop/homesystem/services/impl/DeviceService.java @@ -47,19 +47,19 @@ public class DeviceService { private final AnimationRepository animationRepository; private final Vertx vertx; - private Set notLights; + private Set ignoreLightIdsOrNamesForCentralFunctions; @PostConstruct @Transactional - void setNotLights() { - notLights = basicConfigRepository.findByOrderByModifiedDesc() + void setIgnoreLightIdsOrNamesForCentralFunctions() { + ignoreLightIdsOrNamesForCentralFunctions = basicConfigRepository.findByOrderByModifiedDesc() .map(BasicConfig::getNotLights) - .map(HashSet::new) + .map(HashSet::new) .orElse(new HashSet<>()); } public void registerAControlledLight(Device device) { - notLights.add(device.getId()); + ignoreLightIdsOrNamesForCentralFunctions.add(device.getId()); } public > Optional findDeviceByName(String name, Class clazz) { @@ -93,14 +93,9 @@ public > Collection getDevicesOfType(Class clazz) { .collect(Collectors.toSet()); } - @Transactional public void turnAllLightsOff() { - var notLights = basicConfigRepository.findByOrderByModifiedDesc() - .map(BasicConfig::getNotLights) - .orElse(new HashSet<>()); - getDevicesOfType(SimpleLight.class).stream() - .filter(light -> !notLights.contains(light.getName())) + .filter(this::isLightUsableForCentralFunctions) .filter(Device::isReachable) .forEach(light -> { // see #74, if the commands are cumming to fast, then maybe lights are not correctly off @@ -119,7 +114,7 @@ public boolean isAnyLightOn() { return getDevicesOfType(SimpleLight.class) .stream() .filter(Device::isReachable) - .filter(light -> !notLights.contains(light.getName())) + .filter(this::isLightUsableForCentralFunctions) .anyMatch(SimpleLight::isCurrentStateIsOn); } @@ -168,4 +163,9 @@ public void activeSceneForAllGroups(String sceneName) { .filter(scene -> scene.getName().equals(sceneName)) .forEach(Scene::activate); } + + private boolean isLightUsableForCentralFunctions(SimpleLight light) { + return !ignoreLightIdsOrNamesForCentralFunctions.contains(light.getId()) + && !ignoreLightIdsOrNamesForCentralFunctions.contains(light.getName()); + } }