Skip to content

Commit

Permalink
[openwebnet] added Thing status detail when bridge is offline
Browse files Browse the repository at this point in the history
Signed-off-by: Massimo Valla <[email protected]>
  • Loading branch information
mvalla committed Feb 6, 2023
1 parent 9e75294 commit d5fc81d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void onEventMessage(@Nullable OpenMessage msg) {
|| (discoveryByActivation && !scanIsActive))) {
discoverByActivation(baseMsg);
} else {
logger.debug("ownId={} has NO DEVICE associated, ignoring it", ownId);
logger.debug("ownId={} has NO DEVICE associated to bridge {}: ignoring it", ownId, thing.getUID());
}
} else {
deviceHandler.handleMessage(baseMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
import org.slf4j.LoggerFactory;

/**
* The {@link OpenWebNetThingHandler} is responsible for handling commands for an OpenWebNet device.
* It's the abstract class for all OpenWebNet things. It should be extended by each specific OpenWebNet category of
* device (WHO).
* The {@link OpenWebNetThingHandler} is responsible for handling commands for
* an OpenWebNet device.
* It's the abstract class for all OpenWebNet things. It should be extended by
* each specific OpenWebNet category of device (WHO).
*
* @author Massimo Valla - Initial contribution
*/
Expand Down Expand Up @@ -118,7 +119,7 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, "@text/unknown.waiting-state");
} else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "@text/offline.bridge-offline");
}
}

Expand Down Expand Up @@ -157,8 +158,8 @@ public void handleCommand(ChannelUID channel, Command command) {
protected abstract void handleChannelCommand(ChannelUID channel, Command command);

/**
* Handle incoming message from OWN network via bridge Thing, directed to this device.
* It should be further implemented by each specific device handler.
* Handle incoming message from OWN network via bridge Thing, directed to this
* device. It should be further implemented by each specific device handler.
*
* @param msg the message to handle
*/
Expand Down Expand Up @@ -203,8 +204,8 @@ protected void handleMessage(BaseOpenMessage msg) {
}

/**
* Request the state for the specified channel. If no answer is received within THING_STATE_REQ_TIMEOUT_SEC, it is
* put OFFLINE.
* Request the state for the specified channel. If no answer is received within
* THING_STATE_REQ_TIMEOUT_SEC, it is put OFFLINE.
* The method must be further implemented by each specific handler.
*
* @param channel the {@link ChannelUID} to request the state for
Expand All @@ -217,7 +218,8 @@ protected void requestChannelState(ChannelUID channel) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/offline.conf-error-where");
return;
}
// set a schedule to put device OFFLINE if no answer is received after THING_STATE_REQ_TIMEOUT_SEC
// set a schedule to put device OFFLINE if no answer is received after
// THING_STATE_REQ_TIMEOUT_SEC
requestChannelStateTimeout = scheduler.schedule(() -> {
if (thing.getStatus().equals(ThingStatus.UNKNOWN)) {
logger.debug("requestChannelState() TIMEOUT for thing {}", thing.getUID());
Expand All @@ -228,21 +230,24 @@ protected void requestChannelState(ChannelUID channel) {
}

/**
* Refresh a device, possibly using a single OWN command if refreshAll=true and if supported.
* The method must be further implemented by each specific handler.
* Refresh a device, possibly using a single OWN command if refreshAll=true and
* if supported. The method must be further implemented by each specific
* handler.
*
* @param refreshAll true if all devices for this handler must be refreshed with a single OWN command, if supported,
* otherwise just refresh the single device.
* @param refreshAll true if all devices for this handler must be refreshed with
* a single OWN command, if supported, otherwise just refresh
* the single device.
*/
protected abstract void refreshDevice(boolean refreshAll);

/**
* If the subclass supports refreshing all devices with a single OWN command, returns the last TS when a refreshAll
* was requested, or 0 if not requested yet. If not supported return -1 (default).
* If the subclass supports refreshing all devices with a single OWN command,
* returns the last TS when a refreshAll was requested, or 0 if not requested
* yet. If not supported return -1 (default).
* It must be implemented by each subclass that supports all devices refresh.
*
* @return timestamp when last refreshAll command was sent, 0 if not requested yet, or -1 if it's not supported by
* subclass.
* @return timestamp when last refreshAll command was sent, 0 if not requested
* yet, or -1 if it's not supported by subclass.
*/
protected long getRefreshAllLastTS() {
return -1;
Expand All @@ -266,8 +271,8 @@ protected void refreshAllDevices() {
logger.debug("--- refreshAllDevices() : refresh all devices sent {}msec ago, skipping... ({})",
ALL_DEVICES_REFRESH_INTERVAL_MSEC, thing.getUID());
}
// sometimes GENERAL (e.g. #*1*0##) refresh requests do not return state for all devices, so let's
// schedule another single refresh device, just in case
// sometimes GENERAL (e.g. #*1*0##) refresh requests do not return state for all
// devices, so let's schedule another single refresh device, just in case
refreshTimeout = scheduler.schedule(() -> {
if (thing.getStatus().equals(ThingStatus.UNKNOWN)) {
logger.debug(
Expand All @@ -286,8 +291,9 @@ protected void refreshAllDevices() {
}

/**
* Abstract builder for device Where address, to be implemented by each subclass to choose the right Where subclass
* (the method is used only if the Thing is associated to a BUS gateway).
* Abstract builder for device Where address, to be implemented by each subclass
* to choose the right Where subclass (the method is used only if the Thing is
* associated to a BUS gateway).
*
* @param wStr the WHERE string
*/
Expand All @@ -312,7 +318,8 @@ public void dispose() {
}

/**
* Helper method to return a Quantity from a Number value or UnDefType.NULL if value is null
* Helper method to return a Quantity from a Number value or UnDefType.NULL if
* value is null
*
* @param value to be used
* @param unit to be used
Expand All @@ -323,7 +330,8 @@ protected <U extends Quantity<U>> State getAsQuantityTypeOrNull(@Nullable Number
}

/**
* Returns a prefix String for ownId specific for each handler. To be implemented by sub-classes.
* Returns a prefix String for ownId specific for each handler.
* To be implemented by sub-classes.
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,14 @@ channel-type.openwebnet.zoneAlarm.state.option.SILENT = Silent

# thing status descriptions

offline.comm-error-disconnected = Disconnected from gateway.
offline.comm-error-timeout = Connection to gateway timed out.
offline.comm-error-connection = Could not connect to gateway.
offline.comm-error-state = Could not get channel state.
offline.conf-error-no-ip-address = Cannot connect to gateway. No host/IP address has been provided in configuration.
offline.conf-error-no-serial-port = Cannot connect to gateway. No serial port has been provided in configuration.
offline.conf-error-where = OpenWebNet Address (where) parameter in configuration is null or invalid.
offline.conf-error-no-bridge = No bridge associated. Assign a bridge in configuration.
offline.conf-error-auth = Authentication failed. Check gateway password in configuration.
offline.comm-error-disconnected = Disconnected from gateway
offline.comm-error-timeout = Connection to gateway timed out
offline.comm-error-connection = Could not connect to gateway
offline.comm-error-state = Could not get channel state
offline.conf-error-no-ip-address = Cannot connect to gateway. No host/IP address has been provided in configuration
offline.conf-error-no-serial-port = Cannot connect to gateway. No serial port has been provided in configuration
offline.conf-error-where = OpenWebNet Address (where) parameter in configuration is null or invalid
offline.conf-error-no-bridge = No bridge associated. Assign a bridge in configuration
offline.conf-error-auth = Authentication failed. Check gateway password in configuration
offline.bridge-offline = Bridge offline
unknown.waiting-state = Waiting state update...

0 comments on commit d5fc81d

Please sign in to comment.