mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[hue] Fix compile warnings (#17293)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
77561d5d8f
commit
ba6cef3137
@ -22,7 +22,6 @@ import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -662,22 +661,22 @@ public class Resource {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the scene resource contains a 'status.active' element. If such an element is present, returns a Boolean
|
||||
* Optional whose value depends on the value of that element, or an empty Optional if it is not.
|
||||
* Check if the scene resource contains a 'status.active' element. Returns a Boolean if such an element is present,
|
||||
* whose value depends on the value of that element, or null if it is not.
|
||||
*
|
||||
* @return true, false, or empty.
|
||||
* @return true, false, or null.
|
||||
*/
|
||||
public Optional<Boolean> getSceneActive() {
|
||||
public @Nullable Boolean getSceneActive() {
|
||||
if (ResourceType.SCENE == getType()) {
|
||||
JsonElement status = this.status;
|
||||
if (Objects.nonNull(status) && status.isJsonObject()) {
|
||||
JsonElement active = ((JsonObject) status).get("active");
|
||||
if (Objects.nonNull(active) && active.isJsonPrimitive()) {
|
||||
return Optional.of(!"inactive".equalsIgnoreCase(active.getAsString()));
|
||||
return !"inactive".equalsIgnoreCase(active.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -688,42 +687,42 @@ public class Resource {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the getSceneActive() optional result is empty return 'UnDefType.NULL'. Otherwise if the optional result is
|
||||
* present and 'true' (i.e. the scene is active) return the scene name. Or finally (the optional result is present
|
||||
* and 'false') return 'UnDefType.UNDEF'.
|
||||
* Depending on the returned value from getSceneActive() this method returns 'UnDefType.NULL' for 'null',
|
||||
* 'UnDefType.UNDEF' for 'false' or when 'true' (i.e. the scene is active) return the scene name.
|
||||
*
|
||||
* @return either 'UnDefType.NULL', a StringType containing the (active) scene name, or 'UnDefType.UNDEF'.
|
||||
* @return either a StringType containing the (active) scene name, 'UnDefType.UNDEF' or 'UnDefType.NULL'.
|
||||
*/
|
||||
public State getSceneState() {
|
||||
return getSceneActive().map(a -> a ? new StringType(getName()) : UnDefType.UNDEF).orElse(UnDefType.NULL);
|
||||
Boolean sceneActive = getSceneActive();
|
||||
return sceneActive != null ? sceneActive ? new StringType(getName()) : UnDefType.UNDEF : UnDefType.NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the smart scene resource contains a 'state' element. If such an element is present, returns a Boolean
|
||||
* Optional whose value depends on the value of that element, or an empty Optional if it is not. Note that in some
|
||||
* resource types the 'state' element is not a String primitive.
|
||||
* whose value depends on the value of that element, or null if it is not.
|
||||
*
|
||||
* @return true, false, or empty.
|
||||
* @return true, false, or null.
|
||||
*/
|
||||
public Optional<Boolean> getSmartSceneActive() {
|
||||
public @Nullable Boolean getSmartSceneActive() {
|
||||
if (ResourceType.SMART_SCENE == getType() && (state instanceof JsonPrimitive statePrimitive)) {
|
||||
String state = statePrimitive.getAsString();
|
||||
if (Objects.nonNull(state)) {
|
||||
return Optional.of(SmartSceneState.ACTIVE == SmartSceneState.of(state));
|
||||
return SmartSceneState.ACTIVE == SmartSceneState.of(state);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the getSmartSceneActive() optional result is empty return 'UnDefType.NULL'. Otherwise if the optional result
|
||||
* is present and 'true' (i.e. the scene is active) return the smart scene name. Or finally (the optional result is
|
||||
* present and 'false') return 'UnDefType.UNDEF'.
|
||||
* Depending on the returned value from getSmartSceneActive() this method returns 'UnDefType.NULL' for 'null',
|
||||
* 'UnDefType.UNDEF' for 'false' or when 'true' (i.e. the scene is active) return the scene name.
|
||||
*
|
||||
* @return either 'UnDefType.NULL', a StringType containing the (active) scene name, or 'UnDefType.UNDEF'.
|
||||
* @return either a StringType containing the (active) scene name, 'UnDefType.UNDEF' or 'UnDefType.NULL'.
|
||||
*/
|
||||
public State getSmartSceneState() {
|
||||
return getSmartSceneActive().map(a -> a ? new StringType(getName()) : UnDefType.UNDEF).orElse(UnDefType.NULL);
|
||||
Boolean smartSceneActive = getSmartSceneActive();
|
||||
return smartSceneActive != null ? smartSceneActive ? new StringType(getName()) : UnDefType.UNDEF
|
||||
: UnDefType.NULL;
|
||||
}
|
||||
|
||||
public List<ResourceReference> getServiceReferences() {
|
||||
|
@ -485,9 +485,9 @@ public class Clip2Bridge implements Closeable {
|
||||
long delay;
|
||||
synchronized (Clip2Bridge.this) {
|
||||
Instant now = Instant.now();
|
||||
delay = lastRequestTime
|
||||
delay = Objects.requireNonNull(lastRequestTime
|
||||
.map(t -> Math.max(0, Duration.between(now, t).toMillis() + REQUEST_INTERVAL_MILLISECS))
|
||||
.orElse(0L);
|
||||
.orElse(0L));
|
||||
lastRequestTime = Optional.of(now.plusMillis(delay));
|
||||
}
|
||||
Thread.sleep(delay);
|
||||
|
@ -635,12 +635,15 @@ public class Clip2ThingHandler extends BaseThingHandler {
|
||||
* @param resources a collection of Resource objects containing the new state.
|
||||
*/
|
||||
public void onResources(Collection<Resource> resources) {
|
||||
boolean sceneActivated = resources.stream().anyMatch(r -> sceneContributorsCache.containsKey(r.getId())
|
||||
&& (r.getSceneActive().orElse(false) || r.getSmartSceneActive().orElse(false)));
|
||||
boolean sceneActivated = resources.stream()
|
||||
.anyMatch(r -> sceneContributorsCache.containsKey(r.getId())
|
||||
&& (Objects.requireNonNullElse(r.getSceneActive(), false)
|
||||
|| Objects.requireNonNullElse(r.getSmartSceneActive(), false)));
|
||||
for (Resource resource : resources) {
|
||||
// Skip scene deactivation when we have also received a scene activation.
|
||||
boolean updateChannels = !sceneActivated || !sceneContributorsCache.containsKey(resource.getId())
|
||||
|| resource.getSceneActive().orElse(false) || resource.getSmartSceneActive().orElse(false);
|
||||
|| Objects.requireNonNullElse(resource.getSceneActive(), false)
|
||||
|| Objects.requireNonNullElse(resource.getSmartSceneActive(), false);
|
||||
onResource(resource, updateChannels);
|
||||
}
|
||||
}
|
||||
@ -1233,8 +1236,9 @@ public class Clip2ThingHandler extends BaseThingHandler {
|
||||
sceneContributorsCache.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getId(), s -> s)));
|
||||
sceneResourceEntries.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getName(), s -> s)));
|
||||
|
||||
State state = Objects.requireNonNull(scenes.stream().filter(s -> s.getSceneActive().orElse(false))
|
||||
.map(s -> s.getSceneState()).findAny().orElse(UnDefType.UNDEF));
|
||||
State state = Objects.requireNonNull(
|
||||
scenes.stream().filter(s -> Objects.requireNonNullElse(s.getSceneActive(), false))
|
||||
.map(s -> s.getSceneState()).findAny().orElse(UnDefType.UNDEF));
|
||||
|
||||
// create scene channel if it is missing
|
||||
if (getThing().getChannel(CHANNEL_2_SCENE) == null) {
|
||||
|
@ -24,7 +24,6 @@ import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -522,9 +521,9 @@ class Clip2DtoTest {
|
||||
ResourceType type = group.getType();
|
||||
assertNotNull(type);
|
||||
assertEquals(ResourceType.ROOM, type);
|
||||
Optional<Boolean> state = item.getSmartSceneActive();
|
||||
assertTrue(state.isPresent());
|
||||
assertFalse(state.get());
|
||||
Boolean state = item.getSmartSceneActive();
|
||||
assertNotNull(state);
|
||||
assertFalse(state);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -613,9 +612,9 @@ class Clip2DtoTest {
|
||||
assertNotNull(active);
|
||||
assertTrue(active.isJsonPrimitive());
|
||||
assertEquals("inactive", active.getAsString());
|
||||
Optional<Boolean> isActive = resource.getSceneActive();
|
||||
assertTrue(isActive.isPresent());
|
||||
assertEquals(Boolean.FALSE, isActive.get());
|
||||
Boolean isActive = resource.getSceneActive();
|
||||
assertNotNull(isActive);
|
||||
assertEquals(Boolean.FALSE, isActive);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user