Skip to content

Commit

Permalink
[lutron] Update field names to eliminate SCA warnings (openhab#8089)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Adair <bob.github@att.net>
  • Loading branch information
bobadair authored and andrewfg committed Aug 31, 2020
1 parent 9360897 commit be6ad35
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ public class GrafikEyeHandler extends BaseThingHandler {
/**
* Cached instance of the {@link GrafikEyeConfig}. Will be null if disconnected.
*/
private GrafikEyeConfig _config = null;
private GrafikEyeConfig config = null;

/**
* The current fade for the grafik eye (only used when setting zone intensity). Will initially be set from
* configuration.
*/
private int _fade = 0;
private int fade = 0;

/**
* The polling job to poll the actual state of the grafik eye
*/
private ScheduledFuture<?> _polling;
private ScheduledFuture<?> pollingJob;

/**
* Constructs the handler from the {@link org.eclipse.smarthome.core.thing.Thing}
Expand Down Expand Up @@ -109,28 +109,28 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (id.equals(PrgConstants.CHANNEL_SCENE)) {
if (command instanceof DecimalType) {
final int scene = ((DecimalType) command).intValue();
getProtocolHandler().selectScene(_config.getControlUnit(), scene);
getProtocolHandler().selectScene(config.getControlUnit(), scene);
} else {
logger.error("Received a SCENE command with a non DecimalType: {}", command);
}

} else if (id.equals(PrgConstants.CHANNEL_SCENELOCK)) {
if (command instanceof OnOffType) {
getProtocolHandler().setSceneLock(_config.getControlUnit(), command == OnOffType.ON);
getProtocolHandler().setSceneLock(config.getControlUnit(), command == OnOffType.ON);
} else {
logger.error("Received a SCENELOCK command with a non OnOffType: {}", command);
}

} else if (id.equals(PrgConstants.CHANNEL_SCENESEQ)) {
if (command instanceof OnOffType) {
getProtocolHandler().setSceneSequence(_config.getControlUnit(), command == OnOffType.ON);
getProtocolHandler().setSceneSequence(config.getControlUnit(), command == OnOffType.ON);
} else {
logger.error("Received a SCENESEQ command with a non OnOffType: {}", command);
}

} else if (id.equals(PrgConstants.CHANNEL_ZONELOCK)) {
if (command instanceof OnOffType) {
getProtocolHandler().setZoneLock(_config.getControlUnit(), command == OnOffType.ON);
getProtocolHandler().setZoneLock(config.getControlUnit(), command == OnOffType.ON);
} else {
logger.error("Received a ZONELOCK command with a non OnOffType: {}", command);
}
Expand All @@ -139,20 +139,19 @@ public void handleCommand(ChannelUID channelUID, Command command) {
final Integer zone = getTrailingNbr(id, PrgConstants.CHANNEL_ZONELOWER);

if (zone != null) {
getProtocolHandler().setZoneLower(_config.getControlUnit(), zone);
getProtocolHandler().setZoneLower(config.getControlUnit(), zone);
}

} else if (id.startsWith(PrgConstants.CHANNEL_ZONERAISE)) {
final Integer zone = getTrailingNbr(id, PrgConstants.CHANNEL_ZONERAISE);

if (zone != null) {
getProtocolHandler().setZoneRaise(_config.getControlUnit(), zone);
getProtocolHandler().setZoneRaise(config.getControlUnit(), zone);
}

} else if (id.equals(PrgConstants.CHANNEL_ZONEFADE)) {
if (command instanceof DecimalType) {
final int fade = ((DecimalType) command).intValue();
setFade(fade);
setFade(((DecimalType) command).intValue());
} else {
logger.error("Received a ZONEFADE command with a non DecimalType: {}", command);
}
Expand All @@ -163,12 +162,12 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (zone != null) {
if (command instanceof PercentType) {
final int intensity = ((PercentType) command).intValue();
getProtocolHandler().setZoneIntensity(_config.getControlUnit(), zone, _fade, intensity);
getProtocolHandler().setZoneIntensity(config.getControlUnit(), zone, fade, intensity);
} else if (command instanceof OnOffType) {
getProtocolHandler().setZoneIntensity(_config.getControlUnit(), zone, _fade,
getProtocolHandler().setZoneIntensity(config.getControlUnit(), zone, fade,
command == OnOffType.ON ? 100 : 0);
} else if (command instanceof IncreaseDecreaseType) {
getProtocolHandler().setZoneIntensity(_config.getControlUnit(), zone, _fade,
getProtocolHandler().setZoneIntensity(config.getControlUnit(), zone, fade,
command == IncreaseDecreaseType.INCREASE);
} else {
logger.error("Received a ZONEINTENSITY command with a non DecimalType: {}", command);
Expand All @@ -184,9 +183,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
} else if (command == StopMoveType.MOVE) {
logger.info("StopMoveType.Move is not suppored by QED shades");
} else if (command == StopMoveType.STOP) {
getProtocolHandler().setZoneIntensity(_config.getControlUnit(), zone, _fade, 0);
getProtocolHandler().setZoneIntensity(config.getControlUnit(), zone, fade, 0);
} else if (command instanceof UpDownType) {
getProtocolHandler().setZoneIntensity(_config.getControlUnit(), zone, _fade,
getProtocolHandler().setZoneIntensity(config.getControlUnit(), zone, fade,
command == UpDownType.UP ? 1 : 2);
} else {
logger.error("Received a ZONEINTENSITY command with a non DecimalType: {}", command);
Expand All @@ -213,9 +212,9 @@ private void handleRefresh(String id) {
getProtocolHandler().refreshScene();

} else if (id.equals(PrgConstants.CHANNEL_ZONEINTENSITY)) {
getProtocolHandler().refreshZoneIntensity(_config.getControlUnit());
getProtocolHandler().refreshZoneIntensity(config.getControlUnit());
} else if (id.equals(PrgConstants.CHANNEL_ZONEFADE)) {
updateState(PrgConstants.CHANNEL_ZONEFADE, new DecimalType(_fade));
updateState(PrgConstants.CHANNEL_ZONEFADE, new DecimalType(fade));
}
}

Expand Down Expand Up @@ -274,14 +273,14 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
* starts a status refresh job
*/
private void internalInitialize() {
_config = getThing().getConfiguration().as(GrafikEyeConfig.class);
config = getThing().getConfiguration().as(GrafikEyeConfig.class);

if (_config == null) {
if (config == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Configuration file missing");
return;
}

final String configErr = _config.validate();
final String configErr = config.validate();
if (configErr != null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, configErr);
return;
Expand All @@ -301,27 +300,27 @@ private void internalInitialize() {
}

updateStatus(ThingStatus.ONLINE);
setFade(_config.getFade());
setFade(config.getFade());

cancelPolling();
_polling = this.scheduler.scheduleWithFixedDelay(new Runnable() {
pollingJob = this.scheduler.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
final ThingStatus status = getThing().getStatus();
if (status == ThingStatus.ONLINE && _config != null) {
getProtocolHandler().refreshState(_config.getControlUnit());
if (status == ThingStatus.ONLINE && config != null) {
getProtocolHandler().refreshState(config.getControlUnit());
}
}
}, 1, _config.getPolling(), TimeUnit.SECONDS);
}, 1, config.getPolling(), TimeUnit.SECONDS);
}

/**
* Helper method to cancel our polling if we are currently polling
*/
private void cancelPolling() {
if (_polling != null) {
_polling.cancel(true);
_polling = null;
if (pollingJob != null) {
pollingJob.cancel(true);
pollingJob = null;
}
}

Expand Down Expand Up @@ -349,7 +348,7 @@ private PrgProtocolHandler getProtocolHandler() {
* @return the control unit
*/
int getControlUnit() {
return _config.getControlUnit();
return config.getControlUnit();
}

/**
Expand All @@ -360,7 +359,7 @@ int getControlUnit() {
* @return true if a shade zone, false otherwise
*/
boolean isShade(int zone) {
return _config == null ? false : _config.isShadeZone(zone);
return config == null ? false : config.isShadeZone(zone);
}

/**
Expand All @@ -383,7 +382,7 @@ private void setFade(int fade) {
throw new IllegalArgumentException("fade must be between 1-3600");
}

_fade = fade;
updateState(PrgConstants.CHANNEL_ZONEFADE, new DecimalType(_fade));
this.fade = fade;
updateState(PrgConstants.CHANNEL_ZONEFADE, new DecimalType(this.fade));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public class PrgBridgeHandler extends BaseBridgeHandler {
/**
* The {@link PrgProtocolHandler} that handles the actual protocol. Will never be null
*/
private PrgProtocolHandler _protocolHandler;
private PrgProtocolHandler protocolHandler;

/**
* The {@link SocketSession} to the physical devices. Will never be null
*/
private SocketSession _session;
private SocketSession session;

/**
* The retry connection event. Null if not retrying.
*/
private ScheduledFuture<?> _retryConnection;
private ScheduledFuture<?> retryConnectionJob;

/**
* Constructs the handler from the {@link Bridge}. Simply calls the super constructor with the {@link Bridge},
Expand All @@ -71,9 +71,9 @@ public PrgBridgeHandler(Bridge bridge) {
}

final PrgBridgeConfig config = getPrgBridgeConfig();
_session = new SocketSession(config.getIpAddress(), 23);
session = new SocketSession(config.getIpAddress(), 23);

_protocolHandler = new PrgProtocolHandler(_session, new PrgHandlerCallback() {
protocolHandler = new PrgProtocolHandler(session, new PrgHandlerCallback() {
@Override
public void stateChanged(String channelId, State state) {
updateState(channelId, state);
Expand Down Expand Up @@ -106,7 +106,7 @@ public boolean isShade(int controlUnit, int zone) {
* @return a non-null protocol handler to use
*/
PrgProtocolHandler getProtocolHandler() {
return _protocolHandler;
return protocolHandler;
}

/**
Expand Down Expand Up @@ -161,33 +161,33 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}

if (id.equals(PrgConstants.CHANNEL_ZONELOWERSTOP)) {
_protocolHandler.setZoneLowerStop();
protocolHandler.setZoneLowerStop();

} else if (id.equals(PrgConstants.CHANNEL_ZONERAISESTOP)) {
_protocolHandler.setZoneRaiseStop();
protocolHandler.setZoneRaiseStop();

} else if (id.equals(PrgConstants.CHANNEL_TIMECLOCK)) {
if (command instanceof DateTimeType) {
final ZonedDateTime zdt = ((DateTimeType) command).getZonedDateTime();
_protocolHandler.setTime(GregorianCalendar.from(zdt));
protocolHandler.setTime(GregorianCalendar.from(zdt));
} else {
logger.error("Received a TIMECLOCK channel command with a non DateTimeType: {}", command);
}
} else if (id.startsWith(PrgConstants.CHANNEL_SCHEDULE)) {
if (command instanceof DecimalType) {
final int schedule = ((DecimalType) command).intValue();
_protocolHandler.selectSchedule(schedule);
protocolHandler.selectSchedule(schedule);
} else {
logger.error("Received a SCHEDULE channel command with a non DecimalType: {}", command);
}

} else if (id.startsWith(PrgConstants.CHANNEL_SUPERSEQUENCESTART)) {
_protocolHandler.startSuperSequence();
protocolHandler.startSuperSequence();

} else if (id.startsWith(PrgConstants.CHANNEL_SUPERSEQUENCEPAUSE)) {
_protocolHandler.pauseSuperSequence();
protocolHandler.pauseSuperSequence();
} else if (id.startsWith(PrgConstants.CHANNEL_SUPERSEQUENCERESUME)) {
_protocolHandler.resumeSuperSequence();
protocolHandler.resumeSuperSequence();

} else {
logger.error("Unknown/Unsupported Channel id: {}", id);
Expand All @@ -206,25 +206,25 @@ private void handleRefresh(String id) {
}

if (id.equals(PrgConstants.CHANNEL_TIMECLOCK)) {
_protocolHandler.refreshTime();
protocolHandler.refreshTime();

} else if (id.equals(PrgConstants.CHANNEL_SCHEDULE)) {
_protocolHandler.refreshSchedule();
protocolHandler.refreshSchedule();

} else if (id.equals(PrgConstants.CHANNEL_SUNRISE)) {
_protocolHandler.refreshSunriseSunset();
protocolHandler.refreshSunriseSunset();

} else if (id.equals(PrgConstants.CHANNEL_SUNSET)) {
_protocolHandler.refreshSunriseSunset();
protocolHandler.refreshSunriseSunset();

} else if (id.equals(PrgConstants.CHANNEL_SUPERSEQUENCESTATUS)) {
_protocolHandler.reportSuperSequenceStatus();
protocolHandler.reportSuperSequenceStatus();
} else if (id.equals(PrgConstants.CHANNEL_SUPERSEQUENCENEXTSTEP)) {
_protocolHandler.reportSuperSequenceStatus();
protocolHandler.reportSuperSequenceStatus();
} else if (id.equals(PrgConstants.CHANNEL_SUPERSEQUENCENEXTMIN)) {
_protocolHandler.reportSuperSequenceStatus();
protocolHandler.reportSuperSequenceStatus();
} else if (id.equals(PrgConstants.CHANNEL_SUPERSEQUENCENEXTSEC)) {
_protocolHandler.reportSuperSequenceStatus();
protocolHandler.reportSuperSequenceStatus();
}
}

Expand Down Expand Up @@ -268,9 +268,9 @@ private void connect() {
String response = "Server is offline - will try to reconnect later";
try {
logger.info("Attempting connection ...");
_session.connect();
session.connect();

response = _protocolHandler.login(config.getUserName());
response = protocolHandler.login(config.getUserName());
if (response == null) {
if (config != null) {
updateStatus(ThingStatus.ONLINE);
Expand All @@ -293,7 +293,7 @@ private void connect() {
*/
private void disconnect(boolean retryConnection) {
try {
_session.disconnect();
session.disconnect();
} catch (IOException e) {
// ignore - we don't care
}
Expand All @@ -308,14 +308,14 @@ private void disconnect(boolean retryConnection) {
* call the {@link #connect()} method. If a retry attempt is pending, the request is ignored.
*/
private void retryConnect() {
if (_retryConnection == null) {
if (retryConnectionJob == null) {
final PrgBridgeConfig config = getPrgBridgeConfig();
if (config != null) {
logger.info("Will try to reconnect in {} seconds", config.getRetryPolling());
_retryConnection = this.scheduler.schedule(new Runnable() {
retryConnectionJob = this.scheduler.schedule(new Runnable() {
@Override
public void run() {
_retryConnection = null;
retryConnectionJob = null;
connect();
}
}, config.getRetryPolling(), TimeUnit.SECONDS);
Expand Down
Loading

0 comments on commit be6ad35

Please sign in to comment.