Java 17 features (H-M) (#15520)

- add missing @override
- Java style array syntax
- remove redundant modifiers
- always move String constants to left side in comparisons
- simplify lambda expressions and return statements
- use replace instead of replaceAll w/o regex
- instanceof matching and multiline strings
- remove null check before instanceof

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -324,8 +324,7 @@ public class MilightBridgeDiscovery extends AbstractDiscoveryService implements
try (MilightV6SessionManager session = new MilightV6SessionManager(bridgeID, sessionState, addressOfBridge,
MilightBindingConstants.PORT_VER6, MilightV6SessionManager.TIMEOUT_MS, new byte[] { 0, 0 })) {
session.start();
boolean success = s.tryAcquire(1, 1300, TimeUnit.MILLISECONDS);
return success;
return s.tryAcquire(1, 1300, TimeUnit.MILLISECONDS);
} catch (IOException e) {
logger.debug("checkForV6Bridge failed", e);
}

View File

@@ -105,20 +105,16 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
switch (channelUID.getId()) {
case MilightBindingConstants.CHANNEL_COLOR: {
if (command instanceof HSBType) {
HSBType hsb = (HSBType) command;
if (command instanceof HSBType hsb) {
this.setHSB(hsb.getHue().intValue(), hsb.getSaturation().intValue(), hsb.getBrightness().intValue(),
state);
updateState(MilightBindingConstants.CHANNEL_SATURATION, new PercentType(state.saturation));
} else if (command instanceof OnOffType) {
OnOffType hsb = (OnOffType) command;
} else if (command instanceof OnOffType hsb) {
this.setPower(hsb == OnOffType.ON, state);
} else if (command instanceof PercentType) {
PercentType p = (PercentType) command;
} else if (command instanceof PercentType p) {
this.setBrightness(p.intValue(), state);
} else if (command instanceof IncreaseDecreaseType) {
this.changeBrightness((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE ? 1 : -1,
state);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
this.changeBrightness(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1, state);
} else {
logger.error(
"CHANNEL_COLOR channel only supports OnOffType/IncreaseDecreaseType/HSBType/PercentType");
@@ -137,15 +133,12 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
break;
}
case MilightBindingConstants.CHANNEL_BRIGHTNESS: {
if (command instanceof OnOffType) {
OnOffType hsb = (OnOffType) command;
this.setPower(hsb == OnOffType.ON, state);
} else if (command instanceof DecimalType) {
DecimalType d = (DecimalType) command;
this.setBrightness(d.intValue(), state);
} else if (command instanceof IncreaseDecreaseType) {
this.changeBrightness((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE ? 1 : -1,
state);
if (command instanceof OnOffType onOffCommand) {
this.setPower(onOffCommand == OnOffType.ON, state);
} else if (command instanceof DecimalType decimalCommand) {
this.setBrightness(decimalCommand.intValue(), state);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
this.changeBrightness(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1, state);
} else {
logger.error("CHANNEL_BRIGHTNESS channel only supports OnOffType/IncreaseDecreaseType/DecimalType");
}
@@ -155,15 +148,12 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
break;
}
case MilightBindingConstants.CHANNEL_SATURATION: {
if (command instanceof OnOffType) {
OnOffType s = (OnOffType) command;
this.setSaturation((s == OnOffType.ON) ? 100 : 0, state);
} else if (command instanceof DecimalType) {
DecimalType d = (DecimalType) command;
this.setSaturation(d.intValue(), state);
} else if (command instanceof IncreaseDecreaseType) {
this.changeSaturation((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE ? 1 : -1,
state);
if (command instanceof OnOffType onOffCommand) {
this.setSaturation((onOffCommand == OnOffType.ON) ? 100 : 0, state);
} else if (command instanceof DecimalType decimalCommand) {
this.setSaturation(decimalCommand.intValue(), state);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
this.changeSaturation(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1, state);
} else {
logger.error("CHANNEL_SATURATION channel only supports OnOffType/IncreaseDecreaseType/DecimalType");
}
@@ -173,14 +163,12 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
break;
}
case MilightBindingConstants.CHANNEL_TEMP: {
if (command instanceof OnOffType) {
OnOffType s = (OnOffType) command;
this.setColorTemperature((s == OnOffType.ON) ? 100 : 0, state);
} else if (command instanceof IncreaseDecreaseType) {
this.changeColorTemperature(
(IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE ? 1 : -1, state);
} else if (command instanceof DecimalType) {
DecimalType d = (DecimalType) command;
if (command instanceof OnOffType onOffCommand) {
this.setColorTemperature((onOffCommand == OnOffType.ON) ? 100 : 0, state);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
this.changeColorTemperature(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1,
state);
} else if (command instanceof DecimalType d) {
this.setColorTemperature(d.intValue(), state);
} else {
logger.error("CHANNEL_TEMP channel only supports OnOffType/IncreaseDecreaseType/DecimalType");
@@ -188,11 +176,10 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
break;
}
case MilightBindingConstants.CHANNEL_SPEED_REL: {
if (command instanceof IncreaseDecreaseType) {
IncreaseDecreaseType id = (IncreaseDecreaseType) command;
if (id == IncreaseDecreaseType.INCREASE) {
if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
if (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) {
this.changeSpeed(1, state);
} else if (id == IncreaseDecreaseType.DECREASE) {
} else if (increaseDecreaseCommand == IncreaseDecreaseType.DECREASE) {
this.changeSpeed(-1, state);
}
} else {
@@ -201,20 +188,18 @@ public abstract class AbstractLedHandler extends BaseThingHandler implements Led
break;
}
case MilightBindingConstants.CHANNEL_ANIMATION_MODE: {
if (command instanceof DecimalType) {
DecimalType d = (DecimalType) command;
this.setLedMode(d.intValue(), state);
if (command instanceof DecimalType decimalCommand) {
this.setLedMode(decimalCommand.intValue(), state);
} else {
logger.error("Animation mode channel only supports DecimalType");
}
break;
}
case MilightBindingConstants.CHANNEL_ANIMATION_MODE_REL: {
if (command instanceof IncreaseDecreaseType) {
IncreaseDecreaseType id = (IncreaseDecreaseType) command;
if (id == IncreaseDecreaseType.INCREASE) {
if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
if (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) {
this.nextAnimationMode(state);
} else if (id == IncreaseDecreaseType.DECREASE) {
} else if (increaseDecreaseCommand == IncreaseDecreaseType.DECREASE) {
this.previousAnimationMode(state);
}
} else {

View File

@@ -71,13 +71,13 @@ public class MilightV2RGBHandler extends AbstractLedHandler {
public void setPower(boolean on, MilightThingState state) {
if (on) {
logger.debug("milight: sendOn");
byte messageBytes[] = null;
byte[] messageBytes = null;
// message rgb bulbs ON
messageBytes = new byte[] { 0x22, 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_POWER_MODE), messageBytes));
} else {
logger.debug("milight: sendOff");
byte messageBytes[] = null;
byte[] messageBytes = null;
// message rgb bulbs OFF
messageBytes = new byte[] { 0x21, 0x00, 0x55 };

View File

@@ -26,12 +26,12 @@ import org.openhab.core.thing.Thing;
public class MilightV3RGBWHandler extends AbstractLedV3Handler {
protected static final int BRIGHTNESS_LEVELS = 26;
private static final byte COMMAND_ON[] = { (byte) 0x42, (byte) 0x45, (byte) 0x47, (byte) 0x49, (byte) 0x4B };
private static final byte COMMAND_OFF[] = { (byte) 0x41, (byte) 0x46, (byte) 0x48, (byte) 0x4A, (byte) 0x4C };
private static final byte COMMAND_WHITEMODE[] = { (byte) 0xC2, (byte) 0xC5, (byte) 0xC7, (byte) 0xC9, (byte) 0xCB };
private static final byte NIGHTMODE_FIRST[] = { 0x41, 0x46, 0x48, 0x4A, 0x4C };
private static final byte NIGHTMODE_SECOND[] = { (byte) 0xC1, (byte) 0xC6, (byte) 0xC8, (byte) 0xCA, (byte) 0xCC };
private static final byte NEXT_ANIMATION_MODE[] = { 0x4D, 0x00, 0x55 };
private static final byte[] COMMAND_ON = { (byte) 0x42, (byte) 0x45, (byte) 0x47, (byte) 0x49, (byte) 0x4B };
private static final byte[] COMMAND_OFF = { (byte) 0x41, (byte) 0x46, (byte) 0x48, (byte) 0x4A, (byte) 0x4C };
private static final byte[] COMMAND_WHITEMODE = { (byte) 0xC2, (byte) 0xC5, (byte) 0xC7, (byte) 0xC9, (byte) 0xCB };
private static final byte[] NIGHTMODE_FIRST = { 0x41, 0x46, 0x48, 0x4A, 0x4C };
private static final byte[] NIGHTMODE_SECOND = { (byte) 0xC1, (byte) 0xC6, (byte) 0xC8, (byte) 0xCA, (byte) 0xCC };
private static final byte[] NEXT_ANIMATION_MODE = { 0x4D, 0x00, 0x55 };
public MilightV3RGBWHandler(Thing thing, QueuedSend sendQueue) {
super(thing, sendQueue, 10);
@@ -45,8 +45,8 @@ public class MilightV3RGBWHandler extends AbstractLedV3Handler {
whiteMode(state);
} else {
state.hue360 = hue;
final byte messageBytes[] = new byte[] { 0x40, makeColor(hue), 0x55 };
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] messageBytes = new byte[] { 0x40, makeColor(hue), 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_COLOR_SET), cOn).addRepeatable(messageBytes));
}
@@ -68,15 +68,15 @@ public class MilightV3RGBWHandler extends AbstractLedV3Handler {
@Override
public void whiteMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte cWhite[] = { COMMAND_WHITEMODE[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cWhite = { COMMAND_WHITEMODE[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_WHITEMODE), cOn).addRepeatable(cWhite));
}
@Override
public void nightMode(MilightThingState state) {
final byte cN1[] = { NIGHTMODE_FIRST[config.zone], 0x00, 0x55 };
final byte cN2[] = { NIGHTMODE_SECOND[config.zone], 0x00, 0x55 };
final byte[] cN1 = { NIGHTMODE_FIRST[config.zone], 0x00, 0x55 };
final byte[] cN2 = { NIGHTMODE_SECOND[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_POWER_MODE), cN1).addRepeatable(cN2));
}
@@ -101,7 +101,7 @@ public class MilightV3RGBWHandler extends AbstractLedV3Handler {
int br = (int) Math.ceil((value * BRIGHTNESS_LEVELS) / 100.0) + 1;
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_BRIGHTNESS_SET), cOn)
.addRepeatable(new byte[] { 0x4E, (byte) br, 0x55 }));
@@ -119,8 +119,8 @@ public class MilightV3RGBWHandler extends AbstractLedV3Handler {
return;
}
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte cSpeed[] = { (byte) (relativeSpeed > 0 ? 0x44 : 0x43), 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cSpeed = { (byte) (relativeSpeed > 0 ? 0x44 : 0x43), 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(cSpeed));
}
@@ -128,14 +128,14 @@ public class MilightV3RGBWHandler extends AbstractLedV3Handler {
// instead.
@Override
public void previousAnimationMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(NEXT_ANIMATION_MODE));
state.animationMode = (state.animationMode + 1) % (MAX_ANIM_MODES + 1);
}
@Override
public void nextAnimationMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(NEXT_ANIMATION_MODE));
state.animationMode = (state.animationMode + 1) % (MAX_ANIM_MODES + 1);
}

View File

@@ -33,12 +33,12 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
super(thing, sendQueue, 0);
}
private static final byte COMMAND_FULL[] = { (byte) 0xB5, (byte) 0xB8, (byte) 0xBD, (byte) 0xB7, (byte) 0xB2 };
private static final byte COMMAND_ON[] = { (byte) 0x35, (byte) 0x38, (byte) 0x3D, (byte) 0x37, (byte) 0x32 };
private static final byte COMMAND_OFF[] = { (byte) 0x39, (byte) 0x3B, (byte) 0x33, (byte) 0x3A, (byte) 0x36 };
private static final byte COMMAND_NIGHTMODE[] = { (byte) 0xB9, (byte) 0xBB, (byte) 0xB3, (byte) 0xBA, (byte) 0xB6 };
private static final byte PREV_ANIMATION_MODE[] = { 0x27, 0x00, 0x55 };
private static final byte NEXT_ANIMATION_MODE[] = { 0x27, 0x00, 0x55 };
private static final byte[] COMMAND_FULL = { (byte) 0xB5, (byte) 0xB8, (byte) 0xBD, (byte) 0xB7, (byte) 0xB2 };
private static final byte[] COMMAND_ON = { (byte) 0x35, (byte) 0x38, (byte) 0x3D, (byte) 0x37, (byte) 0x32 };
private static final byte[] COMMAND_OFF = { (byte) 0x39, (byte) 0x3B, (byte) 0x33, (byte) 0x3A, (byte) 0x36 };
private static final byte[] COMMAND_NIGHTMODE = { (byte) 0xB9, (byte) 0xBB, (byte) 0xB3, (byte) 0xBA, (byte) 0xB6 };
private static final byte[] PREV_ANIMATION_MODE = { 0x27, 0x00, 0x55 };
private static final byte[] NEXT_ANIMATION_MODE = { 0x27, 0x00, 0x55 };
protected void setFull(int zone, MilightThingState state) {
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_BRIGHTNESS_SET),
@@ -72,8 +72,8 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
@Override
public void nightMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte cNight[] = { COMMAND_NIGHTMODE[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cNight = { COMMAND_NIGHTMODE[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_POWER_MODE), cOn).addRepeatable(cNight));
}
@@ -113,8 +113,8 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
@Override
public void changeColorTemperature(int colorTempRelative, MilightThingState state) {
state.colorTemperature = Math.min(100, Math.max(state.colorTemperature + colorTempRelative, 0));
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte cTemp[] = { (byte) (colorTempRelative > 0 ? 0x3E : 0x3F), 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cTemp = { (byte) (colorTempRelative > 0 ? 0x3E : 0x3F), 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(cTemp));
}
@@ -134,7 +134,7 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
// When turning on start from full brightness
int oldLevel;
final byte cFull[] = { COMMAND_FULL[config.zone], 0x00, 0x55 };
final byte[] cFull = { COMMAND_FULL[config.zone], 0x00, 0x55 };
QueueItem item = createRepeatable(cFull);
boolean skipFirst = false;
@@ -155,7 +155,7 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
String.valueOf(value), repeatCount);
int op = newLevel > oldLevel ? +1 : -1;
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
for (int i = 0; i < repeatCount; i++) {
final byte[] cBr = { (byte) (op < 0 ? 0x34 : 0x3C), 0x00, 0x55 };
item = item.addRepeatable(cOn).addNonRepeatable(cBr);
@@ -182,8 +182,8 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
sendQueue.queue(createRepeatable(uidc(ProtocolConstants.CAT_POWER_MODE),
new byte[] { COMMAND_OFF[config.zone], 0x00, 0x55 }));
} else {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte cBr[] = { (byte) (relativeBrightness < 0 ? 0x34 : 0x3C), 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cBr = { (byte) (relativeBrightness < 0 ? 0x34 : 0x3C), 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(cBr));
}
}
@@ -194,14 +194,14 @@ public class MilightV3WhiteHandler extends AbstractLedV3Handler {
@Override
public void previousAnimationMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(PREV_ANIMATION_MODE));
state.animationMode = Math.max(state.animationMode - 1, 0);
}
@Override
public void nextAnimationMode(MilightThingState state) {
final byte cOn[] = { COMMAND_ON[config.zone], 0x00, 0x55 };
final byte[] cOn = { COMMAND_ON[config.zone], 0x00, 0x55 };
sendQueue.queue(createRepeatable(cOn).addNonRepeatable(NEXT_ANIMATION_MODE));
state.animationMode = Math.min(state.animationMode + 1, MAX_ANIM_MODES);
}

View File

@@ -64,10 +64,10 @@ public class MilightV6SessionManager implements Runnable, Closeable {
private int sequenceNo = 0;
// Password bytes 1 and 2
public byte pw[] = { 0, 0 };
public byte[] pw = { 0, 0 };
// Session bytes 1 and 2
public byte sid[] = { 0, 0 };
public byte[] sid = { 0, 0 };
// Client session bytes 1 and 2. Those are fixed for now.
public final byte clientSID1 = (byte) 0xab;

View File

@@ -47,29 +47,29 @@ public class EmulatedV6Bridge {
(byte) 0xD4 };
// Send to the network by clients to find V6 bridges
private byte searchBroadcast[] = new byte[] { 0x10, 0, 0, 0, 0x24, 0x02, cls1, cls2, 0x02, 0x39, 0x38, 0x35, 0x62,
private byte[] searchBroadcast = new byte[] { 0x10, 0, 0, 0, 0x24, 0x02, cls1, cls2, 0x02, 0x39, 0x38, 0x35, 0x62,
0x31, 0x35, 0x37, 0x62, 0x66, 0x36, 0x66, 0x63, 0x34, 0x33, 0x33, 0x36, 0x38, 0x61, 0x36, 0x33, 0x34, 0x36,
0x37, 0x65, 0x61, 0x33, 0x62, 0x31, 0x39, 0x64, 0x30, 0x64 };
// Send to broadcast address by the client usually and used to test if the client with the contained bridge id
// is present on the network. If the IP of the bridge is known already, then SESSION_REQUEST is used usually.
private byte sessionRequestFindBroadcast[] = new byte[] { 0x10, 0, 0, 0, 0x0A, 2, cls1, cls2, 1, FAKE_MAC[0],
private byte[] sessionRequestFindBroadcast = new byte[] { 0x10, 0, 0, 0, 0x0A, 2, cls1, cls2, 1, FAKE_MAC[0],
FAKE_MAC[1], FAKE_MAC[2], FAKE_MAC[3], FAKE_MAC[4], FAKE_MAC[5] };
// Some clients send this as first command to get a session id, especially if the bridge IP is already known.
private byte sessionRequest[] = new byte[] { (byte) 0x20, 0, 0, 0, (byte) 0x16, 2, (byte) 0x62, (byte) 0x3A,
private byte[] sessionRequest = new byte[] { (byte) 0x20, 0, 0, 0, (byte) 0x16, 2, (byte) 0x62, (byte) 0x3A,
(byte) 0xD5, (byte) 0xED, (byte) 0xA3, 1, (byte) 0xAE, (byte) 0x08, (byte) 0x2D, (byte) 0x46, (byte) 0x61,
(byte) 0x41, (byte) 0xA7, (byte) 0xF6, (byte) 0xDC, (byte) 0xAF, cls1, cls2, 0, 0, (byte) 0x1E };
private byte sessionResponse[] = { (byte) 0x28, 0, 0, 0, (byte) 0x11, 0, 2, (byte) 0xAC, (byte) 0xCF, (byte) 0x23,
private byte[] sessionResponse = { (byte) 0x28, 0, 0, 0, (byte) 0x11, 0, 2, (byte) 0xAC, (byte) 0xCF, (byte) 0x23,
(byte) 0xF5, (byte) 0x7A, (byte) 0xD4, (byte) 0x69, (byte) 0xF0, (byte) 0x3C, (byte) 0x23, 0, 1, SID1, SID2,
0 };
// Some clients call this as second command to establish a session.
private static final byte ESTABLISH_SESSION_REQUEST[] = new byte[] { (byte) 0x30, 0, 0, 0, 3, SID1, SID2, 0 };
private static final byte[] ESTABLISH_SESSION_REQUEST = new byte[] { (byte) 0x30, 0, 0, 0, 3, SID1, SID2, 0 };
// In response to SEARCH, ESTABLISH_SESSION_REQUEST but also to SESSION_REQUEST_FIND_BROADCAST
private static final byte REESTABLISH_SESSION_RESPONSE[] = new byte[] { (byte) 0x18, 0, 0, 0, (byte) 0x40, 2,
private static final byte[] REESTABLISH_SESSION_RESPONSE = new byte[] { (byte) 0x18, 0, 0, 0, (byte) 0x40, 2,
FAKE_MAC[0], FAKE_MAC[1], FAKE_MAC[2], FAKE_MAC[3], FAKE_MAC[4], FAKE_MAC[5], 0, (byte) 0x20, (byte) 0x39,
(byte) 0x38, (byte) 0x35, (byte) 0x62, (byte) 0x31, (byte) 0x35, (byte) 0x37, (byte) 0x62, (byte) 0x66,
(byte) 0x36, (byte) 0x66, (byte) 0x63, (byte) 0x34, (byte) 0x33, (byte) 0x33, (byte) 0x36, (byte) 0x38,
@@ -79,11 +79,11 @@ public class EmulatedV6Bridge {
(byte) 0x6E, (byte) 0x6B, (byte) 0x5F, (byte) 0x64, (byte) 0x65, (byte) 0x76, (byte) 0x07, (byte) 0x5B,
(byte) 0xCD, (byte) 0x15 };
private static final byte REGISTRATION_REQUEST[] = { (byte) 0x80, 0, 0, 0, 0x11, SID1, SID2, SEQ1, SEQ2, 0, 0x33,
private static final byte[] REGISTRATION_REQUEST = { (byte) 0x80, 0, 0, 0, 0x11, SID1, SID2, SEQ1, SEQ2, 0, 0x33,
PW1, PW2, 0, 0, 0, 0, 0, 0, 0, 0, 0x33 };
// 80:00:00:00:15:(f0:fe:6b:16:b0:8a):05:02:00:34:00:00:00:00:00:00:00:00:00:00:34
private static final byte REGISTRATION_REQUEST_RESPONSE[] = { (byte) 0x80, 0, 0, 0, 0x15, FAKE_MAC[0], FAKE_MAC[1],
private static final byte[] REGISTRATION_REQUEST_RESPONSE = { (byte) 0x80, 0, 0, 0, 0x15, FAKE_MAC[0], FAKE_MAC[1],
FAKE_MAC[2], FAKE_MAC[3], FAKE_MAC[4], FAKE_MAC[5], 5, 2, 0, 0x34, PW1, PW2, 0, 0, 0, 0, 0, 0, 0, 0, 0x34 };
private static final byte[] KEEP_ALIVE_REQUEST = { (byte) 0xD0, 0, 0, 0, 2, SID1, SID2 };
@@ -96,7 +96,7 @@ public class EmulatedV6Bridge {
new Thread(this::runBrigde).start();
}
private void replaceWithMac(byte data[], int offset) {
private void replaceWithMac(byte[] data, int offset) {
data[offset + 0] = FAKE_MAC[0];
data[offset + 1] = FAKE_MAC[1];
data[offset + 2] = FAKE_MAC[2];
@@ -106,7 +106,7 @@ public class EmulatedV6Bridge {
}
public void runDiscovery() {
final byte discover[] = "HF-A11ASSISTHREAD".getBytes();
final byte[] discover = "HF-A11ASSISTHREAD".getBytes();
try {
byte[] a = new byte[0];
@@ -286,7 +286,7 @@ public class EmulatedV6Bridge {
debugStr.append("iBox ");
}
debugStr.append("Zone " + String.valueOf(buffer[19]) + " ");
debugStr.append("Zone " + buffer[19] + " ");
for (int i = 13; i < 19; ++i) {
debugStr.append(String.format("%02X ", buffer[i]));
@@ -295,7 +295,7 @@ public class EmulatedV6Bridge {
}
}
byte response[] = { (byte) 0x88, 0, 0, 0, (byte) 0x03, 0, seq, 0 };
byte[] response = { (byte) 0x88, 0, 0, 0, (byte) 0x03, 0, seq, 0 };
sendMessage(sPacket, datagramSocket, response);
continue;
}
@@ -320,7 +320,7 @@ public class EmulatedV6Bridge {
logger.error("{}: {}", reason, s);
}
protected void sendMessage(DatagramPacket packet, DatagramSocket datagramSocket, byte buffer[]) {
protected void sendMessage(DatagramPacket packet, DatagramSocket datagramSocket, byte[] buffer) {
packet.setData(buffer);
try {
datagramSocket.send(packet);
@@ -330,7 +330,7 @@ public class EmulatedV6Bridge {
}
}
private void debugSessionSend(byte buffer[], InetAddress address) {
private void debugSessionSend(byte[] buffer, InetAddress address) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < buffer.length; ++i) {
s.append(String.format("%02X ", buffer[i]));