Skip to content

Commit

Permalink
[ZoneMinder] Use DS annotations, fix static code analysis findings (o…
Browse files Browse the repository at this point in the history
…penhab#3382)

Signed-off-by: Wouter Born <[email protected]>
Signed-off-by: Maximilian Hess <[email protected]>
  • Loading branch information
wborn authored and ne0h committed Sep 15, 2019
1 parent 26e2c2d commit 87e5ef9
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
Automatic-Module-Name: org.openhab.binding.zoneminder
Bundle-ActivationPolicy: lazy
Bundle-ClassPath:
.,
lib/gson-2.7.jar,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ZoneMinderConstants {
// Parameters for the ZoneMinder Server
public static final String PARAM_HOSTNAME = "hostname";
public static final String PARAM_PORT = "port";
public static final String PARAM_REFRESH_INTERVAL_ = "refresh_interval";
public static final String PARAM_REFRESH_INTERVAL = "refresh_interval";
public static final String PARAM_REFRESH_INTERVAL_DISKUSAGE = "refresh_interval_disk_usage";

// Default values for Monitor parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,29 @@
public abstract class ZoneMinderBaseThingHandler extends BaseThingHandler implements ZoneMinderHandler {

/** Logger for the Thing. */
private Logger logger = LoggerFactory.getLogger(ZoneMinderBaseThingHandler.class);
private final Logger logger = LoggerFactory.getLogger(ZoneMinderBaseThingHandler.class);

/** Bridge Handler for the Thing. */
public ZoneMinderServerBridgeHandler zoneMinderBridgeHandler = null;
public ZoneMinderServerBridgeHandler zoneMinderBridgeHandler;

/** This refresh status. */
private boolean thingRefreshed = false;
private boolean thingRefreshed;

/** Unique Id of the thing in zoneminder. */
private String zoneMinderId;

/** ZoneMidner ConnectionInfo */
private IZoneMinderConnectionInfo zoneMinderConnection = null;
private IZoneMinderConnectionInfo zoneMinderConnection;

private Lock lockSession = new ReentrantLock();
private IZoneMinderSession zoneMinderSession = null;
private IZoneMinderSession zoneMinderSession;

/** Configuration from openHAB */
protected ZoneMinderThingConfig configuration;

private DataRefreshPriorityEnum _refreshPriority = DataRefreshPriorityEnum.SCHEDULED;
private DataRefreshPriorityEnum refreshPriority = DataRefreshPriorityEnum.SCHEDULED;

protected boolean isOnline() {

if (zoneMinderSession == null) {
return false;
}
Expand All @@ -89,7 +88,7 @@ protected boolean isOnline() {
}

public DataRefreshPriorityEnum getRefreshPriority() {
return _refreshPriority;
return refreshPriority;
}

public ZoneMinderBaseThingHandler(Thing thing) {
Expand All @@ -104,15 +103,7 @@ public ZoneMinderBaseThingHandler(Thing thing) {
*/
@Override
public void initialize() {

updateStatus(ThingStatus.ONLINE);
try {

} catch (Exception ex) {
logger.error("{}: BridgeHandler failed to initialize. Exception='{}'", getLogIdentifier(), ex.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR);
} finally {
}
}

protected boolean isConnected() {
Expand All @@ -136,9 +127,8 @@ protected void releaseSession() {
*/

protected boolean startPriorityRefresh() {

logger.info("[MONITOR-{}]: Starting High Priority Refresh", getZoneMinderId());
_refreshPriority = DataRefreshPriorityEnum.HIGH_PRIORITY;
refreshPriority = DataRefreshPriorityEnum.HIGH_PRIORITY;
return true;
}

Expand All @@ -147,12 +137,11 @@ protected boolean startPriorityRefresh() {
*/
protected void stopPriorityRefresh() {
logger.info("{}: Stopping Priority Refresh for Monitor", getLogIdentifier());
_refreshPriority = DataRefreshPriorityEnum.SCHEDULED;
refreshPriority = DataRefreshPriorityEnum.SCHEDULED;
}

@Override
public void dispose() {

}

/**
Expand All @@ -170,7 +159,6 @@ public ChannelUID getChannelUIDFromChannelId(String id) {
* Method to Refresh Thing Handler.
*/
public final synchronized void refreshThing(IZoneMinderSession session, DataRefreshPriorityEnum refreshPriority) {

if ((refreshPriority != getRefreshPriority()) && (!isConnected())) {
return;
}
Expand All @@ -183,7 +171,6 @@ public final synchronized void refreshThing(IZoneMinderSession session, DataRefr

if (getZoneMinderBridgeHandler() != null) {
if (isConnected()) {

logger.debug("{}: refreshThing(): Bridge '{}' Found for Thing '{}'!", getLogIdentifier(),
getThing().getUID(), this.getThing().getUID());

Expand All @@ -201,7 +188,6 @@ public final synchronized void refreshThing(IZoneMinderSession session, DataRefr

this.setThingRefreshed(true);
logger.debug("[{}: refreshThing(): Thing Refreshed - {}", getLogIdentifier(), thing.getUID());

}

/**
Expand All @@ -210,9 +196,7 @@ public final synchronized void refreshThing(IZoneMinderSession session, DataRefr
* @return zoneMinderBridgeHandler
*/
public synchronized ZoneMinderServerBridgeHandler getZoneMinderBridgeHandler() {

if (this.zoneMinderBridgeHandler == null) {

Bridge bridge = getBridge();

if (bridge == null) {
Expand Down Expand Up @@ -247,8 +231,6 @@ public synchronized ZoneMinderServerBridgeHandler getZoneMinderBridgeHandler() {
*/
@Override
public void updateChannel(ChannelUID channel) {
OnOffType onOffType;

switch (channel.getId()) {
case ZoneMinderConstants.CHANNEL_ONLINE:
updateState(channel, getChannelBoolAsOnOffState(isOnline()));
Expand Down Expand Up @@ -278,20 +260,16 @@ public void onBridgeConnected(ZoneMinderServerBridgeHandler bridge, IZoneMinderC

@Override
public void onBridgeDisconnected(ZoneMinderServerBridgeHandler bridge) {

if (bridge.getThing().getUID().equals(getThing().getBridgeUID())) {

this.setThingRefreshed(false);
}

lockSession.lock();
try {
zoneMinderSession = null;

} finally {
lockSession.unlock();
}

}

/**
Expand Down Expand Up @@ -399,13 +377,11 @@ protected State getChannelBoolAsOnOffState(boolean value) {

protected void updateThingStatus(ThingStatus thingStatus, ThingStatusDetail statusDetail,
String statusDescription) {

ThingStatusInfo curStatusInfo = thing.getStatusInfo();
String curDescription = ((curStatusInfo.getDescription() == null) ? "" : curStatusInfo.getDescription());
// Status changed
if ((curStatusInfo.getStatus() != thingStatus) || (curStatusInfo.getStatusDetail() != statusDetail)
|| (curDescription != statusDescription)) {

// Update Status correspondingly
if ((thingStatus == ThingStatus.OFFLINE) && (statusDetail != ThingStatusDetail.NONE)) {
logger.info("{}: Thing status changed from '{}' to '{}' (DetailedStatus='{}', Description='{}')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Interface for ZoneMinder handlers.
*
* @author Martin S. Eskildsen
* @author Martin S. Eskildsen - Initial contribution
*/
public interface ZoneMinderHandler {

Expand Down
Loading

0 comments on commit 87e5ef9

Please sign in to comment.