Skip to content

Commit

Permalink
[tuya] Improve decode color format error handling (#541)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <[email protected]>
  • Loading branch information
jsetton committed Dec 24, 2023
1 parent d1ee7fd commit a616368
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.openhab.core.types.Command;
import org.openhab.core.types.CommandOption;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smarthomej.binding.tuya.internal.config.ChannelConfiguration;
Expand Down Expand Up @@ -163,36 +164,40 @@ private void processChannelStatus(Integer dp, Object value) {
return;
}

if (value instanceof String && CHANNEL_TYPE_UID_COLOR.equals(channelTypeUID)) {
oldColorMode = ((String) value).length() == 14;
updateState(channelId, ConversionUtil.hexColorDecode((String) value));
return;
} else if (value instanceof String && CHANNEL_TYPE_UID_STRING.equals(channelTypeUID)) {
updateState(channelId, new StringType((String) value));
return;
} else if (Double.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_DIMMER.equals(channelTypeUID)) {
updateState(channelId, ConversionUtil.brightnessDecode((double) value, 0, configuration.max));
return;
} else if (Double.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_NUMBER.equals(channelTypeUID)) {
updateState(channelId, new DecimalType((double) value));
return;
} else if (Boolean.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_SWITCH.equals(channelTypeUID)) {
updateState(channelId, OnOffType.from((boolean) value));
return;
} else if (value instanceof String && CHANNEL_TYPE_UID_IR_CODE.equals(channelTypeUID)) {
if (configuration.dp == 2) {
String decoded = convertBase64Code(configuration, (String) value);
logger.info("thing {} received ir code: {}", thing.getUID(), decoded);
updateState(channelId, new StringType(decoded));
irStartLearning(configuration.activeListen);
try {
if (value instanceof String && CHANNEL_TYPE_UID_COLOR.equals(channelTypeUID)) {
oldColorMode = ((String) value).length() == 14;
updateState(channelId, ConversionUtil.hexColorDecode((String) value));
return;
} else if (value instanceof String && CHANNEL_TYPE_UID_STRING.equals(channelTypeUID)) {
updateState(channelId, new StringType((String) value));
return;
} else if (Double.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_DIMMER.equals(channelTypeUID)) {
updateState(channelId, ConversionUtil.brightnessDecode((double) value, 0, configuration.max));
return;
} else if (Double.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_NUMBER.equals(channelTypeUID)) {
updateState(channelId, new DecimalType((double) value));
return;
} else if (Boolean.class.isAssignableFrom(value.getClass())
&& CHANNEL_TYPE_UID_SWITCH.equals(channelTypeUID)) {
updateState(channelId, OnOffType.from((boolean) value));
return;
} else if (value instanceof String && CHANNEL_TYPE_UID_IR_CODE.equals(channelTypeUID)) {
if (configuration.dp == 2) {
String decoded = convertBase64Code(configuration, (String) value);
logger.info("thing {} received ir code: {}", thing.getUID(), decoded);
updateState(channelId, new StringType(decoded));
irStartLearning(configuration.activeListen);
}
return;
}
return;
} catch (IllegalArgumentException ignored) {
}
logger.warn("Could not update channel '{}' of thing '{}' with value '{}'. Datatype incompatible.",
channelId, getThing().getUID(), value);
updateState(channelId, UnDefType.UNDEF);
} else {
// try additional channelDps, only OnOffType
List<String> channelIds = dp2ToChannelId.get(dp);
Expand Down

0 comments on commit a616368

Please sign in to comment.