Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tuya] Improve decode color format error handling #541

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading