mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[shelly] improved logging on WebSocket connection problems (#16303)
* Improve logging on WebSocket connection problems Signed-off-by: Markus Michels <markus7017@gmail.com>
This commit is contained in:
parent
4870083c76
commit
9e1f87db86
@ -672,7 +672,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
|
||||
getThing().requestUpdates(1, true); // refresh config
|
||||
break;
|
||||
case SHELLY2_EVENT_SLEEP:
|
||||
logger.debug("{}: Device went to sleep mode", thingName);
|
||||
logger.debug("{}: Connection terminated, e.g. device in sleep mode", thingName);
|
||||
break;
|
||||
case SHELLY2_EVENT_WIFICONNFAILED:
|
||||
logger.debug("{}: WiFi connect failed, check setup, reason {}", thingName,
|
||||
@ -700,10 +700,14 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int statusCode, String reason) {
|
||||
public void onClose(int statusCode, String description) {
|
||||
try {
|
||||
logger.debug("{}: WebSocket connection closed, status = {}/{}", thingName, statusCode, getString(reason));
|
||||
if (statusCode == StatusCode.ABNORMAL && !discovery && getProfile().alwaysOn) { // e.g. device rebooted
|
||||
String reason = getString(description);
|
||||
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");
|
||||
}
|
||||
} catch (ShellyApiException e) {
|
||||
@ -714,7 +718,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
|
||||
|
||||
@Override
|
||||
public void onError(Throwable cause) {
|
||||
logger.debug("{}: WebSocket error", thingName);
|
||||
logger.debug("{}: WebSocket error: {}", thingName, cause.getMessage());
|
||||
if (thing != null && thing.getProfile().alwaysOn) {
|
||||
thingOffline("WebSocket error");
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
|
||||
import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.shelly.internal.api.ShellyApiException;
|
||||
import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
|
||||
@ -50,25 +50,24 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Markus Michels - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ShellyBluApi extends Shelly2ApiRpc {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShellyBluApi.class);
|
||||
private boolean connected = false; // true = BLU devices has connected
|
||||
private ShellySettingsStatus deviceStatus = new ShellySettingsStatus();
|
||||
private int lastPid = -1;
|
||||
|
||||
private static final Map<String, String> MAP_INPUT_EVENT_TYPE = new HashMap<>();
|
||||
static {
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put("1", SHELLY_BTNEVENT_1SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put("2", SHELLY_BTNEVENT_2SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put("3", SHELLY_BTNEVENT_3SHORTPUSH);
|
||||
MAP_INPUT_EVENT_TYPE.put("4", SHELLY_BTNEVENT_LONGPUSH);
|
||||
}
|
||||
private static final Map<String, String> MAP_INPUT_EVENT_TYPE = Map.of( //
|
||||
SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH, //
|
||||
SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH, //
|
||||
SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH, //
|
||||
SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH, //
|
||||
SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH, //
|
||||
SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH, //
|
||||
"1", SHELLY_BTNEVENT_1SHORTPUSH, //
|
||||
"2", SHELLY_BTNEVENT_2SHORTPUSH, //
|
||||
"3", SHELLY_BTNEVENT_3SHORTPUSH, //
|
||||
"4", SHELLY_BTNEVENT_LONGPUSH);
|
||||
|
||||
/**
|
||||
* Regular constructor - called by Thing handler
|
||||
|
@ -340,7 +340,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||
? tmpPrf.settings.sleepMode.period * 60 // minutes
|
||||
: tmpPrf.settings.sleepMode.period * 3600; // hours
|
||||
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
|
||||
tmpPrf.updatePeriod = Math.max(UPDATE_SETTINGS_INTERVAL_SECONDS,
|
||||
2 * getInteger(tmpPrf.settings.coiot.updatePeriod)) + 10;
|
||||
|
@ -20,6 +20,7 @@ import static org.openhab.core.thing.Thing.PROPERTY_MODEL_ID;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
|
||||
@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Markus Michels - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ShellyBluSensorHandler extends ShellyBaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShellyBluSensorHandler.class);
|
||||
|
||||
@ -52,7 +54,7 @@ public class ShellyBluSensorHandler extends ShellyBaseHandler {
|
||||
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 mac = e.data.addr.replaceAll(":", "");
|
||||
String ttype = "";
|
||||
|
@ -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.shellyplus10v.description = Shelly Plus Dimmer 10V
|
||||
|
||||
# Wall displays
|
||||
thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
|
||||
|
||||
# Plus Mini Devices
|
||||
thing-type.shelly.shellyplusmini1.description = Shelly Plus Mini 1 - Single Relay Switch
|
||||
thing-type.shelly.shellyplusminipm.description = Shelly Plus Mini PM - Power Meter
|
||||
@ -125,8 +122,8 @@ thing-type.shelly.shellyblubutton.description = Shelly BLU Button 1
|
||||
thing-type.shelly.shellybludw.description = Shelly BLU Door/Window Sensor
|
||||
thing-type.shelly.shellyblumotion.description = Shelly BLU Motion Sensor
|
||||
|
||||
# Wall Displays
|
||||
thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
|
||||
# Wall Displays
|
||||
thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
|
||||
|
||||
# thing config - shellydevice
|
||||
thing-type.config.shelly.deviceIp.label = IP Address
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This script uses the BLE scan functionality in scripting to pass scan reults to openHAB
|
||||
* Supported BLU Devices: SBBT , SBDW
|
||||
* This script uses the BLE scan functionality in scripting to pass scan results to openHAB
|
||||
* Supported BLU Devices: BLU Button 1, BLU Door/Window, BLU Motion
|
||||
* Version 0.2
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user