2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.miio.internal.handler;
15 import static org.openhab.binding.miio.internal.MiIoBindingConstants.*;
17 import java.awt.Color;
18 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.LinkedHashSet;
23 import java.util.List;
25 import java.util.concurrent.TimeUnit;
27 import javax.measure.Unit;
28 import javax.measure.format.ParserException;
30 import org.eclipse.jdt.annotation.NonNullByDefault;
31 import org.eclipse.jdt.annotation.Nullable;
32 import org.openhab.binding.miio.internal.MiIoBindingConfiguration;
33 import org.openhab.binding.miio.internal.MiIoCommand;
34 import org.openhab.binding.miio.internal.MiIoQuantiyTypes;
35 import org.openhab.binding.miio.internal.MiIoSendCommand;
36 import org.openhab.binding.miio.internal.Utils;
37 import org.openhab.binding.miio.internal.basic.ActionConditions;
38 import org.openhab.binding.miio.internal.basic.BasicChannelTypeProvider;
39 import org.openhab.binding.miio.internal.basic.CommandParameterType;
40 import org.openhab.binding.miio.internal.basic.Conversions;
41 import org.openhab.binding.miio.internal.basic.MiIoBasicChannel;
42 import org.openhab.binding.miio.internal.basic.MiIoBasicDevice;
43 import org.openhab.binding.miio.internal.basic.MiIoDatabaseWatchService;
44 import org.openhab.binding.miio.internal.basic.MiIoDeviceAction;
45 import org.openhab.binding.miio.internal.basic.MiIoDeviceActionCondition;
46 import org.openhab.binding.miio.internal.cloud.CloudConnector;
47 import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
48 import org.openhab.core.cache.ExpiringCache;
49 import org.openhab.core.library.types.DecimalType;
50 import org.openhab.core.library.types.HSBType;
51 import org.openhab.core.library.types.OnOffType;
52 import org.openhab.core.library.types.PercentType;
53 import org.openhab.core.library.types.QuantityType;
54 import org.openhab.core.library.types.StringType;
55 import org.openhab.core.library.unit.SIUnits;
56 import org.openhab.core.library.unit.SmartHomeUnits;
57 import org.openhab.core.thing.Channel;
58 import org.openhab.core.thing.ChannelUID;
59 import org.openhab.core.thing.Thing;
60 import org.openhab.core.thing.binding.builder.ChannelBuilder;
61 import org.openhab.core.thing.binding.builder.ThingBuilder;
62 import org.openhab.core.thing.type.ChannelTypeRegistry;
63 import org.openhab.core.thing.type.ChannelTypeUID;
64 import org.openhab.core.types.Command;
65 import org.openhab.core.types.RefreshType;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
69 import com.google.gson.Gson;
70 import com.google.gson.GsonBuilder;
71 import com.google.gson.JsonArray;
72 import com.google.gson.JsonElement;
73 import com.google.gson.JsonIOException;
74 import com.google.gson.JsonObject;
75 import com.google.gson.JsonPrimitive;
76 import com.google.gson.JsonSyntaxException;
79 * The {@link MiIoBasicHandler} is responsible for handling commands, which are
80 * sent to one of the channels.
82 * @author Marcel Verpaalen - Initial contribution
85 public class MiIoBasicHandler extends MiIoAbstractHandler {
86 private final Logger logger = LoggerFactory.getLogger(MiIoBasicHandler.class);
87 private boolean hasChannelStructure;
89 private final ExpiringCache<Boolean> updateDataCache = new ExpiringCache<>(CACHE_EXPIRY, () -> {
90 miIoScheduler.schedule(this::updateData, 0, TimeUnit.SECONDS);
94 List<MiIoBasicChannel> refreshList = new ArrayList<>();
95 private Map<String, MiIoBasicChannel> refreshListCustomCommands = new HashMap<>();
97 private @Nullable MiIoBasicDevice miioDevice;
98 private Map<ChannelUID, MiIoBasicChannel> actions = new HashMap<>();
99 private ChannelTypeRegistry channelTypeRegistry;
100 private BasicChannelTypeProvider basicChannelTypeProvider;
102 public MiIoBasicHandler(Thing thing, MiIoDatabaseWatchService miIoDatabaseWatchService,
103 CloudConnector cloudConnector, ChannelTypeRegistry channelTypeRegistry,
104 BasicChannelTypeProvider basicChannelTypeProvider) {
105 super(thing, miIoDatabaseWatchService, cloudConnector);
106 this.channelTypeRegistry = channelTypeRegistry;
107 this.basicChannelTypeProvider = basicChannelTypeProvider;
111 public void initialize() {
113 hasChannelStructure = false;
114 isIdentified = false;
115 refreshList = new ArrayList<>();
116 refreshListCustomCommands = new HashMap<>();
120 public void handleCommand(ChannelUID channelUID, Command receivedCommand) {
121 Command command = receivedCommand;
122 if (command == RefreshType.REFRESH) {
123 if (updateDataCache.isExpired()) {
124 logger.debug("Refreshing {}", channelUID);
125 updateDataCache.getValue();
127 logger.debug("Refresh {} skipped. Already refreshing", channelUID);
131 if (channelUID.getId().equals(CHANNEL_COMMAND)) {
132 cmds.put(sendCommand(command.toString()), command.toString());
135 logger.debug("Locating action for {} channel '{}': '{}'", getThing().getUID(), channelUID.getId(), command);
136 if (!actions.isEmpty()) {
137 MiIoBasicChannel miIoBasicChannel = actions.get(channelUID);
138 if (miIoBasicChannel != null) {
140 for (MiIoDeviceAction action : miIoBasicChannel.getActions()) {
142 JsonElement value = null;
143 JsonArray parameters = action.getParameters().deepCopy();
144 for (int i = 0; i < action.getParameters().size(); i++) {
145 JsonElement p = action.getParameters().get(i);
146 if (p.isJsonPrimitive() && p.getAsString().toLowerCase().contains("$value$")) {
151 String cmd = action.getCommand();
152 CommandParameterType paramType = action.getparameterType();
153 if (command instanceof QuantityType) {
154 QuantityType<?> qtc = null;
156 if (!miIoBasicChannel.getUnit().isBlank()) {
157 Unit<?> unit = MiIoQuantiyTypes.get(miIoBasicChannel.getUnit());
159 qtc = ((QuantityType<?>) command).toUnit(unit);
162 } catch (ParserException e) {
166 command = new DecimalType(qtc.toBigDecimal());
168 logger.debug("Could not convert QuantityType to '{}'", miIoBasicChannel.getUnit());
169 command = new DecimalType(((QuantityType<?>) command).toBigDecimal());
172 if (paramType == CommandParameterType.COLOR) {
173 if (command instanceof HSBType) {
174 HSBType hsb = (HSBType) command;
175 Color color = Color.getHSBColor(hsb.getHue().floatValue() / 360,
176 hsb.getSaturation().floatValue() / 100, hsb.getBrightness().floatValue() / 100);
177 value = new JsonPrimitive(
178 (color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
179 } else if (command instanceof DecimalType) {
180 // actually brightness is being set instead of a color
181 value = new JsonPrimitive(((DecimalType) command).toBigDecimal());
182 } else if (command instanceof OnOffType) {
183 value = new JsonPrimitive(command == OnOffType.ON ? 100 : 0);
185 logger.debug("Unsupported command for COLOR: {}", command);
187 } else if (command instanceof OnOffType) {
188 if (paramType == CommandParameterType.ONOFF) {
189 value = new JsonPrimitive(command == OnOffType.ON ? "on" : "off");
190 } else if (paramType == CommandParameterType.ONOFFPARA) {
191 cmd = cmd.replace("*", command == OnOffType.ON ? "on" : "off");
192 value = new JsonArray();
193 } else if (paramType == CommandParameterType.ONOFFBOOL) {
194 boolean boolCommand = command == OnOffType.ON;
195 value = new JsonPrimitive(boolCommand);
196 } else if (paramType == CommandParameterType.ONOFFBOOLSTRING) {
197 value = new JsonPrimitive(command == OnOffType.ON ? "true" : "false");
199 } else if (command instanceof DecimalType) {
200 value = new JsonPrimitive(((DecimalType) command).toBigDecimal());
201 } else if (command instanceof StringType) {
202 if (paramType == CommandParameterType.STRING) {
203 value = new JsonPrimitive(command.toString().toLowerCase());
204 } else if (paramType == CommandParameterType.CUSTOMSTRING) {
205 value = new JsonPrimitive(parameters.get(valuePos).getAsString().replace("$value",
206 command.toString().toLowerCase()));
209 value = new JsonPrimitive(command.toString().toLowerCase());
211 if (paramType == CommandParameterType.EMPTY) {
212 value = new JsonArray();
214 final MiIoDeviceActionCondition miIoDeviceActionCondition = action.getCondition();
215 if (miIoDeviceActionCondition != null) {
216 value = ActionConditions.executeAction(miIoDeviceActionCondition, deviceVariables, value,
219 // Check for miot channel
221 if (action.isMiOtAction()) {
222 value = miotActionTransform(action, miIoBasicChannel, value);
223 } else if (miIoBasicChannel.isMiOt()) {
224 value = miotTransform(miIoBasicChannel, value);
227 if (paramType != CommandParameterType.NONE && paramType != CommandParameterType.ONOFFPARA
229 if (parameters.size() > 0) {
230 parameters.set(valuePos, value);
232 parameters.add(value);
235 if (action.isMiOtAction() && parameters.size() > 0 && parameters.get(0).isJsonObject()) {
236 // hack as unlike any other commands miot actions parameters appear to be send as a json object
237 // instead of a json array
238 cmd = cmd + parameters.get(0).getAsJsonObject().toString();
240 cmd = cmd + parameters.toString();
243 logger.debug("Sending command {}", cmd);
246 if (miIoDeviceActionCondition != null) {
247 logger.debug("Conditional command {} not send, condition '{}' not met", cmd,
248 miIoDeviceActionCondition.getName());
250 logger.debug("Command not send. Value null");
255 logger.debug("Channel Id {} not in mapping.", channelUID.getId());
256 if (logger.isTraceEnabled()) {
257 for (ChannelUID a : actions.keySet()) {
258 logger.trace("Available entries: {} : {}", a, actions.get(a).getFriendlyName());
262 updateDataCache.invalidateValue();
263 miIoScheduler.schedule(() -> {
265 }, 3000, TimeUnit.MILLISECONDS);
267 logger.debug("Actions not loaded yet, or none available");
271 private @Nullable JsonElement miotTransform(MiIoBasicChannel miIoBasicChannel, @Nullable JsonElement value) {
272 JsonObject json = new JsonObject();
273 json.addProperty("did", miIoBasicChannel.getChannel());
274 json.addProperty("siid", miIoBasicChannel.getSiid());
275 json.addProperty("piid", miIoBasicChannel.getPiid());
276 json.add("value", value);
280 private @Nullable JsonElement miotActionTransform(MiIoDeviceAction action, MiIoBasicChannel miIoBasicChannel,
281 @Nullable JsonElement value) {
282 JsonObject json = new JsonObject();
283 json.addProperty("did", miIoBasicChannel.getChannel());
284 json.addProperty("siid", action.getSiid());
285 json.addProperty("aiid", action.getAiid());
287 json.add("in", value);
293 protected synchronized void updateData() {
294 logger.debug("Periodic update for '{}' ({})", getThing().getUID().toString(), getThing().getThingTypeUID());
295 final MiIoAsyncCommunication miioCom = getConnection();
297 if (!hasConnection() || skipUpdate() || miioCom == null) {
300 checkChannelStructure();
302 sendCommand(MiIoCommand.MIIO_INFO);
304 final MiIoBasicDevice midevice = miioDevice;
305 if (midevice != null) {
306 refreshProperties(midevice);
307 refreshCustomProperties(midevice);
310 } catch (Exception e) {
311 logger.debug("Error while updating '{}': ", getThing().getUID().toString(), e);
315 private void refreshCustomProperties(MiIoBasicDevice midevice) {
316 for (MiIoBasicChannel miChannel : refreshListCustomCommands.values()) {
317 sendCommand(miChannel.getChannelCustomRefreshCommand());
321 private boolean refreshProperties(MiIoBasicDevice device) {
322 MiIoCommand command = MiIoCommand.getCommand(device.getDevice().getPropertyMethod());
323 int maxProperties = device.getDevice().getMaxProperties();
324 JsonArray getPropString = new JsonArray();
325 for (MiIoBasicChannel miChannel : refreshList) {
326 if (!isLinked(miChannel.getChannel())) {
327 logger.debug("Skip refresh of channel {} for {} as it is not linked", miChannel.getChannel(),
328 getThing().getUID());
331 JsonElement property;
332 if (miChannel.isMiOt()) {
333 JsonObject json = new JsonObject();
334 json.addProperty("did", miChannel.getProperty());
335 json.addProperty("siid", miChannel.getSiid());
336 json.addProperty("piid", miChannel.getPiid());
339 property = new JsonPrimitive(miChannel.getProperty());
341 getPropString.add(property);
342 if (getPropString.size() >= maxProperties) {
343 sendRefreshProperties(command, getPropString);
344 getPropString = new JsonArray();
347 if (getPropString.size() > 0) {
348 sendRefreshProperties(command, getPropString);
353 private void sendRefreshProperties(MiIoCommand command, JsonArray getPropString) {
354 sendCommand(command, getPropString.toString());
358 * Checks if the channel structure has been build already based on the model data. If not build it.
360 private void checkChannelStructure() {
361 final MiIoBindingConfiguration configuration = this.configuration;
362 if (configuration == null) {
365 if (!hasChannelStructure) {
366 if (configuration.model == null || configuration.model.isEmpty()) {
367 logger.debug("Model needs to be determined");
368 isIdentified = false;
370 hasChannelStructure = buildChannelStructure(configuration.model);
373 if (hasChannelStructure) {
374 refreshList = new ArrayList<>();
375 final MiIoBasicDevice miioDevice = this.miioDevice;
376 if (miioDevice != null) {
377 for (MiIoBasicChannel miChannel : miioDevice.getDevice().getChannels()) {
378 if (miChannel.getRefresh()) {
379 if (miChannel.getChannelCustomRefreshCommand().isBlank()) {
380 refreshList.add(miChannel);
382 String i = miChannel.getChannelCustomRefreshCommand().split("\\[")[0];
383 refreshListCustomCommands.put(i.trim(), miChannel);
392 private boolean buildChannelStructure(String deviceName) {
393 logger.debug("Building Channel Structure for {} - Model: {}", getThing().getUID().toString(), deviceName);
394 URL fn = miIoDatabaseWatchService.getDatabaseUrl(deviceName);
396 logger.warn("Database entry for model '{}' cannot be found.", deviceName);
400 JsonObject deviceMapping = Utils.convertFileToJSON(fn);
401 logger.debug("Using device database: {} for device {}", fn.getFile(), deviceName);
402 Gson gson = new GsonBuilder().serializeNulls().create();
403 miioDevice = gson.fromJson(deviceMapping, MiIoBasicDevice.class);
404 for (Channel ch : getThing().getChannels()) {
405 logger.debug("Current thing channels {}, type: {}", ch.getUID(), ch.getChannelTypeUID());
407 ThingBuilder thingBuilder = editThing();
408 int channelsAdded = 0;
410 // make a map of the actions
411 actions = new HashMap<>();
412 final MiIoBasicDevice device = this.miioDevice;
413 if (device != null) {
414 for (Channel cn : getThing().getChannels()) {
415 logger.trace("Channel '{}' for thing {} already exist... removing", cn.getUID(),
416 getThing().getUID());
417 if (!PERSISTENT_CHANNELS.contains(cn.getUID().getId().toString())) {
418 thingBuilder.withoutChannels(cn);
421 for (MiIoBasicChannel miChannel : device.getDevice().getChannels()) {
422 logger.debug("properties {}", miChannel);
423 if (!miChannel.getType().isEmpty()) {
424 basicChannelTypeProvider.addChannelType(miChannel, deviceName);
425 ChannelUID channelUID = addChannel(thingBuilder, miChannel, deviceName);
426 if (channelUID != null) {
427 actions.put(channelUID, miChannel);
430 logger.debug("Channel for {} ({}) not loaded", miChannel.getChannel(),
431 miChannel.getFriendlyName());
434 logger.debug("Channel {} ({}), not loaded, missing type", miChannel.getChannel(),
435 miChannel.getFriendlyName());
439 // only update if channels were added/removed
440 if (channelsAdded > 0) {
441 logger.debug("Current thing channels added: {}", channelsAdded);
442 updateThing(thingBuilder.build());
445 } catch (JsonIOException | JsonSyntaxException e) {
446 logger.warn("Error parsing database Json", e);
447 } catch (IOException e) {
448 logger.warn("Error reading database file", e);
449 } catch (Exception e) {
450 logger.warn("Error creating channel structure", e);
455 private @Nullable ChannelUID addChannel(ThingBuilder thingBuilder, MiIoBasicChannel miChannel, String model) {
456 String channel = miChannel.getChannel();
457 String dataType = miChannel.getType();
458 if (channel.isEmpty() || dataType.isEmpty()) {
459 logger.info("Channel '{}', UID '{}' cannot be added incorrectly configured database. ", channel,
460 getThing().getUID());
463 ChannelUID channelUID = new ChannelUID(getThing().getUID(), channel);
464 ChannelBuilder newChannel = ChannelBuilder.create(channelUID, dataType).withLabel(miChannel.getFriendlyName());
465 boolean useGeneratedChannelType = false;
466 if (!miChannel.getChannelType().isBlank()) {
467 ChannelTypeUID channelTypeUID = new ChannelTypeUID(miChannel.getChannelType());
468 if (channelTypeRegistry.getChannelType(channelTypeUID) != null) {
469 newChannel = newChannel.withType(channelTypeUID);
470 final LinkedHashSet<String> tags = miChannel.getTags();
471 if (tags != null && tags.size() > 0) {
472 newChannel.withDefaultTags(tags);
475 logger.debug("ChannelType '{}' is not available. Check the Json file for {}", channelTypeUID, model);
476 useGeneratedChannelType = true;
479 useGeneratedChannelType = true;
481 if (useGeneratedChannelType) {
482 newChannel = newChannel
483 .withType(new ChannelTypeUID(BINDING_ID, model.toUpperCase().replace(".", "_") + "_" + channel));
484 final LinkedHashSet<String> tags = miChannel.getTags();
485 if (tags != null && tags.size() > 0) {
486 newChannel.withDefaultTags(tags);
489 thingBuilder.withChannel(newChannel.build());
493 private @Nullable MiIoBasicChannel getChannel(String parameter) {
494 for (MiIoBasicChannel refreshEntry : refreshList) {
495 if (refreshEntry.getProperty().equals(parameter)) {
499 logger.trace("Did not find channel for {} in {}", parameter, refreshList);
503 private void updatePropsFromJsonArray(MiIoSendCommand response) {
504 JsonArray res = response.getResult().getAsJsonArray();
505 JsonArray para = parser.parse(response.getCommandString()).getAsJsonObject().get("params").getAsJsonArray();
506 if (res.size() != para.size()) {
507 logger.debug("Unexpected size different. Request size {}, response size {}. (Req: {}, Resp:{})",
508 para.size(), res.size(), para, res);
511 for (int i = 0; i < para.size(); i++) {
512 // This is a miot parameter
514 final JsonElement paraElement = para.get(i);
515 if (paraElement.isJsonObject()) { // miot channel
516 param = paraElement.getAsJsonObject().get("did").getAsString();
518 param = paraElement.getAsString();
520 JsonElement val = res.get(i);
521 if (val.isJsonNull()) {
522 logger.debug("Property '{}' returned null (is it supported?).", param);
524 } else if (val.isJsonObject()) { // miot channel
525 val = val.getAsJsonObject().get("value");
527 MiIoBasicChannel basicChannel = getChannel(param);
528 updateChannel(basicChannel, param, val);
532 private void updatePropsFromJsonObject(MiIoSendCommand response) {
533 JsonObject res = response.getResult().getAsJsonObject();
534 for (Object k : res.keySet()) {
535 String param = (String) k;
536 JsonElement val = res.get(param);
537 if (val.isJsonNull()) {
538 logger.debug("Property '{}' returned null (is it supported?).", param);
541 MiIoBasicChannel basicChannel = getChannel(param);
542 updateChannel(basicChannel, param, val);
546 private void updateChannel(@Nullable MiIoBasicChannel basicChannel, String param, JsonElement value) {
547 JsonElement val = value;
548 if (basicChannel == null) {
549 logger.debug("Channel not found for {}", param);
552 final String transformation = basicChannel.getTransfortmation();
553 if (transformation != null) {
554 JsonElement transformed = Conversions.execute(transformation, val);
555 logger.debug("Transformed with '{}': {} {} -> {} ", transformation, basicChannel.getFriendlyName(), val,
560 String[] chType = basicChannel.getType().toLowerCase().split(":");
563 quantityTypeUpdate(basicChannel, val, chType.length > 1 ? chType[1] : "");
566 updateState(basicChannel.getChannel(), new PercentType(val.getAsBigDecimal()));
569 updateState(basicChannel.getChannel(), new StringType(val.getAsString()));
572 updateState(basicChannel.getChannel(), val.getAsString().toLowerCase().equals("on")
573 || val.getAsString().toLowerCase().equals("true") ? OnOffType.ON : OnOffType.OFF);
576 Color rgb = new Color(val.getAsInt());
577 HSBType hsb = HSBType.fromRGB(rgb.getRed(), rgb.getGreen(), rgb.getBlue());
578 updateState(basicChannel.getChannel(), hsb);
581 logger.debug("No update logic for channeltype '{}' ", basicChannel.getType());
583 } catch (Exception e) {
584 logger.debug("Error updating {} property {} with '{}' : {}: {}", getThing().getUID(),
585 basicChannel.getChannel(), val, e.getClass().getCanonicalName(), e.getMessage());
586 logger.trace("Property update error detail:", e);
590 private void quantityTypeUpdate(MiIoBasicChannel basicChannel, JsonElement val, String type) {
591 if (!basicChannel.getUnit().isBlank()) {
592 Unit<?> unit = MiIoQuantiyTypes.get(basicChannel.getUnit());
594 logger.debug("'{}' channel '{}' has unit '{}' with symbol '{}'.", getThing().getUID(),
595 basicChannel.getChannel(), basicChannel.getUnit(), unit);
596 updateState(basicChannel.getChannel(), new QuantityType<>(val.getAsBigDecimal(), unit));
598 logger.debug("Unit '{}' used by '{}' channel '{}' is not found.. using default unit.",
599 getThing().getUID(), basicChannel.getUnit(), basicChannel.getChannel());
602 // if no unit is provided or unit not found use default units, these units have so far been seen for miio
604 switch (type.toLowerCase()) {
606 updateState(basicChannel.getChannel(), new QuantityType<>(val.getAsBigDecimal(), SIUnits.CELSIUS));
608 case "electriccurrent":
609 updateState(basicChannel.getChannel(),
610 new QuantityType<>(val.getAsBigDecimal(), SmartHomeUnits.AMPERE));
613 updateState(basicChannel.getChannel(), new QuantityType<>(val.getAsBigDecimal(), SmartHomeUnits.WATT));
616 updateState(basicChannel.getChannel(), new QuantityType<>(val.getAsBigDecimal(), SmartHomeUnits.HOUR));
619 updateState(basicChannel.getChannel(), new DecimalType(val.getAsBigDecimal()));
624 public void onMessageReceived(MiIoSendCommand response) {
625 super.onMessageReceived(response);
626 if (response.isError()) {
630 switch (response.getCommand()) {
636 if (response.getResult().isJsonArray()) {
637 updatePropsFromJsonArray(response);
638 } else if (response.getResult().isJsonObject()) {
639 updatePropsFromJsonObject(response);
643 if (refreshListCustomCommands.containsKey(response.getMethod())) {
644 logger.debug("Processing custom refresh command response for !{}", response.getMethod());
645 MiIoBasicChannel ch = refreshListCustomCommands.get(response.getMethod());
646 if (response.getResult().isJsonArray()) {
647 JsonArray cmdResponse = response.getResult().getAsJsonArray();
648 final String transformation = ch.getTransfortmation();
649 if (transformation == null || transformation.isBlank()) {
650 updateChannel(ch, ch.getChannel(),
651 cmdResponse.get(0).isJsonPrimitive() ? cmdResponse.get(0)
652 : new JsonPrimitive(cmdResponse.get(0).toString()));
654 updateChannel(ch, ch.getChannel(), cmdResponse);
657 updateChannel(ch, ch.getChannel(), new JsonPrimitive(response.getResult().toString()));
662 } catch (Exception e) {
663 logger.debug("Error while handing message {}", response.getResponse(), e);