]> git.basschouten.com Git - openhab-addons.git/blob
0f684320c4a838af85bf6dace2e1529d6dda3e0f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.knx.internal.handler;
14
15 import static org.openhab.binding.knx.internal.KNXBindingConstants.*;
16
17 import java.math.BigDecimal;
18 import java.time.Duration;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Objects;
22 import java.util.Random;
23 import java.util.Set;
24 import java.util.concurrent.ConcurrentHashMap;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.ScheduledExecutorService;
27 import java.util.concurrent.ScheduledFuture;
28 import java.util.concurrent.TimeUnit;
29
30 import javax.measure.Unit;
31
32 import org.eclipse.jdt.annotation.NonNullByDefault;
33 import org.eclipse.jdt.annotation.Nullable;
34 import org.openhab.binding.knx.internal.KNXBindingConstants;
35 import org.openhab.binding.knx.internal.channel.KNXChannel;
36 import org.openhab.binding.knx.internal.channel.KNXChannelFactory;
37 import org.openhab.binding.knx.internal.client.AbstractKNXClient;
38 import org.openhab.binding.knx.internal.client.DeviceInspector;
39 import org.openhab.binding.knx.internal.client.InboundSpec;
40 import org.openhab.binding.knx.internal.client.KNXClient;
41 import org.openhab.binding.knx.internal.client.OutboundSpec;
42 import org.openhab.binding.knx.internal.config.DeviceConfig;
43 import org.openhab.binding.knx.internal.dpt.DPTUnits;
44 import org.openhab.binding.knx.internal.dpt.DPTUtil;
45 import org.openhab.binding.knx.internal.dpt.ValueDecoder;
46 import org.openhab.binding.knx.internal.i18n.KNXTranslationProvider;
47 import org.openhab.core.cache.ExpiringCacheMap;
48 import org.openhab.core.library.types.IncreaseDecreaseType;
49 import org.openhab.core.thing.Bridge;
50 import org.openhab.core.thing.Channel;
51 import org.openhab.core.thing.ChannelUID;
52 import org.openhab.core.thing.Thing;
53 import org.openhab.core.thing.ThingStatus;
54 import org.openhab.core.thing.ThingStatusDetail;
55 import org.openhab.core.thing.ThingStatusInfo;
56 import org.openhab.core.thing.binding.BaseThingHandler;
57 import org.openhab.core.thing.binding.ThingHandlerCallback;
58 import org.openhab.core.thing.binding.builder.ChannelBuilder;
59 import org.openhab.core.thing.binding.builder.ThingBuilder;
60 import org.openhab.core.types.Command;
61 import org.openhab.core.types.RefreshType;
62 import org.openhab.core.types.State;
63 import org.openhab.core.types.Type;
64 import org.openhab.core.types.UnDefType;
65 import org.openhab.core.types.util.UnitUtils;
66 import org.openhab.core.util.HexUtils;
67 import org.slf4j.Logger;
68 import org.slf4j.LoggerFactory;
69
70 import tuwien.auto.calimero.GroupAddress;
71 import tuwien.auto.calimero.IndividualAddress;
72 import tuwien.auto.calimero.KNXException;
73 import tuwien.auto.calimero.KNXFormatException;
74 import tuwien.auto.calimero.datapoint.CommandDP;
75 import tuwien.auto.calimero.datapoint.Datapoint;
76
77 /**
78  * The {@link DeviceThingHandler} is responsible for handling commands and state updates sent to and received from the
79  * bus and updating the channels correspondingly.
80  *
81  * @author Simon Kaufmann - Initial contribution and API
82  * @author Jan N. Klug - Refactored for performance
83  */
84 @NonNullByDefault
85 public class DeviceThingHandler extends BaseThingHandler implements GroupAddressListener {
86     private static final int INITIAL_PING_DELAY = 5;
87     private final Logger logger = LoggerFactory.getLogger(DeviceThingHandler.class);
88
89     private final Set<GroupAddress> groupAddresses = ConcurrentHashMap.newKeySet();
90     private final ExpiringCacheMap<GroupAddress, @Nullable Boolean> groupAddressesWriteBlocked = new ExpiringCacheMap<>(
91             Duration.ofMillis(1000));
92     private final Map<GroupAddress, OutboundSpec> groupAddressesRespondingSpec = new ConcurrentHashMap<>();
93     private final Map<GroupAddress, ScheduledFuture<?>> readFutures = new ConcurrentHashMap<>();
94     private final Map<ChannelUID, ScheduledFuture<?>> channelFutures = new ConcurrentHashMap<>();
95     private final Map<ChannelUID, KNXChannel> knxChannels = new ConcurrentHashMap<>();
96     private final Random random = new Random();
97     protected @Nullable IndividualAddress address;
98     private int readInterval;
99     private @Nullable ScheduledFuture<?> descriptionJob;
100     private boolean filledDescription = false;
101     private @Nullable ScheduledFuture<?> pollingJob;
102
103     public DeviceThingHandler(Thing thing) {
104         super(thing);
105     }
106
107     @Override
108     public void initialize() {
109         DeviceConfig config = getConfigAs(DeviceConfig.class);
110         readInterval = config.getReadInterval();
111
112         // gather all GAs from channel configurations and create channels
113         ThingBuilder thingBuilder = editThing();
114         boolean modified = false;
115         ThingHandlerCallback callback = getCallback();
116         if (callback == null) {
117             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Framework failure: callback must not be null");
118             return;
119         }
120
121         for (Channel channel : getThing().getChannels()) {
122             KNXChannel knxChannel = KNXChannelFactory.createKnxChannel(channel);
123             knxChannels.put(channel.getUID(), knxChannel);
124             groupAddresses.addAll(knxChannel.getAllGroupAddresses());
125
126             if (knxChannel.getChannelType().startsWith("number")) {
127                 // check if we need to update the accepted item-type
128                 List<InboundSpec> inboundSpecs = knxChannel.getAllGroupAddresses().stream()
129                         .map(knxChannel::getListenSpec).filter(Objects::nonNull).map(Objects::requireNonNull).toList();
130
131                 String dpt = inboundSpecs.get(0).getDPT(); // there can be only one DPT on number channels
132                 Unit<?> unit = UnitUtils.parseUnit(DPTUnits.getUnitForDpt(dpt));
133                 String dimension = unit == null ? null : UnitUtils.getDimensionName(unit);
134                 String expectedItemType = dimension == null ? "Number" : "Number:" + dimension; // unknown dimension ->
135                                                                                                 // Number
136                 String actualItemType = channel.getAcceptedItemType();
137                 if (!expectedItemType.equals(actualItemType)) {
138                     ChannelBuilder channelBuilder = callback
139                             .createChannelBuilder(channel.getUID(), Objects.requireNonNull(channel.getChannelTypeUID()))
140                             .withAcceptedItemType(expectedItemType).withConfiguration(channel.getConfiguration());
141                     if (channel.getLabel() != null) {
142                         channelBuilder.withLabel(Objects.requireNonNull(channel.getLabel()));
143                     }
144                     if (channel.getDescription() != null) {
145                         channelBuilder.withDescription(Objects.requireNonNull(channel.getDescription()));
146                     }
147                     thingBuilder.withoutChannel(channel.getUID());
148                     thingBuilder.withChannel(channelBuilder.build());
149                     modified = true;
150                 }
151             }
152         }
153
154         if (modified) {
155             updateThing(thingBuilder.build());
156         }
157
158         attachToClient();
159     }
160
161     @Override
162     public void dispose() {
163         for (ChannelUID channelUID : channelFutures.keySet()) {
164             channelFutures.computeIfPresent(channelUID, (k, v) -> {
165                 v.cancel(true);
166                 return null;
167             });
168         }
169
170         groupAddresses.clear();
171         groupAddressesWriteBlocked.clear();
172         groupAddressesRespondingSpec.clear();
173         knxChannels.clear();
174
175         detachFromClient();
176     }
177
178     protected void cancelReadFutures() {
179         for (GroupAddress groupAddress : readFutures.keySet()) {
180             readFutures.computeIfPresent(groupAddress, (k, v) -> {
181                 v.cancel(true);
182                 return null;
183             });
184         }
185     }
186
187     @Override
188     public void channelLinked(ChannelUID channelUID) {
189         KNXChannel knxChannel = knxChannels.get(channelUID);
190         if (knxChannel == null) {
191             logger.warn("Channel '{}' received a channel linked event, but no KNXChannel found", channelUID);
192             return;
193         }
194         if (!knxChannel.isControl()) {
195             scheduleRead(knxChannel);
196         }
197     }
198
199     protected void scheduleReadJobs() {
200         cancelReadFutures();
201         for (KNXChannel knxChannel : knxChannels.values()) {
202             if (isLinked(knxChannel.getChannelUID()) && !knxChannel.isControl()) {
203                 scheduleRead(knxChannel);
204             }
205         }
206     }
207
208     private void scheduleRead(KNXChannel knxChannel) {
209         List<InboundSpec> readSpecs = knxChannel.getReadSpec();
210         for (InboundSpec readSpec : readSpecs) {
211             readSpec.getGroupAddresses().forEach(ga -> scheduleReadJob(ga, readSpec.getDPT()));
212         }
213     }
214
215     private void scheduleReadJob(GroupAddress groupAddress, String dpt) {
216         if (readInterval > 0) {
217             ScheduledFuture<?> future = readFutures.get(groupAddress);
218             if (future == null || future.isDone() || future.isCancelled()) {
219                 future = getScheduler().scheduleWithFixedDelay(() -> readDatapoint(groupAddress, dpt), 0, readInterval,
220                         TimeUnit.SECONDS);
221                 readFutures.put(groupAddress, future);
222             }
223         } else {
224             getScheduler().submit(() -> readDatapoint(groupAddress, dpt));
225         }
226     }
227
228     private void readDatapoint(GroupAddress groupAddress, String dpt) {
229         if (getClient().isConnected()) {
230             if (DPTUtil.getAllowedTypes(dpt).isEmpty()) {
231                 logger.warn("DPT '{}' is not supported by the KNX binding", dpt);
232                 return;
233             }
234             Datapoint datapoint = new CommandDP(groupAddress, getThing().getUID().toString(), 0, dpt);
235             getClient().readDatapoint(datapoint);
236         }
237     }
238
239     @Override
240     public boolean listensTo(GroupAddress destination) {
241         return groupAddresses.contains(destination);
242     }
243
244     /** Handling commands triggered from openHAB */
245     @Override
246     public void handleCommand(ChannelUID channelUID, Command command) {
247         logger.trace("Handling command '{}' for channel '{}'", command, channelUID);
248         KNXChannel knxChannel = knxChannels.get(channelUID);
249         if (knxChannel == null) {
250             logger.warn("Channel '{}' received command, but no KNXChannel found", channelUID);
251             return;
252         }
253         if (command instanceof RefreshType && !knxChannel.isControl()) {
254             logger.debug("Refreshing channel '{}'", channelUID);
255             scheduleRead(knxChannel);
256         } else {
257             if (CHANNEL_RESET.equals(channelUID.getId())) {
258                 if (address != null) {
259                     restart();
260                 }
261             } else {
262                 try {
263                     OutboundSpec commandSpec = knxChannel.getCommandSpec(command);
264                     // only send GroupValueWrite to KNX if GA is not blocked once
265                     if (commandSpec != null) {
266                         GroupAddress destination = commandSpec.getGroupAddress();
267                         if (knxChannel.isControl()) {
268                             // always remember, otherwise we might send an old state
269                             groupAddressesRespondingSpec.put(destination, commandSpec);
270                         }
271                         if (groupAddressesWriteBlocked.get(destination) != null) {
272                             logger.debug("Write to {} blocked for 1s/one call after read.", destination);
273                             groupAddressesWriteBlocked.invalidate(destination);
274                         } else {
275                             getClient().writeToKNX(commandSpec);
276                         }
277                     } else {
278                         logger.debug(
279                                 "None of the configured GAs on channel '{}' could handle the command '{}' of type '{}'",
280                                 channelUID, command, command.getClass().getSimpleName());
281                     }
282                 } catch (KNXException e) {
283                     logger.warn("An error occurred while handling command '{}' on channel '{}': {}", command,
284                             channelUID, e.getMessage());
285                 }
286             }
287         }
288     }
289
290     /** KNXIO */
291     private void sendGroupValueResponse(ChannelUID channelUID, GroupAddress destination) {
292         KNXChannel knxChannel = knxChannels.get(channelUID);
293         if (knxChannel == null) {
294             return;
295         }
296         Set<GroupAddress> rsa = knxChannel.getWriteAddresses();
297         if (!rsa.isEmpty()) {
298             logger.trace("onGroupRead size '{}'", rsa.size());
299             OutboundSpec os = groupAddressesRespondingSpec.get(destination);
300             if (os != null) {
301                 logger.trace("onGroupRead respondToKNX '{}'",
302                         os.getGroupAddress()); /* KNXIO: sending real "GroupValueResponse" to the KNX bus. */
303                 try {
304                     getClient().respondToKNX(os);
305                 } catch (KNXException e) {
306                     logger.warn("An error occurred on channel {}: {}", channelUID, e.getMessage(), e);
307                 }
308             }
309         }
310     }
311
312     /**
313      * KNXIO, extended with the ability to respond on "GroupValueRead" telegrams with "GroupValueResponse" telegram
314      */
315     @Override
316     public void onGroupRead(AbstractKNXClient client, IndividualAddress source, GroupAddress destination, byte[] asdu) {
317         logger.trace("onGroupRead Thing '{}' received a GroupValueRead telegram from '{}' for destination '{}'",
318                 getThing().getUID(), source, destination);
319         for (KNXChannel knxChannel : knxChannels.values()) {
320             if (knxChannel.isControl()) {
321                 OutboundSpec responseSpec = knxChannel.getResponseSpec(destination, RefreshType.REFRESH);
322                 if (responseSpec != null) {
323                     logger.trace("onGroupRead isControl -> postCommand");
324                     // This event should be sent to KNX as GroupValueResponse immediately.
325                     sendGroupValueResponse(knxChannel.getChannelUID(), destination);
326
327                     // block write attempts for 1s or 1 request to prevent loops
328                     if (!groupAddressesWriteBlocked.containsKey(destination)) {
329                         groupAddressesWriteBlocked.put(destination, () -> null);
330                     }
331                     groupAddressesWriteBlocked.putValue(destination, true);
332
333                     // Send REFRESH to openHAB to get this event for scripting with postCommand
334                     // and remember to ignore/block this REFRESH to be sent back to KNX as GroupValueWrite after
335                     // postCommand is done!
336                     postCommand(knxChannel.getChannelUID(), RefreshType.REFRESH);
337                 }
338             }
339         }
340     }
341
342     @Override
343     public void onGroupReadResponse(AbstractKNXClient client, IndividualAddress source, GroupAddress destination,
344             byte[] asdu) {
345         // GroupValueResponses are treated the same as GroupValueWrite telegrams
346         logger.trace("onGroupReadResponse Thing '{}' processes a GroupValueResponse telegram for destination '{}'",
347                 getThing().getUID(), destination);
348         onGroupWrite(client, source, destination, asdu);
349     }
350
351     /**
352      * KNXIO, here value changes are set, coming from KNX OR openHAB.
353      */
354     @Override
355     public void onGroupWrite(AbstractKNXClient client, IndividualAddress source, GroupAddress destination,
356             byte[] asdu) {
357         logger.debug("onGroupWrite Thing '{}' received a GroupValueWrite telegram from '{}' for destination '{}'",
358                 getThing().getUID(), source, destination);
359
360         for (KNXChannel knxChannel : knxChannels.values()) {
361             InboundSpec listenSpec = knxChannel.getListenSpec(destination);
362             if (listenSpec != null) {
363                 logger.trace(
364                         "onGroupWrite Thing '{}' processes a GroupValueWrite telegram for destination '{}' for channel '{}'",
365                         getThing().getUID(), destination, knxChannel.getChannelUID());
366                 /**
367                  * Remember current KNXIO outboundSpec only if it is a control channel.
368                  */
369                 if (knxChannel.isControl()) {
370                     logger.trace("onGroupWrite isControl");
371                     Type value = ValueDecoder.decode(listenSpec.getDPT(), asdu, knxChannel.preferredType());
372                     if (value != null) {
373                         OutboundSpec commandSpec = knxChannel.getCommandSpec(value);
374                         if (commandSpec != null) {
375                             groupAddressesRespondingSpec.put(destination, commandSpec);
376                         }
377                     }
378                 }
379                 processDataReceived(destination, asdu, listenSpec, knxChannel);
380             }
381         }
382     }
383
384     private void processDataReceived(GroupAddress destination, byte[] asdu, InboundSpec listenSpec,
385             KNXChannel knxChannel) {
386         if (DPTUtil.getAllowedTypes(listenSpec.getDPT()).isEmpty()) {
387             logger.warn("DPT '{}' is not supported by the KNX binding.", listenSpec.getDPT());
388             return;
389         }
390
391         Type value = ValueDecoder.decode(listenSpec.getDPT(), asdu, knxChannel.preferredType());
392         if (value != null) {
393             if (knxChannel.isControl()) {
394                 ChannelUID channelUID = knxChannel.getChannelUID();
395                 int frequency;
396                 if (KNXBindingConstants.CHANNEL_DIMMER_CONTROL.equals(knxChannel.getChannelType())) {
397                     // if we have a dimmer control channel, check if a frequency is defined
398                     Channel channel = getThing().getChannel(channelUID);
399                     if (channel == null) {
400                         logger.warn("Failed to find channel for ChannelUID '{}'", channelUID);
401                         return;
402                     }
403                     frequency = ((BigDecimal) Objects.requireNonNullElse(
404                             channel.getConfiguration().get(KNXBindingConstants.REPEAT_FREQUENCY), BigDecimal.ZERO))
405                             .intValue();
406                 } else {
407                     // disable dimming by binding
408                     frequency = 0;
409                 }
410                 if ((value instanceof UnDefType || value instanceof IncreaseDecreaseType) && frequency > 0) {
411                     // continuous dimming by the binding
412                     // cancel a running scheduler before adding a new (and only add if not UnDefType)
413                     ScheduledFuture<?> oldFuture = channelFutures.remove(channelUID);
414                     if (oldFuture != null) {
415                         oldFuture.cancel(true);
416                     }
417                     if (value instanceof IncreaseDecreaseType increaseDecreaseCommand) {
418                         channelFutures.put(channelUID,
419                                 scheduler.scheduleWithFixedDelay(() -> postCommand(channelUID, increaseDecreaseCommand),
420                                         0, frequency, TimeUnit.MILLISECONDS));
421                     }
422                 } else {
423                     if (value instanceof Command command) {
424                         logger.trace("processDataReceived postCommand new value '{}' for GA '{}'", asdu, address);
425                         postCommand(channelUID, command);
426                     }
427                 }
428             } else {
429                 if (value instanceof State state && !(value instanceof UnDefType)) {
430                     updateState(knxChannel.getChannelUID(), state);
431                 }
432             }
433         } else {
434             logger.warn(
435                     "Ignoring KNX bus data for channel '{}': couldn't transform to any Type (GA='{}', DPT='{}', data='{}')",
436                     knxChannel.getChannelUID(), destination, listenSpec.getDPT(), HexUtils.bytesToHex(asdu));
437         }
438     }
439
440     protected final ScheduledExecutorService getScheduler() {
441         return getBridgeHandler().getScheduler();
442     }
443
444     protected final ScheduledExecutorService getBackgroundScheduler() {
445         return getBridgeHandler().getBackgroundScheduler();
446     }
447
448     protected final KNXBridgeBaseThingHandler getBridgeHandler() {
449         Bridge bridge = getBridge();
450         if (bridge != null) {
451             KNXBridgeBaseThingHandler handler = (KNXBridgeBaseThingHandler) bridge.getHandler();
452             if (handler != null) {
453                 return handler;
454             }
455         }
456         throw new IllegalStateException("The bridge must not be null and must be initialized");
457     }
458
459     protected final KNXClient getClient() {
460         return getBridgeHandler().getClient();
461     }
462
463     protected final boolean describeDevice(@Nullable IndividualAddress address) {
464         if (address == null) {
465             return false;
466         }
467         DeviceInspector inspector = new DeviceInspector(getClient().getDeviceInfoClient(), address);
468         DeviceInspector.Result result = inspector.readDeviceInfo();
469         if (result != null) {
470             Map<String, String> properties = editProperties();
471             properties.putAll(result.getProperties());
472             updateProperties(properties);
473             return true;
474         }
475         return false;
476     }
477
478     protected final void restart() {
479         if (address != null) {
480             getClient().restartNetworkDevice(address);
481         }
482     }
483
484     @Override
485     public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
486         if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
487             attachToClient();
488         } else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
489             detachFromClient();
490             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
491         }
492     }
493
494     private void pollDeviceStatus() {
495         try {
496             if (address != null && getClient().isConnected()) {
497                 logger.debug("Polling individual address '{}'", address);
498                 boolean isReachable = getClient().isReachable(address);
499                 if (isReachable) {
500                     updateStatus(ThingStatus.ONLINE);
501                     DeviceConfig config = getConfigAs(DeviceConfig.class);
502                     if (!filledDescription && config.getFetch()) {
503                         Future<?> descriptionJob = this.descriptionJob;
504                         if (descriptionJob == null || descriptionJob.isCancelled()) {
505                             long initialDelay = Math.round(config.getPingInterval() * random.nextFloat());
506                             this.descriptionJob = getBackgroundScheduler().schedule(() -> {
507                                 filledDescription = describeDevice(address);
508                             }, initialDelay, TimeUnit.SECONDS);
509                         }
510                     }
511                 } else {
512                     updateStatus(ThingStatus.OFFLINE);
513                 }
514             }
515         } catch (KNXException e) {
516             logger.debug("An error occurred while testing the reachability of a thing '{}': {}", getThing().getUID(),
517                     e.getMessage());
518             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
519                     KNXTranslationProvider.I18N.getLocalizedException(e));
520         }
521     }
522
523     protected void attachToClient() {
524         if (!getClient().isConnected()) {
525             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
526             return;
527         }
528         DeviceConfig config = getConfigAs(DeviceConfig.class);
529         try {
530             if (!config.getAddress().isEmpty()) {
531                 updateStatus(ThingStatus.UNKNOWN);
532                 address = new IndividualAddress(config.getAddress());
533
534                 long pingInterval = config.getPingInterval();
535                 long initialPingDelay = Math.round(INITIAL_PING_DELAY * random.nextFloat());
536
537                 ScheduledFuture<?> pollingJob = this.pollingJob;
538                 if ((pollingJob == null || pollingJob.isCancelled())) {
539                     logger.debug("'{}' will be polled every {}s", getThing().getUID(), pingInterval);
540                     this.pollingJob = getBackgroundScheduler().scheduleWithFixedDelay(this::pollDeviceStatus,
541                             initialPingDelay, pingInterval, TimeUnit.SECONDS);
542                 }
543             } else {
544                 updateStatus(ThingStatus.ONLINE);
545             }
546         } catch (KNXFormatException e) {
547             logger.debug("An exception occurred while setting the individual address '{}': {}", config.getAddress(),
548                     e.getMessage());
549             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
550                     KNXTranslationProvider.I18N.getLocalizedException(e));
551         }
552         getClient().registerGroupAddressListener(this);
553         scheduleReadJobs();
554     }
555
556     protected void detachFromClient() {
557         ScheduledFuture<?> pollingJobSynced = pollingJob;
558         if (pollingJobSynced != null) {
559             pollingJobSynced.cancel(true);
560             pollingJob = null;
561         }
562         ScheduledFuture<?> descriptionJobSynced = descriptionJob;
563         if (descriptionJobSynced != null) {
564             descriptionJobSynced.cancel(true);
565             descriptionJob = null;
566         }
567         cancelReadFutures();
568         Bridge bridge = getBridge();
569         if (bridge != null) {
570             KNXBridgeBaseThingHandler handler = (KNXBridgeBaseThingHandler) bridge.getHandler();
571             if (handler != null) {
572                 handler.getClient().unregisterGroupAddressListener(this);
573             }
574         }
575     }
576 }