use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class UidUtilsTest method testGeneratedChannelUIDHasExpectedFormat.
@Test
public void testGeneratedChannelUIDHasExpectedFormat() {
HmDatapoint hmDatapoint = createDimmerHmDatapoint();
ThingUID thingUID = createDimmerThingUID();
ChannelUID channelUID = UidUtils.generateChannelUID(hmDatapoint, thingUID);
assertThat(channelUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3:ABC12345678:1#DIMMER"));
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class UidUtilsTest method testGeneratedChannelTypeUIDHasExpectedFormat.
@Test
public void testGeneratedChannelTypeUIDHasExpectedFormat() {
HmDatapoint hmDatapoint = createDimmerHmDatapoint();
ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(hmDatapoint);
assertThat(channelTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3_1_DIMMER"));
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class DimmerHelper method createDimmerHmDatapoint.
public static HmDatapoint createDimmerHmDatapoint() {
HmDatapoint hmDatapoint = new HmDatapoint();
hmDatapoint.setName("DIMMER");
hmDatapoint.setChannel(createDimmerHmChannel());
return hmDatapoint;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class PercentTypeConverter method commandToBinding.
@Override
protected Object commandToBinding(Command command, HmDatapoint dp) throws ConverterException {
if (command.getClass() == IncreaseDecreaseType.class) {
PercentType type = convertFromBinding(dp);
int percent = type.intValue();
percent += command.equals(IncreaseDecreaseType.INCREASE) ? 10 : -10;
percent = (percent / 10) * 10;
percent = Math.min(100, percent);
percent = Math.max(0, percent);
return convertToBinding(new PercentType(percent), dp);
} else if (command.getClass() == OnOffType.class) {
PercentType type = new PercentType(command.equals(OnOffType.ON) ? 100 : 0);
return convertToBinding(type, dp);
} else if (command.getClass() == UpDownType.class) {
int result = command.equals(UpDownType.UP) ? 100 : 0;
if (MetadataUtils.isRollerShutter(dp)) {
result = command.equals(UpDownType.UP) ? 0 : 100;
}
return convertToBinding(new PercentType(result), dp);
} else {
return super.commandToBinding(command, dp);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class PercentTypeConverter method fromBinding.
@Override
protected PercentType fromBinding(HmDatapoint dp) throws ConverterException {
Double number = ((Number) dp.getValue()).doubleValue();
int percent = (int) ((100 / dp.getMaxValue().doubleValue()) * number);
if (MetadataUtils.isRollerShutter(dp)) {
percent = 100 - percent;
}
return new PercentType(percent);
}
Aggregations