Skip to content

Commit

Permalink
Fix equalsIgnoreCase issue (openhab#11140)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
  • Loading branch information
mlobstein committed Aug 24, 2021
1 parent 5ce27e3 commit 8198911
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 44 deletions.
6 changes: 3 additions & 3 deletions bundles/org.openhab.binding.benqprojector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Some notes:
things/benq.things:

```
//serial port connection
// serial port connection
benqprojector:projector-serial:hometheater "Projector" [ serialPort="COM5", pollingInterval=10 ]
// serial over IP connection
// direct IP or serial over IP connection
benqprojector:projector-tcp:hometheater "Projector" [ host="192.168.0.10", port=8000, pollingInterval=10 ]
```
Expand All @@ -94,7 +94,7 @@ Number benqLampTime "Lamp Time [%d h]" <switch> { channel="benqprojector:p
sitemaps/benq.sitemap

```
sitemap benq label="BenQ Projector Demo" {
sitemap benq label="BenQ Projector" {
Frame label="Controls" {
Switch item=benqPower label="Power"
Selection item=benqSource label="Source" mappings=["hdmi"="HDMI", "hdmi2"="HDMI2", "ypbr"="Component", "RGB"="Computer", "vid"="Video", "svid"="S-Video"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.benqprojector.internal;

import java.io.InvalidClassException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.NumberItem;
Expand All @@ -28,14 +26,14 @@
*/
@NonNullByDefault
public enum BenqProjectorCommandType {
POWER("Power", SwitchItem.class),
SOURCE("Source", StringItem.class),
PICTURE_MODE("PictureMode", StringItem.class),
ASPECT_RATIO("AspectRatio", StringItem.class),
FREEZE("Freeze", SwitchItem.class),
BLANK("Blank", SwitchItem.class),
DIRECTCMD("DirectCmd", StringItem.class),
LAMP_TIME("LampTime", NumberItem.class);
POWER("power", SwitchItem.class),
SOURCE("source", StringItem.class),
PICTURE_MODE("picturemode", StringItem.class),
ASPECT_RATIO("aspectratio", StringItem.class),
FREEZE("freeze", SwitchItem.class),
BLANK("blank", SwitchItem.class),
DIRECTCMD("directcmd", StringItem.class),
LAMP_TIME("lamptime", NumberItem.class);

private final String text;
private Class<? extends Item> itemClass;
Expand All @@ -54,48 +52,22 @@ public Class<? extends Item> getItemClass() {
return itemClass;
}

/**
* Procedure to validate command type string.
*
* @param commandTypeText
* command string e.g. RawData, Command, Brightness
* @return true if item is valid.
* @throws IllegalArgumentException
* Not valid command type.
* @throws InvalidClassException
* Not valid class for command type.
*/
public static boolean validateBinding(String commandTypeText, Class<? extends Item> itemClass)
throws IllegalArgumentException, InvalidClassException {
for (BenqProjectorCommandType c : BenqProjectorCommandType.values()) {
if (c.text.equalsIgnoreCase(commandTypeText)) {
if (c.getItemClass().equals(itemClass)) {
return true;
} else {
throw new InvalidClassException("Not valid class for command type");
}
}
}

throw new IllegalArgumentException("Not valid command type");
}

/**
* Procedure to convert command type string to command type class.
*
* @param commandTypeText
* command string e.g. RawData, Command, Brightness
* @return corresponding command type.
* @throws InvalidClassException
* Not valid class for command type.
* @throws IllegalArgumentException
* No valid class for command type.
*/
public static BenqProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
for (BenqProjectorCommandType c : BenqProjectorCommandType.values()) {
if (c.text.equalsIgnoreCase(commandTypeText)) {
if (c.text.equals(commandTypeText)) {
return c;
}
}

throw new IllegalArgumentException("Not valid command type");
throw new IllegalArgumentException("Not valid command type: " + commandTypeText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void updateChannelState(Channel channel) {
}
}
} catch (IllegalArgumentException e) {
logger.warn("Unknown channel {}", channel.getUID().getId());
logger.warn("Unknown channel {}, exception: {}", channel.getUID().getId(), e.getMessage());
}
}

Expand Down

0 comments on commit 8198911

Please sign in to comment.