Add unitHint to AbstractStorageBasedTypeProvider.ChannelTypeEntity (#4317)

* Add unitHint to AbstractStorageBasedTypeProvider.ChannelTypeEntity

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
This commit is contained in:
Anders Alfredsson 2024-07-14 20:18:03 +02:00 committed by GitHub
parent 9d4ec613a2
commit 98554af952
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -251,6 +251,7 @@ public abstract class AbstractStorageBasedTypeProvider
entity.commandDescription = channelType.getCommandDescription(); entity.commandDescription = channelType.getCommandDescription();
entity.event = channelType.getEvent(); entity.event = channelType.getEvent();
entity.autoUpdatePolicy = channelType.getAutoUpdatePolicy(); entity.autoUpdatePolicy = channelType.getAutoUpdatePolicy();
entity.unitHint = channelType.getUnitHint();
return entity; return entity;
} }
@ -334,6 +335,9 @@ public abstract class AbstractStorageBasedTypeProvider
if (entity.autoUpdatePolicy != null) { if (entity.autoUpdatePolicy != null) {
stateBuilder.withAutoUpdatePolicy(Objects.requireNonNull(entity.autoUpdatePolicy)); stateBuilder.withAutoUpdatePolicy(Objects.requireNonNull(entity.autoUpdatePolicy));
} }
if (entity.unitHint != null) {
stateBuilder.withUnitHint(entity.unitHint);
}
} }
if (builder instanceof TriggerChannelTypeBuilderImpl triggerBuilder) { if (builder instanceof TriggerChannelTypeBuilderImpl triggerBuilder) {
if (entity.event != null) { if (entity.event != null) {
@ -424,6 +428,7 @@ public abstract class AbstractStorageBasedTypeProvider
public @Nullable CommandDescription commandDescription; public @Nullable CommandDescription commandDescription;
public @Nullable EventDescription event; public @Nullable EventDescription event;
public @Nullable AutoUpdatePolicy autoUpdatePolicy; public @Nullable AutoUpdatePolicy autoUpdatePolicy;
public @Nullable String unitHint;
} }
static class ChannelGroupTypeEntity { static class ChannelGroupTypeEntity {

View File

@ -48,14 +48,15 @@ public class AbstractStorageBasedTypeProviderTest {
@Test @Test
public void testStateChannelTypeProperlyMappedToEntityAndBack() { 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") .withDescription("testDescription").withCategory("testCategory")
.withConfigDescriptionURI(URI.create("testBinding:testConfig")) .withConfigDescriptionURI(URI.create("testBinding:testConfig"))
.withAutoUpdatePolicy(AutoUpdatePolicy.VETO).isAdvanced(true).withTag("testTag") .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).isAdvanced(true).withTag("testTag")
.withCommandDescription(CommandDescriptionBuilder.create().build()) .withCommandDescription(CommandDescriptionBuilder.create().build())
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().build()).build(); .withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().build()).withUnitHint("km")
.build();
AbstractStorageBasedTypeProvider.ChannelTypeEntity entity = AbstractStorageBasedTypeProvider AbstractStorageBasedTypeProvider.ChannelTypeEntity entity = AbstractStorageBasedTypeProvider
.mapToEntity(expected); .mapToEntity(expected);
ChannelType actual = AbstractStorageBasedTypeProvider.mapFromEntity(entity); ChannelType actual = AbstractStorageBasedTypeProvider.mapFromEntity(entity);
@ -73,6 +74,7 @@ public class AbstractStorageBasedTypeProviderTest {
assertThat(actual.getState(), is(expected.getState())); assertThat(actual.getState(), is(expected.getState()));
assertThat(actual.getItemType(), is(expected.getItemType())); assertThat(actual.getItemType(), is(expected.getItemType()));
assertThat(actual.getTags(), hasItems(expected.getTags().toArray(String[]::new))); assertThat(actual.getTags(), hasItems(expected.getTags().toArray(String[]::new)));
assertThat(actual.getUnitHint(), is(expected.getUnitHint()));
} }
@Test @Test