这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ public void modified(Map<String, Object> properties) {
InetAddress configuredAddress = null;
int networkPrefixLength = 24; // Default for most networks: 255.255.255.0

if (config.discoveryIp != null) {
discoveryIps = Collections.unmodifiableSet(Stream.of(config.discoveryIp.split(",")).map(String::trim)
String discoveryIp = config.discoveryIp;
if (discoveryIp != null) {
discoveryIps = Collections.unmodifiableSet(Stream.of(discoveryIp.split(",")).map(String::trim)
.map(this::byName).filter(e -> e != null).collect(Collectors.toSet()));
} else {
discoveryIps = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
*/
package org.openhab.io.hueemulation.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The pure item type is not enough to decide how we expose an item.
* We need to consider the assigned tags and category as well. This
* computed device type is stored next to the item itself.
*
* @author David Graeff - Initial contribution
*/
@NonNullByDefault
public enum DeviceType {
SwitchType,
WhiteType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;
Expand Down Expand Up @@ -194,7 +193,7 @@ protected void deactivate() {
/**
* We have a hard dependency on the {@link ConfigStore} and that it has initialized the Hue DataStore config
* completely. That initialization happens asynchronously and therefore we cannot rely on OSGi activate/modified
* state changes. Instead the {@link EventAdmin} is used and we listen for the
* state changes. Instead the {@link org.osgi.service.event.EventAdmin} is used and we listen for the
* {@link ConfigStore#EVENT_ADDRESS_CHANGED} event that is fired as soon as the config is ready.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static String[] computeRandomizedDayTime(String baseTime, @Nullable Strin
* {@code "/api/<username>/lights/1/state"}
* @throws IllegalStateException Thrown if address is invalid
*/
@SuppressWarnings({ "unused", "null" })
public static void validateHueHttpAddress(HueDataStore ds, String address) throws IllegalStateException {
String[] validation = address.split("/");
if (validation.length < 6 || !validation[0].isEmpty() || !"api".equals(validation[1])) {
Expand All @@ -113,7 +112,6 @@ public static class ConfigHttpAction {
public String body = "";
}

@SuppressWarnings({ "unused", "null" })
public static @Nullable HueCommand httpActionToHueCommand(HueDataStore ds, Action a, @Nullable String ruleName) {
ConfigHttpAction config = a.getConfiguration().as(ConfigHttpAction.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,30 +430,29 @@ public static AbstractHueState adjustedColorStateFromItemState(State itemState,

if (lastCommand != null && lastHueChange != null) {
if (lastCommand instanceof HSBType) {
if (hueState instanceof HueStateColorBulb && itemState.as(HSBType.class).equals(lastCommand)) {
HueStateColorBulb c = (HueStateColorBulb) hueState;

if (hueState instanceof HueStateColorBulb hueStateColorBulb
&& lastCommand.equals(itemState.as(HSBType.class))) {
if (lastHueChange.bri != null) {
c.bri = lastHueChange.bri;
hueStateColorBulb.bri = lastHueChange.bri;
}
if (lastHueChange.hue != null) {
c.hue = lastHueChange.hue;
hueStateColorBulb.hue = lastHueChange.hue;
}
if (lastHueChange.sat != null) {
c.sat = lastHueChange.sat;
hueStateColorBulb.sat = lastHueChange.sat;
}
// Although we can't set a colour temperature in OH
// this keeps Alexa happy when asking to turn a light
// to white.
if (lastHueChange.ct != null) {
c.ct = lastHueChange.ct;
hueStateColorBulb.ct = lastHueChange.ct;
}
}
} else if (lastCommand instanceof PercentType) {
if (hueState instanceof HueStateBulb && itemState != null
if (hueState instanceof HueStateBulb hueStateBulb
&& lastCommand.equals(itemState.as(PercentType.class))) {
if (lastHueChange.bri != null) {
((HueStateBulb) hueState).bri = lastHueChange.bri;
hueStateBulb.bri = lastHueChange.bri;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.time.temporal.TemporalAccessor;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.ModuleHandlerCallback;
import org.openhab.core.automation.Trigger;
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
Expand All @@ -40,6 +42,7 @@
*
* @author David Graeff - Initial contribution
*/
@NonNullByDefault
public class AbsoluteDateTimeTriggerHandler extends BaseTriggerModuleHandler implements SchedulerRunnable {

private final Logger logger = LoggerFactory.getLogger(AbsoluteDateTimeTriggerHandler.class);
Expand All @@ -52,13 +55,14 @@ public class AbsoluteDateTimeTriggerHandler extends BaseTriggerModuleHandler imp
public static final String CFG_TIME = "time";
public static final String CFG_TIME_RND = "randomizeTime";

private final Scheduler scheduler;
private final Instant dateTime;
private ScheduledCompletableFuture<?> schedule;
private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String TIME_FORMAT = "HH:mm:ss";
private static final String DATETIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT;

private final Scheduler scheduler;
private final Instant dateTime;
private final DateTimeFormatter dateTimeformatter;
private @Nullable ScheduledCompletableFuture<?> schedule;

public AbsoluteDateTimeTriggerHandler(Trigger module, Scheduler scheduler) {
super(module);
Expand Down Expand Up @@ -99,15 +103,19 @@ private void scheduleJob() {
@Override
public synchronized void dispose() {
super.dispose();
ScheduledCompletableFuture<?> schedule = this.schedule;
if (schedule != null) {
schedule.cancel(true);
logger.debug("cancelled job for trigger '{}'.", module.getId());
this.schedule = null;
logger.debug("Cancelled job for trigger '{}'.", module.getId());
}
}

@Override
public void run() {
((TriggerHandlerCallback) callback).triggered(module, Map.of());
if (callback instanceof TriggerHandlerCallback triggerHandlerCallback) {
triggerHandlerCallback.triggered(module, Map.of());
}
schedule = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.net.URI;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -74,7 +75,8 @@ public HttpActionHandler(final Action module, HttpClientFactory httpFactory) {
// convert relative path to absolute one
String url = config.url;
if (url.startsWith("/")) {
config.url = "http://localhost:" + Integer.getInteger("org.osgi.service.http.port", 8080).toString() + url;
config.url = "http://localhost:"
+ Objects.requireNonNull(Integer.getInteger("org.osgi.service.http.port", 8080)).toString() + url;
}

httpClient = httpFactory.createHttpClient("HttpActionHandler_" + module.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -72,7 +70,6 @@ public class HueRuleConditionHandler extends BaseModuleHandler<Condition> implem
// weekdays range from Monday to Sunday (1-7). The first entry is not used
private final boolean[] weekDaysAllowed = { false, false, false, false, false, false, false, false };

@SuppressWarnings({ "null", "unused" })
public HueRuleConditionHandler(Condition module, HueDataStore ds) {
super(module);
config = module.getConfiguration().as(HueRuleEntry.Condition.class);
Expand Down Expand Up @@ -106,10 +103,6 @@ public HueRuleConditionHandler(Condition module, HueDataStore ds) {
throw new IllegalStateException("Can only handle groups and lights");
}

if (itemUID == null) {
throw new IllegalStateException("Can only handle groups and lights");
}

final String value = config.value;
switch (config.operator) {
case eq:
Expand Down Expand Up @@ -174,7 +167,6 @@ public HueRuleConditionHandler(Condition module, HueDataStore ds) {

// Monday = 64, Tuesday = 32, Wednesday = 16, Thursday = 8, Friday = 4, Saturday = 2, Sunday = 1
int weekdaysBinaryEncoded = Integer.valueOf(m.group(1));
List<String> cronWeekdays = new ArrayList<>();
for (int bin = 64, c = 1; bin > 0; bin /= 2, c += 1) {
if (weekdaysBinaryEncoded / bin == 1) {
weekdaysBinaryEncoded = weekdaysBinaryEncoded % bin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class RemoveRuleActionHandler extends BaseModuleHandler<Action> implement

private RuleRegistry ruleRegistry;

@SuppressWarnings({ "null", "unused" })
public RemoveRuleActionHandler(final Action module, RuleRegistry ruleRegistry) {
super(module);
this.ruleRegistry = ruleRegistry;
Expand All @@ -49,10 +48,11 @@ public RemoveRuleActionHandler(final Action module, RuleRegistry ruleRegistry) {
throw new IllegalArgumentException("'Configuration' can not be empty.");
}

ruleUID = (String) config.get(CFG_REMOVE_UID);
String ruleUID = (String) config.get(CFG_REMOVE_UID);
if (ruleUID == null) {
throw new IllegalArgumentException("'ruleUIDs' property must not be null.");
}
this.ruleUID = ruleUID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public synchronized void dispose() {

@Override
public Duration call() {
((TriggerHandlerCallback) callback).triggered(module, Map.of());
if (callback instanceof TriggerHandlerCallback triggerHandlerCallback) {
triggerHandlerCallback.triggered(module, Map.of());
}
config.repeat -= 1;
if (config.repeat == 0) {
schedule = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ public Response putFullConfigApi(@Context UriInfo uri,
if (!userManagement.authorizeUser(username)) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.UNAUTHORIZED, "Not Authorized");
}
final HueChangeRequest changes;
changes = cs.gson.fromJson(body, HueChangeRequest.class);
final HueChangeRequest changes = cs.gson.fromJson(body, HueChangeRequest.class);
if (changes == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.INVALID_JSON, "Empty body");
}
String devicename = changes.devicename;
if (devicename != null) {
cs.ds.config.devicename = devicename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ public synchronized void added(Item newElement) {
* The HUE API enforces a Group 0 that contains all lights.
*/
private void updateGroup0() {
cs.ds.groups.get("0").lights = cs.ds.lights.keySet().stream().map(v -> String.valueOf(v))
.collect(Collectors.toList());
HueGroupEntry group0 = cs.ds.groups.get("0");
if (group0 != null) {
group0.lights = cs.ds.lights.keySet().stream().map(v -> String.valueOf(v)).toList();
}
}

@Override
Expand All @@ -207,7 +209,6 @@ public synchronized void removed(Item element) {
/**
* The tags might have changed
*/
@SuppressWarnings({ "null", "unused" })
@Override
public synchronized void updated(Item oldElement, Item newElement) {
if (!(newElement instanceof GenericItem element)) {
Expand Down Expand Up @@ -291,7 +292,6 @@ public Response getLightApi(@Context UriInfo uri, //
return Response.ok(cs.gson.toJson(cs.ds.lights.get(id))).build();
}

@SuppressWarnings({ "null", "unused" })
@DELETE
@Path("{username}/lights/{id}")
@Operation(summary = "Deletes the item that is represented by this id", responses = {
Expand All @@ -316,7 +316,6 @@ public Response removeLightAPI(@Context UriInfo uri,
}
}

@SuppressWarnings({ "null", "unused" })
@PUT
@Path("{username}/lights/{id}")
@Operation(summary = "Rename a light", responses = { @ApiResponse(responseCode = "200", description = "OK") })
Expand All @@ -333,6 +332,10 @@ public Response renameLightApi(@Context UriInfo uri, //

final HueChangeRequest changeRequest = cs.gson.fromJson(body, HueChangeRequest.class);

if (changeRequest == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.INVALID_JSON, "Empty body");
}

String name = changeRequest.name;
if (name == null || name.isEmpty()) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.INVALID_JSON, "Invalid request: No name set");
Expand All @@ -344,7 +347,6 @@ public Response renameLightApi(@Context UriInfo uri, //
return NetworkUtils.singleSuccess(cs.gson, name, "/lights/" + id + "/name");
}

@SuppressWarnings({ "null", "unused" })
@PUT
@Path("{username}/lights/{id}/state")
@Operation(summary = "Set light state", responses = { @ApiResponse(responseCode = "200", description = "OK") })
Expand Down Expand Up @@ -390,7 +392,6 @@ public Response setLightStateApi(@Context UriInfo uri, //
}.getType())).build();
}

@SuppressWarnings({ "null", "unused" })
@PUT
@Path("{username}/groups/{id}/action")
@Operation(summary = "Initiate group action", responses = {
Expand All @@ -402,11 +403,11 @@ public Response setGroupActionApi(@Context UriInfo uri, //
return NetworkUtils.singleError(cs.gson, uri, HueResponse.UNAUTHORIZED, "Not Authorized");
}
HueGroupEntry hueDevice = cs.ds.groups.get(id);
GroupItem groupItem = hueDevice.groupItem;
if (hueDevice == null || groupItem == null) {
if (hueDevice == null || hueDevice.groupItem == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.NOT_AVAILABLE, "Group not existing");
}

GroupItem groupItem = hueDevice.groupItem;
HueStateChange state = cs.gson.fromJson(body, HueStateChange.class);
if (state == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.INVALID_JSON,
Expand Down Expand Up @@ -459,7 +460,6 @@ public Response getGroupApi(@Context UriInfo uri, //
return Response.ok(cs.gson.toJson(cs.ds.groups.get(id))).build();
}

@SuppressWarnings({ "null", "unused" })
@POST
@Path("{username}/groups")
@Operation(summary = "Create a new group", responses = { @ApiResponse(responseCode = "200", description = "OK") })
Expand All @@ -486,7 +486,6 @@ public Response postNewGroup(@Context UriInfo uri,
groupItem.addTag("hueroom_" + state.roomclass);
}

List<Item> groupItems = new ArrayList<>();
for (String id : state.lights) {
Item item = itemRegistry.get(id);
if (item == null) {
Expand All @@ -502,7 +501,6 @@ public Response postNewGroup(@Context UriInfo uri,
return NetworkUtils.singleSuccess(cs.gson, groupid, "id");
}

@SuppressWarnings({ "null", "unused" })
@DELETE
@Path("{username}/groups/{id}")
@Operation(summary = "Deletes the item that is represented by this id", responses = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ public Response modifyRuleApi(@Context UriInfo uri, //

final HueRuleEntry changeRequest = cs.gson.fromJson(body, HueRuleEntry.class);

if (changeRequest == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.INVALID_JSON, "Empty body");
}

Rule rule = ruleRegistry.remove(id);
if (rule == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.NOT_AVAILABLE, "Rule does not exist!");
Expand Down Expand Up @@ -333,7 +337,6 @@ public Response modifyRuleApi(@Context UriInfo uri, //
));
}

@SuppressWarnings({ "null" })
@POST
@Path("{username}/rules")
@Operation(summary = "Create a new rule", responses = { @ApiResponse(responseCode = "200", description = "OK") })
Expand All @@ -353,10 +356,7 @@ public Response postNewRule(@Context UriInfo uri,
String uid = UUID.randomUUID().toString();
RuleBuilder builder = RuleBuilder.create(uid).withName(newRuleData.name);

String description = newRuleData.description;
if (description != null) {
builder.withDescription(description);
}
builder.withDescription(newRuleData.description);

try {
builder.withActions(createActions(uid, newRuleData.actions, Collections.emptyList(), username));
Expand Down
Loading