mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-02-04 08:03: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.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 {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user