throw new IllegalStateException("Time pattern incorrect. Must be 'hh:mm[:ss]'. " + baseTime);
}
- String randomizedTime[] = baseTime.split(":");
+ String[] randomizedTime = baseTime.split(":");
if (upperTime != null && !upperTime.isEmpty()) {
String[] upperTimeParts = upperTime.split(":");
@SuppressWarnings({ "unused", "null" })
public static void validateHueHttpAddress(HueDataStore ds, String address) throws IllegalStateException {
String[] validation = address.split("/");
- if (validation.length < 6 || !validation[0].isEmpty() || !validation[1].equals("api")) {
+ if (validation.length < 6 || !validation[0].isEmpty() || !"api".equals(validation[1])) {
throw new IllegalStateException("Given address invalid!");
}
if ("groups".equals(validation[3]) && "action".equals(validation[5])) {
cronWeekdays.add(String.valueOf(c));
}
}
- String hourMinSec[] = RuleUtils.computeRandomizedDayTime(time, randomize);
+ String[] hourMinSec = RuleUtils.computeRandomizedDayTime(time, randomize);
// Cron expression: min hour day month weekdays
String cronExpression = hourMinSec[1] + " " + hourMinSec[0] + " * * " + String.join(",", cronWeekdays);
public static @Nullable String timeStringFromTrigger(List<Trigger> triggers) {
Optional<Trigger> trigger;
- trigger = triggers.stream().filter(p -> p.getId().equals("crontrigger")).findFirst();
+ trigger = triggers.stream().filter(p -> "crontrigger".equals(p.getId())).findFirst();
if (trigger.isPresent()) {
- String cronParts[] = ((String) trigger.get().getConfiguration().get("cronExpression")).split(" ");
+ String[] cronParts = ((String) trigger.get().getConfiguration().get("cronExpression")).split(" ");
if (cronParts.length != 5) {
LOGGER.warn("Cron trigger has no valid cron expression: {}", String.join(",", cronParts));
return null;
return String.format("W%d/T%s:%s:00", weekdays, cronParts[1], cronParts[0]);
}
- trigger = triggers.stream().filter(p -> p.getId().equals("timertrigger")).findFirst();
+ trigger = triggers.stream().filter(p -> "timertrigger".equals(p.getId())).findFirst();
if (trigger.isPresent()) {
TimerConfig c = trigger.get().getConfiguration().as(TimerConfig.class);
if (c.repeat == null) {
c.randomizeTime);
}
} else {
- trigger = triggers.stream().filter(p -> p.getId().equals("absolutetrigger")).findFirst();
+ trigger = triggers.stream().filter(p -> "absolutetrigger".equals(p.getId())).findFirst();
if (trigger.isPresent()) {
String date = (String) trigger.get().getConfiguration().get("date");
String time = (String) trigger.get().getConfiguration().get("time");
private final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(TIME_FORMAT);
private final Pattern timePattern = Pattern.compile("W(.*)/T(.*)/T(.*)");
// 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 };
+ private final boolean[] weekDaysAllowed = { false, false, false, false, false, false, false, false };
@SuppressWarnings({ "null", "unused" })
public HueRuleConditionHandler(Condition module, HueDataStore ds) {
config = module.getConfiguration().as(HueRuleEntry.Condition.class);
// pattern: "/sensors/2/state/buttonevent" or "/config/localtime"
- String validation[] = config.address.split("/");
+ String[] validation = config.address.split("/");
String uid = validation[2];
if ("groups".equals(validation[1]) && "action".equals(validation[3])) {
public boolean reachable = true;
public String mode = "homeautomation";
- public static enum AlertEnum {
+ public enum AlertEnum {
none,
/** flashes light once */
select,
public JsonElement serialize(HueAuthorizedConfig src, Type typeOfSrc, JsonSerializationContext context) {
src.UTC = LocalDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
src.localtime = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
- JsonElement jsonSubscription = context.serialize(src, HueAuthorizedConfigHelper.class);
- return jsonSubscription;
+ return context.serialize(src, HueAuthorizedConfigHelper.class);
}
}
}
public String nextGroupID() {
int nextId = groups.size();
while (true) {
- String id = "hueemulation" + String.valueOf(nextId);
+ String id = "hueemulation" + nextId;
if (!groups.containsKey(id)) {
return id;
}
*/
@NonNullByDefault
public class HueGroupEntry {
- public static enum TypeEnum {
+ public enum TypeEnum {
LightGroup, // 1.4
Luminaire, // 1.4
LightSource, // 1.4
.collect(Collectors.toList());
}
- JsonElement jsonSubscription = context.serialize(product, HueGroupHelper.class);
- return jsonSubscription;
+ return context.serialize(product, HueGroupHelper.class);
}
}
}
product.name = label;
}
- JsonElement jsonSubscription = context.serialize(product, HueDeviceHelper.class);
- return jsonSubscription;
+ return context.serialize(product, HueDeviceHelper.class);
}
}
public String owner = "";
- public static enum Operator {
+ public enum Operator {
unknown,
eq, // equals, Used for bool and int.
gt, // greater than, Allowed on int values.
*/
@NonNullByDefault
public class HueSceneEntry {
- public static enum TypeEnum {
+ public enum TypeEnum {
LightScene, // 1.28
GroupScene, // 1.28
}
/** time for transition in centiseconds. */
public int transitiontime;
- public static enum ColorMode {
+ public enum ColorMode {
ct,
hs,
xy
entry.description = desc;
}
- rule.getConditions().stream().filter(c -> c.getTypeUID().equals("hue.ruleCondition")).forEach(c -> {
+ rule.getConditions().stream().filter(c -> "hue.ruleCondition".equals(c.getTypeUID())).forEach(c -> {
HueRuleEntry.Condition condition = c.getConfiguration().as(HueRuleEntry.Condition.class);
// address with pattern "/sensors/2/state/buttonevent"
String[] parts = condition.address.split("/");
entry.conditions.add(condition);
});
- rule.getActions().stream().filter(a -> a.getTypeUID().equals("rules.HttpAction")).forEach(a -> {
+ rule.getActions().stream().filter(a -> "rules.HttpAction".equals(a.getTypeUID())).forEach(a -> {
HueCommand command = RuleUtils.httpActionToHueCommand(cs.ds, a, rule.getName());
if (command == null) {
return;
RuleBuilder builder, List<Trigger> oldTriggers, List<Condition> oldConditions, ItemRegistry itemRegistry) {
// Preserve all triggers, conditions that are not part of hue rules
Map<String, Trigger> triggers = new TreeMap<>();
- triggers.putAll(oldTriggers.stream().filter(a -> !a.getTypeUID().equals("core.ItemStateChangeTrigger"))
+ triggers.putAll(oldTriggers.stream().filter(a -> !"core.ItemStateChangeTrigger".equals(a.getTypeUID()))
.collect(Collectors.toMap(e -> e.getId(), e -> e)));
Map<String, Condition> conditions = new TreeMap<>();
- conditions.putAll(oldConditions.stream().filter(a -> !a.getTypeUID().equals("hue.ruleCondition"))
+ conditions.putAll(oldConditions.stream().filter(a -> !"hue.ruleCondition".equals(a.getTypeUID()))
.collect(Collectors.toMap(e -> e.getId(), e -> e)));
for (HueRuleEntry.Condition condition : hueConditions) {
String apikey) {
// Preserve all actions that are not "rules.HttpAction"
List<Action> actions = new ArrayList<>(oldActions);
- actions.removeIf(a -> a.getTypeUID().equals("rules.HttpAction"));
+ actions.removeIf(a -> "rules.HttpAction".equals(a.getTypeUID()));
for (HueCommand command : hueActions) {
command.address = "/api/" + apikey + command.address;
List<String> items = new ArrayList<>();
for (Action a : scene.getActions()) {
- if (!a.getTypeUID().equals("core.ItemCommandAction")) {
+ if (!"core.ItemCommandAction".equals(a.getTypeUID())) {
continue;
}
ItemCommandActionConfig config = a.getConfiguration().as(ItemCommandActionConfig.class);
HueScheduleEntry entry = new HueScheduleEntry();
entry.name = rule.getName();
entry.description = rule.getDescription();
- entry.autodelete = rule.getActions().stream().anyMatch(p -> p.getId().equals("autodelete"));
+ entry.autodelete = rule.getActions().stream().anyMatch(p -> "autodelete".equals(p.getId()));
entry.status = ruleManager.isEnabled(rule.getUID()) ? "enabled" : "disabled";
String timeStringFromTrigger = RuleUtils.timeStringFromTrigger(rule.getTriggers());
entry.localtime = timeStringFromTrigger;
for (Action a : rule.getActions()) {
- if (!a.getTypeUID().equals("rules.HttpAction")) {
+ if (!"rules.HttpAction".equals(a.getTypeUID())) {
continue;
}
HueCommand command = RuleUtils.httpActionToHueCommand(cs.ds, a, rule.getName());
if (command != null) {
RuleUtils.validateHueHttpAddress(ds, command.address);
- actions.removeIf(a -> a.getId().equals("command")); // Remove old command action if any and add new one
+ actions.removeIf(a -> "command".equals(a.getId())); // Remove old command action if any and add new one
actions.add(RuleUtils.createHttpAction(command, "command"));
} else if (oldActions.isEmpty()) { // This is a new rule without an action yet
throw new IllegalStateException("No command set!");
if (autodelete != null) {
// Remove action to remove rule after execution
- actions = actions.stream().filter(e -> !e.getId().equals("autodelete"))
+ actions = actions.stream().filter(e -> !"autodelete".equals(e.getId()))
.collect(Collectors.toCollection(() -> new ArrayList<>()));
if (autodelete) { // Add action to remove this rule again after execution
final Configuration actionConfig = new Configuration();
+ user.getValue().name + "</b> <small>" + user.getValue().lastUseDate + "</small>")
.collect(Collectors.joining("\n"));
- String url = "http://" + cs.ds.config.ipaddress + ":" + String.valueOf(localDiscovery.getDefaultport());
+ String url = "http://" + cs.ds.config.ipaddress + ":" + localDiscovery.getDefaultport();
String reachable = localDiscovery.selfTests().stream()
.map(entry -> TR(TD(entry.address) + TD(toYesNo(entry.reachable)) + TD(toYesNo(entry.isOurs))))
return;
}
logger.debug("APIKey {} added", apiKey);
- String l[] = label.split("#");
+ String[] l = label.split("#");
HueUserAuthWithSecrets hueUserAuth = new HueUserAuthWithSecrets(l[0], l.length == 2 ? l[1] : "openhab", apiKey,
clientKey);
cs.ds.config.whitelist.put(apiKey, hueUserAuth);
}
configChangeFuture = root.thenApply(this::createConfiguration)
.thenApplyAsync(this::performAddressTest, executor).thenApply(this::applyConfiguration)
- .thenCompose(c -> {
- return c.startNow();
- }).whenComplete((HueEmulationConfigWithRuntime config, @Nullable Throwable e) -> {
+ .thenCompose(c -> c.startNow())
+ .whenComplete((HueEmulationConfigWithRuntime config, @Nullable Throwable e) -> {
if (e != null) {
logger.warn("Upnp server: Address test failed", e);
}