[shelly] improved logging on WebSocket connection problems (#16303)

* Improve logging on WebSocket connection problems

Signed-off-by: Markus Michels <markus7017@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Markus Michels 2024-01-19 15:58:18 -05:00 committed by Ciprian Pascu
parent 9e17107d20
commit 168d1fec39
6 changed files with 30 additions and 28 deletions

View File

@ -672,7 +672,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
getThing().requestUpdates(1, true); // refresh config getThing().requestUpdates(1, true); // refresh config
break; break;
case SHELLY2_EVENT_SLEEP: case SHELLY2_EVENT_SLEEP:
logger.debug("{}: Device went to sleep mode", thingName); logger.debug("{}: Connection terminated, e.g. device in sleep mode", thingName);
break; break;
case SHELLY2_EVENT_WIFICONNFAILED: case SHELLY2_EVENT_WIFICONNFAILED:
logger.debug("{}: WiFi connect failed, check setup, reason {}", thingName, logger.debug("{}: WiFi connect failed, check setup, reason {}", thingName,
@ -700,10 +700,14 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
} }
@Override @Override
public void onClose(int statusCode, String reason) { public void onClose(int statusCode, String description) {
try { try {
logger.debug("{}: WebSocket connection closed, status = {}/{}", thingName, statusCode, getString(reason)); String reason = getString(description);
if (statusCode == StatusCode.ABNORMAL && !discovery && getProfile().alwaysOn) { // e.g. device rebooted logger.debug("{}: WebSocket connection closed, status = {}/{}", thingName, statusCode, reason);
if ("Bye".equalsIgnoreCase(reason)) {
logger.debug("{}: Device went to sleep mode", thingName);
} else if (statusCode == StatusCode.ABNORMAL && !discovery && getProfile().alwaysOn) {
// e.g. device rebooted
thingOffline("WebSocket connection closed abnormal"); thingOffline("WebSocket connection closed abnormal");
} }
} catch (ShellyApiException e) { } catch (ShellyApiException e) {
@ -714,7 +718,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
@Override @Override
public void onError(Throwable cause) { public void onError(Throwable cause) {
logger.debug("{}: WebSocket error", thingName); logger.debug("{}: WebSocket error: {}", thingName, cause.getMessage());
if (thing != null && thing.getProfile().alwaysOn) { if (thing != null && thing.getProfile().alwaysOn) {
thingOffline("WebSocket error"); thingOffline("WebSocket error");
} }

View File

@ -18,9 +18,9 @@ import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.shelly.internal.api.ShellyApiException; import org.openhab.binding.shelly.internal.api.ShellyApiException;
import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile; import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
@ -50,25 +50,24 @@ import org.slf4j.LoggerFactory;
* *
* @author Markus Michels - Initial contribution * @author Markus Michels - Initial contribution
*/ */
@NonNullByDefault
public class ShellyBluApi extends Shelly2ApiRpc { public class ShellyBluApi extends Shelly2ApiRpc {
private static final Logger logger = LoggerFactory.getLogger(ShellyBluApi.class); private static final Logger logger = LoggerFactory.getLogger(ShellyBluApi.class);
private boolean connected = false; // true = BLU devices has connected private boolean connected = false; // true = BLU devices has connected
private ShellySettingsStatus deviceStatus = new ShellySettingsStatus(); private ShellySettingsStatus deviceStatus = new ShellySettingsStatus();
private int lastPid = -1; private int lastPid = -1;
private static final Map<String, String> MAP_INPUT_EVENT_TYPE = new HashMap<>(); private static final Map<String, String> MAP_INPUT_EVENT_TYPE = Map.of( //
static { SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH); SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH); SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH); SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH); SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH); SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH, //
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH); "1", SHELLY_BTNEVENT_1SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put("1", SHELLY_BTNEVENT_1SHORTPUSH); "2", SHELLY_BTNEVENT_2SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put("2", SHELLY_BTNEVENT_2SHORTPUSH); "3", SHELLY_BTNEVENT_3SHORTPUSH, //
MAP_INPUT_EVENT_TYPE.put("3", SHELLY_BTNEVENT_3SHORTPUSH); "4", SHELLY_BTNEVENT_LONGPUSH);
MAP_INPUT_EVENT_TYPE.put("4", SHELLY_BTNEVENT_LONGPUSH);
}
/** /**
* Regular constructor - called by Thing handler * Regular constructor - called by Thing handler

View File

@ -340,7 +340,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
? tmpPrf.settings.sleepMode.period * 60 // minutes ? tmpPrf.settings.sleepMode.period * 60 // minutes
: tmpPrf.settings.sleepMode.period * 3600; // hours : tmpPrf.settings.sleepMode.period * 3600; // hours
tmpPrf.updatePeriod += 60; // give 1min extra tmpPrf.updatePeriod += 60; // give 1min extra
} else if ((tmpPrf.settings.coiot != null) && tmpPrf.settings.coiot.updatePeriod != null) { } else if (tmpPrf.settings.coiot != null && tmpPrf.settings.coiot.updatePeriod != null) {
// Derive from CoAP update interval, usually 2*15+10s=40sec -> 70sec // Derive from CoAP update interval, usually 2*15+10s=40sec -> 70sec
tmpPrf.updatePeriod = Math.max(UPDATE_SETTINGS_INTERVAL_SECONDS, tmpPrf.updatePeriod = Math.max(UPDATE_SETTINGS_INTERVAL_SECONDS,
2 * getInteger(tmpPrf.settings.coiot.updatePeriod)) + 10; 2 * getInteger(tmpPrf.settings.coiot.updatePeriod)) + 10;

View File

@ -20,6 +20,7 @@ import static org.openhab.core.thing.Thing.PROPERTY_MODEL_ID;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile; import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Markus Michels - Initial contribution * @author Markus Michels - Initial contribution
*/ */
@NonNullByDefault
public class ShellyBluSensorHandler extends ShellyBaseHandler { public class ShellyBluSensorHandler extends ShellyBaseHandler {
private static final Logger logger = LoggerFactory.getLogger(ShellyBluSensorHandler.class); private static final Logger logger = LoggerFactory.getLogger(ShellyBluSensorHandler.class);
@ -52,7 +54,7 @@ public class ShellyBluSensorHandler extends ShellyBaseHandler {
super.initialize(); super.initialize();
} }
public static void addBluThing(String gateway, Shelly2NotifyEvent e, ShellyThingTable thingTable) { public static void addBluThing(String gateway, Shelly2NotifyEvent e, @Nullable ShellyThingTable thingTable) {
String model = substringBefore(getString(e.data.name), "-").toUpperCase(); String model = substringBefore(getString(e.data.name), "-").toUpperCase();
String mac = e.data.addr.replaceAll(":", ""); String mac = e.data.addr.replaceAll(":", "");
String ttype = ""; String ttype = "";

View File

@ -101,9 +101,6 @@ thing-type.shelly.shellyplussmoke.description = Shelly Plus Smoke - Smoke Detect
thing-type.shelly.shellypluswdus.description = Shelly Wall Dimmer US Device thing-type.shelly.shellypluswdus.description = Shelly Wall Dimmer US Device
thing-type.shelly.shellyplus10v.description = Shelly Plus Dimmer 10V thing-type.shelly.shellyplus10v.description = Shelly Plus Dimmer 10V
# Wall displays
thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
# Plus Mini Devices # Plus Mini Devices
thing-type.shelly.shellyplusmini1.description = Shelly Plus Mini 1 - Single Relay Switch thing-type.shelly.shellyplusmini1.description = Shelly Plus Mini 1 - Single Relay Switch
thing-type.shelly.shellyplusminipm.description = Shelly Plus Mini PM - Power Meter thing-type.shelly.shellyplusminipm.description = Shelly Plus Mini PM - Power Meter

View File

@ -1,6 +1,6 @@
/* /*
* This script uses the BLE scan functionality in scripting to pass scan reults to openHAB * This script uses the BLE scan functionality in scripting to pass scan results to openHAB
* Supported BLU Devices: SBBT , SBDW * Supported BLU Devices: BLU Button 1, BLU Door/Window, BLU Motion
* Version 0.2 * Version 0.2
*/ */