mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
Add unitHint to AbstractStorageBasedTypeProvider.ChannelTypeEntity (#4317)
* Add unitHint to AbstractStorageBasedTypeProvider.ChannelTypeEntity Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
This commit is contained in:
parent
9d4ec613a2
commit
98554af952
@ -251,6 +251,7 @@ public abstract class AbstractStorageBasedTypeProvider
|
||||
entity.commandDescription = channelType.getCommandDescription();
|
||||
entity.event = channelType.getEvent();
|
||||
entity.autoUpdatePolicy = channelType.getAutoUpdatePolicy();
|
||||
entity.unitHint = channelType.getUnitHint();
|
||||
return entity;
|
||||
}
|
||||
|
||||
@ -334,6 +335,9 @@ public abstract class AbstractStorageBasedTypeProvider
|
||||
if (entity.autoUpdatePolicy != null) {
|
||||
stateBuilder.withAutoUpdatePolicy(Objects.requireNonNull(entity.autoUpdatePolicy));
|
||||
}
|
||||
if (entity.unitHint != null) {
|
||||
stateBuilder.withUnitHint(entity.unitHint);
|
||||
}
|
||||
}
|
||||
if (builder instanceof TriggerChannelTypeBuilderImpl triggerBuilder) {
|
||||
if (entity.event != null) {
|
||||
@ -424,6 +428,7 @@ public abstract class AbstractStorageBasedTypeProvider
|
||||
public @Nullable CommandDescription commandDescription;
|
||||
public @Nullable EventDescription event;
|
||||
public @Nullable AutoUpdatePolicy autoUpdatePolicy;
|
||||
public @Nullable String unitHint;
|
||||
}
|
||||
|
||||
static class ChannelGroupTypeEntity {
|
||||
|
@ -48,14 +48,15 @@ public class AbstractStorageBasedTypeProviderTest {
|
||||
|
||||
@Test
|
||||
public void testStateChannelTypeProperlyMappedToEntityAndBack() {
|
||||
ChannelTypeUID channelTypeUID = new ChannelTypeUID("TestBinding:testChannelType");
|
||||
ChannelTypeUID channelTypeUID = new ChannelTypeUID("TestBinding:testQuantityChannelType");
|
||||
|
||||
ChannelType expected = ChannelTypeBuilder.state(channelTypeUID, "testLabel", "Switch")
|
||||
ChannelType expected = ChannelTypeBuilder.state(channelTypeUID, "testLabel", "Number:Length")
|
||||
.withDescription("testDescription").withCategory("testCategory")
|
||||
.withConfigDescriptionURI(URI.create("testBinding:testConfig"))
|
||||
.withAutoUpdatePolicy(AutoUpdatePolicy.VETO).isAdvanced(true).withTag("testTag")
|
||||
.withCommandDescription(CommandDescriptionBuilder.create().build())
|
||||
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().build()).build();
|
||||
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().build()).withUnitHint("km")
|
||||
.build();
|
||||
AbstractStorageBasedTypeProvider.ChannelTypeEntity entity = AbstractStorageBasedTypeProvider
|
||||
.mapToEntity(expected);
|
||||
ChannelType actual = AbstractStorageBasedTypeProvider.mapFromEntity(entity);
|
||||
@ -73,6 +74,7 @@ public class AbstractStorageBasedTypeProviderTest {
|
||||
assertThat(actual.getState(), is(expected.getState()));
|
||||
assertThat(actual.getItemType(), is(expected.getItemType()));
|
||||
assertThat(actual.getTags(), hasItems(expected.getTags().toArray(String[]::new)));
|
||||
assertThat(actual.getUnitHint(), is(expected.getUnitHint()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user