mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[jablotron] fixed updating of JA100 PG channels (#9003)
* [jablotron] fixed bug when bridge stays offline forever in some cases * [jablotron] fixed the JA100 channel update bug Signed-off-by: Ondrej Pecta <opecta@gmail.com>
This commit is contained in:
parent
d6d68c7a96
commit
8aa4be628a
@ -72,9 +72,13 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler {
|
||||
@Override
|
||||
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
||||
super.bridgeStatusChanged(bridgeStatusInfo);
|
||||
if (ThingStatus.UNINITIALIZED == bridgeStatusInfo.getStatus()) {
|
||||
if (ThingStatus.OFFLINE == bridgeStatusInfo.getStatus()
|
||||
|| ThingStatus.UNINITIALIZED == bridgeStatusInfo.getStatus()) {
|
||||
cleanup();
|
||||
}
|
||||
if (ThingStatus.ONLINE == bridgeStatusInfo.getStatus()) {
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,6 +89,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logger.debug("Initializing the alarm: {}", getThing().getUID());
|
||||
thingConfig = getConfigAs(JablotronDeviceConfig.class);
|
||||
future = scheduler.scheduleWithFixedDelay(this::updateAlarmStatus, 1, thingConfig.getRefresh(),
|
||||
TimeUnit.SECONDS);
|
||||
@ -144,6 +149,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
protected synchronized boolean updateAlarmStatus() {
|
||||
logger.debug("Updating status of alarm: {}", getThing().getUID());
|
||||
JablotronDataUpdateResponse dataUpdate = sendGetStatusRequest();
|
||||
if (dataUpdate == null) {
|
||||
return false;
|
||||
|
@ -90,9 +90,14 @@ public class JablotronBridgeHandler extends BaseBridgeHandler {
|
||||
}
|
||||
|
||||
private void updateAlarmThings() {
|
||||
logger.debug("Updating overall alarm's statuses...");
|
||||
@Nullable
|
||||
List<JablotronDiscoveredService> services = discoverServices();
|
||||
if (services != null) {
|
||||
Bridge localBridge = getThing();
|
||||
if (localBridge != null && ThingStatus.ONLINE != localBridge.getStatus()) {
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
}
|
||||
for (JablotronDiscoveredService service : services) {
|
||||
updateAlarmThing(service);
|
||||
}
|
||||
@ -101,6 +106,11 @@ public class JablotronBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
private void updateAlarmThing(JablotronDiscoveredService service) {
|
||||
for (Thing th : getThing().getThings()) {
|
||||
if (ThingStatus.ONLINE != th.getStatus()) {
|
||||
logger.debug("Thing {} is not online", th.getUID());
|
||||
continue;
|
||||
}
|
||||
|
||||
JablotronAlarmHandler handler = (JablotronAlarmHandler) th.getHandler();
|
||||
|
||||
if (handler == null) {
|
||||
@ -150,12 +160,13 @@ public class JablotronBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
private @Nullable <T> T sendMessage(String url, String urlParameters, Class<T> classOfT, String encoding,
|
||||
boolean relogin) {
|
||||
String line = "";
|
||||
try {
|
||||
ContentResponse resp = createRequest(url).content(new StringContentProvider(urlParameters), encoding)
|
||||
.send();
|
||||
|
||||
logger.trace("Request: {} with data: {}", url, urlParameters);
|
||||
String line = resp.getContentAsString();
|
||||
line = resp.getContentAsString();
|
||||
logger.trace("Response: {}", line);
|
||||
return gson.fromJson(line, classOfT);
|
||||
} catch (TimeoutException e) {
|
||||
@ -166,6 +177,7 @@ public class JablotronBridgeHandler extends BaseBridgeHandler {
|
||||
"Interrupt during calling url: " + url);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("Invalid JSON received: {}", line);
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||
"Syntax error during calling url: " + url);
|
||||
} catch (ExecutionException e) {
|
||||
|
@ -160,7 +160,7 @@ public class JablotronJa100Handler extends JablotronAlarmHandler {
|
||||
if (channel != null) {
|
||||
logger.debug("Updating channel: {} to value: {}", channel.getUID(), segment.getSegmentState());
|
||||
State newState;
|
||||
if (segmentId.startsWith("PGM_")) {
|
||||
if (segmentId.startsWith("pgm_")) {
|
||||
newState = "unset".equals(segment.getSegmentState()) ? OnOffType.OFF : OnOffType.ON;
|
||||
} else {
|
||||
newState = new StringType(segment.getSegmentState());
|
||||
|
Loading…
Reference in New Issue
Block a user