]> git.basschouten.com Git - openhab-addons.git/blob
06040dfaf0bf3c015704fc134b50a849c149c68a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.remoteopenhab.internal.handler;
14
15 import static org.openhab.binding.remoteopenhab.internal.RemoteopenhabBindingConstants.BINDING_ID;
16
17 import java.net.MalformedURLException;
18 import java.net.URL;
19 import java.time.ZonedDateTime;
20 import java.time.format.DateTimeFormatter;
21 import java.time.format.DateTimeParseException;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.concurrent.ScheduledFuture;
29 import java.util.concurrent.TimeUnit;
30 import java.util.stream.Collectors;
31
32 import javax.ws.rs.client.ClientBuilder;
33
34 import org.eclipse.jdt.annotation.NonNullByDefault;
35 import org.eclipse.jdt.annotation.Nullable;
36 import org.eclipse.jetty.client.HttpClient;
37 import org.openhab.binding.remoteopenhab.internal.RemoteopenhabChannelTypeProvider;
38 import org.openhab.binding.remoteopenhab.internal.RemoteopenhabStateDescriptionOptionProvider;
39 import org.openhab.binding.remoteopenhab.internal.config.RemoteopenhabServerConfiguration;
40 import org.openhab.binding.remoteopenhab.internal.data.RemoteopenhabItem;
41 import org.openhab.binding.remoteopenhab.internal.data.RemoteopenhabStateDescription;
42 import org.openhab.binding.remoteopenhab.internal.data.RemoteopenhabStateOption;
43 import org.openhab.binding.remoteopenhab.internal.discovery.RemoteopenhabDiscoveryService;
44 import org.openhab.binding.remoteopenhab.internal.exceptions.RemoteopenhabException;
45 import org.openhab.binding.remoteopenhab.internal.listener.RemoteopenhabItemsDataListener;
46 import org.openhab.binding.remoteopenhab.internal.listener.RemoteopenhabStreamingDataListener;
47 import org.openhab.binding.remoteopenhab.internal.rest.RemoteopenhabRestClient;
48 import org.openhab.core.library.CoreItemFactory;
49 import org.openhab.core.library.types.DateTimeType;
50 import org.openhab.core.library.types.DecimalType;
51 import org.openhab.core.library.types.HSBType;
52 import org.openhab.core.library.types.OnOffType;
53 import org.openhab.core.library.types.OpenClosedType;
54 import org.openhab.core.library.types.PercentType;
55 import org.openhab.core.library.types.PlayPauseType;
56 import org.openhab.core.library.types.PointType;
57 import org.openhab.core.library.types.QuantityType;
58 import org.openhab.core.library.types.RawType;
59 import org.openhab.core.library.types.StringType;
60 import org.openhab.core.net.NetUtil;
61 import org.openhab.core.thing.Bridge;
62 import org.openhab.core.thing.Channel;
63 import org.openhab.core.thing.ChannelUID;
64 import org.openhab.core.thing.ThingStatus;
65 import org.openhab.core.thing.ThingStatusDetail;
66 import org.openhab.core.thing.binding.BaseBridgeHandler;
67 import org.openhab.core.thing.binding.ThingHandlerService;
68 import org.openhab.core.thing.binding.builder.ChannelBuilder;
69 import org.openhab.core.thing.binding.builder.ThingBuilder;
70 import org.openhab.core.thing.type.AutoUpdatePolicy;
71 import org.openhab.core.thing.type.ChannelKind;
72 import org.openhab.core.thing.type.ChannelType;
73 import org.openhab.core.thing.type.ChannelTypeBuilder;
74 import org.openhab.core.thing.type.ChannelTypeUID;
75 import org.openhab.core.types.Command;
76 import org.openhab.core.types.RefreshType;
77 import org.openhab.core.types.State;
78 import org.openhab.core.types.StateDescriptionFragmentBuilder;
79 import org.openhab.core.types.StateOption;
80 import org.openhab.core.types.TypeParser;
81 import org.openhab.core.types.UnDefType;
82 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
83 import org.slf4j.Logger;
84 import org.slf4j.LoggerFactory;
85
86 import com.google.gson.Gson;
87
88 /**
89  * The {@link RemoteopenhabBridgeHandler} is responsible for handling commands and updating states
90  * using the REST API of the remote openHAB server.
91  *
92  * @author Laurent Garnier - Initial contribution
93  */
94 @NonNullByDefault
95 public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
96         implements RemoteopenhabStreamingDataListener, RemoteopenhabItemsDataListener {
97
98     private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
99     private static final DateTimeFormatter FORMATTER_DATE = DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN);
100
101     private static final int MAX_STATE_SIZE_FOR_LOGGING = 50;
102
103     private final Logger logger = LoggerFactory.getLogger(RemoteopenhabBridgeHandler.class);
104
105     private final HttpClient httpClientTrustingCert;
106     private final RemoteopenhabChannelTypeProvider channelTypeProvider;
107     private final RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider;
108
109     private final Object updateThingLock = new Object();
110
111     private @NonNullByDefault({}) RemoteopenhabServerConfiguration config;
112
113     private @Nullable ScheduledFuture<?> checkConnectionJob;
114     private RemoteopenhabRestClient restClient;
115
116     private Map<ChannelUID, State> channelsLastStates = new HashMap<>();
117
118     public RemoteopenhabBridgeHandler(Bridge bridge, HttpClient httpClient, HttpClient httpClientTrustingCert,
119             ClientBuilder clientBuilder, SseEventSourceFactory eventSourceFactory,
120             RemoteopenhabChannelTypeProvider channelTypeProvider,
121             RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider, final Gson jsonParser) {
122         super(bridge);
123         this.httpClientTrustingCert = httpClientTrustingCert;
124         this.channelTypeProvider = channelTypeProvider;
125         this.stateDescriptionProvider = stateDescriptionProvider;
126         this.restClient = new RemoteopenhabRestClient(httpClient, clientBuilder, eventSourceFactory, jsonParser);
127     }
128
129     @Override
130     public void initialize() {
131         logger.debug("Initializing remote openHAB handler for bridge {}", getThing().getUID());
132
133         config = getConfigAs(RemoteopenhabServerConfiguration.class);
134
135         String host = config.host.trim();
136         if (host.length() == 0) {
137             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
138                     "Undefined server address setting in the thing configuration");
139             return;
140         }
141         List<String> localIpAddresses = NetUtil.getAllInterfaceAddresses().stream()
142                 .filter(a -> !a.getAddress().isLinkLocalAddress())
143                 .map(a -> a.getAddress().getHostAddress().split("%")[0]).collect(Collectors.toList());
144         if (localIpAddresses.contains(host)) {
145             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
146                     "Do not use the local server as a remote server in the thing configuration");
147             return;
148         }
149         String path = config.restPath.trim();
150         if (path.length() == 0 || !path.startsWith("/")) {
151             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
152                     "Invalid REST API path setting in the thing configuration");
153             return;
154         }
155         URL url;
156         try {
157             url = new URL(config.useHttps ? "https" : "http", host, config.port, path);
158         } catch (MalformedURLException e) {
159             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
160                     "Invalid REST URL built from the settings in the thing configuration");
161             return;
162         }
163
164         String urlStr = url.toString();
165         if (urlStr.endsWith("/")) {
166             urlStr = urlStr.substring(0, urlStr.length() - 1);
167         }
168         logger.debug("REST URL = {}", urlStr);
169
170         restClient.setRestUrl(urlStr);
171         restClient.setAccessToken(config.token);
172         if (config.useHttps && config.trustedCertificate) {
173             restClient.setHttpClient(httpClientTrustingCert);
174             restClient.setTrustedCertificate(true);
175         }
176
177         updateStatus(ThingStatus.UNKNOWN);
178
179         scheduler.submit(this::checkConnection);
180         if (config.accessibilityInterval > 0) {
181             startCheckConnectionJob(config.accessibilityInterval, config.aliveInterval);
182         }
183     }
184
185     @Override
186     public void dispose() {
187         logger.debug("Disposing remote openHAB handler for bridge {}", getThing().getUID());
188         stopStreamingUpdates();
189         stopCheckConnectionJob();
190         channelsLastStates.clear();
191     }
192
193     @Override
194     public void handleCommand(ChannelUID channelUID, Command command) {
195         if (getThing().getStatus() != ThingStatus.ONLINE) {
196             return;
197         }
198
199         try {
200             if (command instanceof RefreshType) {
201                 String state = restClient.getRemoteItemState(channelUID.getId());
202                 updateChannelState(channelUID.getId(), null, state, false);
203             } else if (isLinked(channelUID)) {
204                 restClient.sendCommandToRemoteItem(channelUID.getId(), command);
205                 String commandStr = command.toFullString();
206                 logger.debug("Sending command {} to remote item {} succeeded",
207                         commandStr.length() < MAX_STATE_SIZE_FOR_LOGGING ? commandStr
208                                 : commandStr.substring(0, MAX_STATE_SIZE_FOR_LOGGING) + "...",
209                         channelUID.getId());
210             }
211         } catch (RemoteopenhabException e) {
212             logger.debug("{}", e.getMessage());
213         }
214     }
215
216     private void createChannels(List<RemoteopenhabItem> items, boolean replace) {
217         synchronized (updateThingLock) {
218             int nbGroups = 0;
219             List<Channel> channels = new ArrayList<>();
220             for (RemoteopenhabItem item : items) {
221                 String itemType = item.type;
222                 boolean readOnly = false;
223                 if ("Group".equals(itemType)) {
224                     if (item.groupType.isEmpty()) {
225                         // Standard groups are ignored
226                         nbGroups++;
227                         continue;
228                     } else {
229                         itemType = item.groupType;
230                     }
231                 } else {
232                     if (item.stateDescription != null && item.stateDescription.readOnly) {
233                         readOnly = true;
234                     }
235                 }
236                 String channelTypeId = String.format("item%s%s", itemType.replace(":", ""), readOnly ? "RO" : "");
237                 ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channelTypeId);
238                 ChannelType channelType = channelTypeProvider.getChannelType(channelTypeUID, null);
239                 String label;
240                 String description;
241                 if (channelType == null) {
242                     logger.trace("Create the channel type {} for item type {}", channelTypeUID, itemType);
243                     label = String.format("Remote %s Item", itemType);
244                     description = String.format("An item of type %s from the remote server.", itemType);
245                     channelType = ChannelTypeBuilder.state(channelTypeUID, label, itemType).withDescription(description)
246                             .withStateDescriptionFragment(
247                                     StateDescriptionFragmentBuilder.create().withReadOnly(readOnly).build())
248                             .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();
249                     channelTypeProvider.addChannelType(channelType);
250                 }
251                 ChannelUID channelUID = new ChannelUID(getThing().getUID(), item.name);
252                 logger.trace("Create the channel {} of type {}", channelUID, channelTypeUID);
253                 label = "Item " + item.name;
254                 description = String.format("Item %s from the remote server.", item.name);
255                 channels.add(ChannelBuilder.create(channelUID, itemType).withType(channelTypeUID)
256                         .withKind(ChannelKind.STATE).withLabel(label).withDescription(description).build());
257             }
258             ThingBuilder thingBuilder = editThing();
259             if (replace) {
260                 thingBuilder.withChannels(channels);
261                 updateThing(thingBuilder.build());
262                 logger.debug("{} channels defined for the thing {} (from {} items including {} groups)",
263                         channels.size(), getThing().getUID(), items.size(), nbGroups);
264             } else if (channels.size() > 0) {
265                 int nbRemoved = 0;
266                 for (Channel channel : channels) {
267                     if (getThing().getChannel(channel.getUID()) != null) {
268                         thingBuilder.withoutChannel(channel.getUID());
269                         nbRemoved++;
270                     }
271                 }
272                 if (nbRemoved > 0) {
273                     logger.debug("{} channels removed for the thing {} (from {} items)", nbRemoved, getThing().getUID(),
274                             items.size());
275                 }
276                 for (Channel channel : channels) {
277                     thingBuilder.withChannel(channel);
278                 }
279                 updateThing(thingBuilder.build());
280                 if (nbGroups > 0) {
281                     logger.debug("{} channels added for the thing {} (from {} items including {} groups)",
282                             channels.size(), getThing().getUID(), items.size(), nbGroups);
283                 } else {
284                     logger.debug("{} channels added for the thing {} (from {} items)", channels.size(),
285                             getThing().getUID(), items.size());
286                 }
287             }
288         }
289     }
290
291     private void removeChannels(List<RemoteopenhabItem> items) {
292         synchronized (updateThingLock) {
293             int nbRemoved = 0;
294             ThingBuilder thingBuilder = editThing();
295             for (RemoteopenhabItem item : items) {
296                 Channel channel = getThing().getChannel(item.name);
297                 if (channel != null) {
298                     thingBuilder.withoutChannel(channel.getUID());
299                     nbRemoved++;
300                 }
301             }
302             if (nbRemoved > 0) {
303                 updateThing(thingBuilder.build());
304                 logger.debug("{} channels removed for the thing {} (from {} items)", nbRemoved, getThing().getUID(),
305                         items.size());
306             }
307         }
308     }
309
310     private void setStateOptions(List<RemoteopenhabItem> items) {
311         for (RemoteopenhabItem item : items) {
312             Channel channel = getThing().getChannel(item.name);
313             RemoteopenhabStateDescription descr = item.stateDescription;
314             List<RemoteopenhabStateOption> options = descr == null ? null : descr.options;
315             if (channel != null && options != null && options.size() > 0) {
316                 List<StateOption> stateOptions = new ArrayList<>();
317                 for (RemoteopenhabStateOption option : options) {
318                     stateOptions.add(new StateOption(option.value, option.label));
319                 }
320                 stateDescriptionProvider.setStateOptions(channel.getUID(), stateOptions);
321                 logger.trace("{} options set for the channel {}", options.size(), channel.getUID());
322             }
323         }
324     }
325
326     public void checkConnection() {
327         logger.debug("Try the root REST API...");
328         try {
329             restClient.tryApi();
330             if (restClient.getRestApiVersion() == null) {
331                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
332                         "OH 1.x server not supported by the binding");
333             } else if (getThing().getStatus() != ThingStatus.ONLINE) {
334                 List<RemoteopenhabItem> items = restClient.getRemoteItems("name,type,groupType,stateDescription");
335
336                 createChannels(items, true);
337                 setStateOptions(items);
338
339                 try {
340                     items = restClient.getRemoteItems("name,state");
341                     for (RemoteopenhabItem item : items) {
342                         updateChannelState(item.name, null, item.state, false);
343                     }
344                 } catch (RemoteopenhabException e) {
345                     logger.debug("{}", e.getMessage());
346                 }
347
348                 updateStatus(ThingStatus.ONLINE);
349
350                 restartStreamingUpdates();
351             }
352         } catch (RemoteopenhabException e) {
353             logger.debug("{}", e.getMessage());
354             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
355             stopStreamingUpdates();
356         }
357     }
358
359     private void startCheckConnectionJob(int accessibilityInterval, int aliveInterval) {
360         ScheduledFuture<?> localCheckConnectionJob = checkConnectionJob;
361         if (localCheckConnectionJob == null || localCheckConnectionJob.isCancelled()) {
362             checkConnectionJob = scheduler.scheduleWithFixedDelay(() -> {
363                 long millisSinceLastEvent = System.currentTimeMillis() - restClient.getLastEventTimestamp();
364                 if (aliveInterval == 0 || restClient.getLastEventTimestamp() == 0) {
365                     logger.debug("Time to check server accessibility");
366                     checkConnection();
367                 } else if (millisSinceLastEvent > (aliveInterval * 60000)) {
368                     logger.debug(
369                             "Time to check server accessibility (maybe disconnected from streaming events, millisSinceLastEvent={})",
370                             millisSinceLastEvent);
371                     checkConnection();
372                 } else {
373                     logger.debug(
374                             "Bypass server accessibility check (receiving streaming events, millisSinceLastEvent={})",
375                             millisSinceLastEvent);
376                 }
377             }, accessibilityInterval, accessibilityInterval, TimeUnit.MINUTES);
378         }
379     }
380
381     private void stopCheckConnectionJob() {
382         ScheduledFuture<?> localCheckConnectionJob = checkConnectionJob;
383         if (localCheckConnectionJob != null) {
384             localCheckConnectionJob.cancel(true);
385             checkConnectionJob = null;
386         }
387     }
388
389     private void restartStreamingUpdates() {
390         synchronized (restClient) {
391             stopStreamingUpdates();
392             startStreamingUpdates();
393         }
394     }
395
396     private void startStreamingUpdates() {
397         synchronized (restClient) {
398             restClient.addStreamingDataListener(this);
399             restClient.addItemsDataListener(this);
400             restClient.start();
401         }
402     }
403
404     private void stopStreamingUpdates() {
405         synchronized (restClient) {
406             restClient.stop();
407             restClient.removeStreamingDataListener(this);
408             restClient.removeItemsDataListener(this);
409         }
410     }
411
412     public RemoteopenhabRestClient gestRestClient() {
413         return restClient;
414     }
415
416     @Override
417     public void onConnected() {
418         updateStatus(ThingStatus.ONLINE);
419     }
420
421     @Override
422     public void onError(String message) {
423         updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message);
424     }
425
426     @Override
427     public void onItemStateEvent(String itemName, String stateType, String state, boolean onlyIfStateChanged) {
428         updateChannelState(itemName, stateType, state, onlyIfStateChanged);
429     }
430
431     @Override
432     public void onItemAdded(RemoteopenhabItem item) {
433         createChannels(List.of(item), false);
434     }
435
436     @Override
437     public void onItemRemoved(RemoteopenhabItem item) {
438         removeChannels(List.of(item));
439     }
440
441     @Override
442     public void onItemUpdated(RemoteopenhabItem newItem, RemoteopenhabItem oldItem) {
443         if (!newItem.type.equals(oldItem.type)) {
444             createChannels(List.of(newItem), false);
445         } else {
446             logger.trace("Updated remote item {} ignored because item type {} is unchanged", newItem.name,
447                     newItem.type);
448         }
449     }
450
451     private void updateChannelState(String itemName, @Nullable String stateType, String state,
452             boolean onlyIfStateChanged) {
453         Channel channel = getThing().getChannel(itemName);
454         if (channel == null) {
455             logger.trace("No channel for item {}", itemName);
456             return;
457         }
458         String acceptedItemType = channel.getAcceptedItemType();
459         if (acceptedItemType == null) {
460             logger.trace("Channel without accepted item type for item {}", itemName);
461             return;
462         }
463         if (!isLinked(channel.getUID())) {
464             logger.trace("Unlinked channel {}", channel.getUID());
465             return;
466         }
467         State channelState = null;
468         if (stateType == null && "NULL".equals(state)) {
469             channelState = UnDefType.NULL;
470         } else if (stateType == null && "UNDEF".equals(state)) {
471             channelState = UnDefType.UNDEF;
472         } else if ("UnDef".equals(stateType)) {
473             switch (state) {
474                 case "NULL":
475                     channelState = UnDefType.NULL;
476                     break;
477                 case "UNDEF":
478                     channelState = UnDefType.UNDEF;
479                     break;
480                 default:
481                     logger.debug("Invalid UnDef value {} for item {}", state, itemName);
482                     break;
483             }
484         } else if (acceptedItemType.startsWith(CoreItemFactory.NUMBER + ":")) {
485             // Item type Number with dimension
486             if (stateType == null || "Quantity".equals(stateType)) {
487                 List<Class<? extends State>> stateTypes = Collections.singletonList(QuantityType.class);
488                 channelState = TypeParser.parseState(stateTypes, state);
489             } else if ("Decimal".equals(stateType)) {
490                 channelState = new DecimalType(state);
491             } else {
492                 logger.debug("Unexpected value type {} for item {}", stateType, itemName);
493             }
494         } else {
495             switch (acceptedItemType) {
496                 case CoreItemFactory.STRING:
497                     if (checkStateType(itemName, stateType, "String")) {
498                         channelState = new StringType(state);
499                     }
500                     break;
501                 case CoreItemFactory.NUMBER:
502                     if (checkStateType(itemName, stateType, "Decimal")) {
503                         channelState = new DecimalType(state);
504                     }
505                     break;
506                 case CoreItemFactory.SWITCH:
507                     if (checkStateType(itemName, stateType, "OnOff")) {
508                         channelState = "ON".equals(state) ? OnOffType.ON : OnOffType.OFF;
509                     }
510                     break;
511                 case CoreItemFactory.CONTACT:
512                     if (checkStateType(itemName, stateType, "OpenClosed")) {
513                         channelState = "OPEN".equals(state) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
514                     }
515                     break;
516                 case CoreItemFactory.DIMMER:
517                     if (checkStateType(itemName, stateType, "Percent")) {
518                         channelState = new PercentType(state);
519                     }
520                     break;
521                 case CoreItemFactory.COLOR:
522                     if (checkStateType(itemName, stateType, "HSB")) {
523                         channelState = HSBType.valueOf(state);
524                     }
525                     break;
526                 case CoreItemFactory.DATETIME:
527                     if (checkStateType(itemName, stateType, "DateTime")) {
528                         try {
529                             channelState = new DateTimeType(ZonedDateTime.parse(state, FORMATTER_DATE));
530                         } catch (DateTimeParseException e) {
531                             logger.debug("Failed to parse date {} for item {}", state, itemName);
532                             channelState = null;
533                         }
534                     }
535                     break;
536                 case CoreItemFactory.LOCATION:
537                     if (checkStateType(itemName, stateType, "Point")) {
538                         channelState = new PointType(state);
539                     }
540                     break;
541                 case CoreItemFactory.IMAGE:
542                     if (checkStateType(itemName, stateType, "Raw")) {
543                         channelState = RawType.valueOf(state);
544                     }
545                     break;
546                 case CoreItemFactory.PLAYER:
547                     if (checkStateType(itemName, stateType, "PlayPause")) {
548                         switch (state) {
549                             case "PLAY":
550                                 channelState = PlayPauseType.PLAY;
551                                 break;
552                             case "PAUSE":
553                                 channelState = PlayPauseType.PAUSE;
554                                 break;
555                             default:
556                                 logger.debug("Unexpected value {} for item {}", state, itemName);
557                                 break;
558                         }
559                     }
560                     break;
561                 case CoreItemFactory.ROLLERSHUTTER:
562                     if (checkStateType(itemName, stateType, "Percent")) {
563                         channelState = new PercentType(state);
564                     }
565                     break;
566                 default:
567                     logger.debug("Item type {} is not yet supported", acceptedItemType);
568                     break;
569             }
570         }
571         if (channelState != null) {
572             if (onlyIfStateChanged && channelState.equals(channelsLastStates.get(channel.getUID()))) {
573                 logger.trace("ItemStateChangedEvent ignored for item {} as state is identical to the last state",
574                         itemName);
575                 return;
576             }
577             channelsLastStates.put(channel.getUID(), channelState);
578             updateState(channel.getUID(), channelState);
579             String channelStateStr = channelState.toFullString();
580             logger.debug("updateState {} with {}", channel.getUID(),
581                     channelStateStr.length() < MAX_STATE_SIZE_FOR_LOGGING ? channelStateStr
582                             : channelStateStr.substring(0, MAX_STATE_SIZE_FOR_LOGGING) + "...");
583         }
584     }
585
586     private boolean checkStateType(String itemName, @Nullable String stateType, String expectedType) {
587         if (stateType != null && !expectedType.equals(stateType)) {
588             logger.debug("Unexpected value type {} for item {}", stateType, itemName);
589             return false;
590         } else {
591             return true;
592         }
593     }
594
595     @Override
596     public Collection<Class<? extends ThingHandlerService>> getServices() {
597         return Collections.singleton(RemoteopenhabDiscoveryService.class);
598     }
599 }