|
39 | 39 | import org.openhab.core.thing.Thing;
|
40 | 40 | import org.openhab.core.thing.ThingStatus;
|
41 | 41 | import org.openhab.core.thing.ThingStatusDetail;
|
| 42 | +import org.openhab.core.thing.ThingStatusInfo; |
42 | 43 | import org.openhab.core.thing.binding.BaseThingHandler;
|
43 | 44 | import org.openhab.core.types.Command;
|
44 | 45 | import org.openhab.core.types.State;
|
@@ -70,10 +71,22 @@ public EaseeChargerHandler(Thing thing) {
|
70 | 71 | this.sessionDataPollingJobReference = new AtomicReference<>(null);
|
71 | 72 | }
|
72 | 73 |
|
73 |
| - void reInit() { |
74 |
| - if (isInitialized()) { |
75 |
| - dispose(); |
76 |
| - initialize(); |
| 74 | + @Override |
| 75 | + public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) { |
| 76 | + super.bridgeStatusChanged(bridgeStatusInfo); |
| 77 | + if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) { |
| 78 | + logger.debug("bridgeStatusChanged: ONLINE"); |
| 79 | + if (isInitialized()) { |
| 80 | + startPolling(); |
| 81 | + } |
| 82 | + } else { |
| 83 | + logger.debug("bridgeStatusChanged: NOT ONLINE"); |
| 84 | + if (isInitialized()) { |
| 85 | + if (bridgeStatusInfo.getStatus() == ThingStatus.UNKNOWN) { |
| 86 | + updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, STATUS_WAITING_FOR_BRIDGE); |
| 87 | + } |
| 88 | + stopPolling(); |
| 89 | + } |
77 | 90 | }
|
78 | 91 | }
|
79 | 92 |
|
@@ -131,6 +144,14 @@ private void startPolling() {
|
131 | 144 | POLLING_INITIAL_DELAY, getBridgeConfiguration().getSessionDataPollingInterval(), TimeUnit.SECONDS));
|
132 | 145 | }
|
133 | 146 |
|
| 147 | + /** |
| 148 | + * Stops the polling. |
| 149 | + */ |
| 150 | + private void stopPolling() { |
| 151 | + cancelJobReference(dataPollingJobReference); |
| 152 | + cancelJobReference(sessionDataPollingJobReference); |
| 153 | + } |
| 154 | + |
134 | 155 | /**
|
135 | 156 | * Poll the Easee Cloud API one time.
|
136 | 157 | */
|
@@ -198,8 +219,7 @@ protected final void updateOnlineStatus(CommunicationStatus status, JsonObject j
|
198 | 219 | @Override
|
199 | 220 | public void dispose() {
|
200 | 221 | logger.debug("Handler disposed.");
|
201 |
| - cancelJobReference(dataPollingJobReference); |
202 |
| - cancelJobReference(sessionDataPollingJobReference); |
| 222 | + stopPolling(); |
203 | 223 | }
|
204 | 224 |
|
205 | 225 | /**
|
|
0 commit comments