Adding UV Index system channel (#3878)

* Adding UV Index system channel

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2024-05-20 12:09:52 +02:00 committed by GitHub
parent c40b82f16e
commit 6887db3b89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -105,6 +105,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
"electric-voltage"); "electric-voltage");
public static final ChannelTypeUID SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_ENERGY = new ChannelTypeUID(BINDING_ID, public static final ChannelTypeUID SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_ENERGY = new ChannelTypeUID(BINDING_ID,
"electric-energy"); "electric-energy");
public static final ChannelTypeUID SYSTEM_CHANNEL_TYPE_UID_UV_INDEX = new ChannelTypeUID(BINDING_ID, "uv-index");
/** /**
* Signal strength default system wide {@link ChannelType}. Represents signal strength of a device as a number * Signal strength default system wide {@link ChannelType}. Represents signal strength of a device as a number
@ -397,6 +398,15 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build()) StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
.withTags(List.of("Measurement", "Energy")).build(); .withTags(List.of("Measurement", "Energy")).build();
/**
* UV Index: system wide {@link ChannelType} which shows the UV Index
*/
public static final ChannelType SYSTEM_UV_INDEX = ChannelTypeBuilder
.state(SYSTEM_CHANNEL_TYPE_UID_UV_INDEX, "UV Index", CoreItemFactory.NUMBER)
.withDescription("Current UV index").withStateDescriptionFragment(StateDescriptionFragmentBuilder.create()
.withReadOnly(true).withPattern("%d").withMinimum(BigDecimal.ONE).build())
.withTags(List.of("Measurement", "Ultraviolet")).build();
private static final Collection<ChannelType> CHANNEL_TYPES = List.of(SYSTEM_CHANNEL_SIGNAL_STRENGTH, private static final Collection<ChannelType> CHANNEL_TYPES = List.of(SYSTEM_CHANNEL_SIGNAL_STRENGTH,
SYSTEM_CHANNEL_LOW_BATTERY, SYSTEM_CHANNEL_BATTERY_LEVEL, SYSTEM_TRIGGER, SYSTEM_RAWBUTTON, SYSTEM_BUTTON, SYSTEM_CHANNEL_LOW_BATTERY, SYSTEM_CHANNEL_BATTERY_LEVEL, SYSTEM_TRIGGER, SYSTEM_RAWBUTTON, SYSTEM_BUTTON,
SYSTEM_RAWROCKER, SYSTEM_POWER, SYSTEM_LOCATION, SYSTEM_MOTION, SYSTEM_BRIGHTNESS, SYSTEM_COLOR, SYSTEM_RAWROCKER, SYSTEM_POWER, SYSTEM_LOCATION, SYSTEM_MOTION, SYSTEM_BRIGHTNESS, SYSTEM_COLOR,
@ -404,7 +414,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
SYSTEM_MEDIA_TITLE, SYSTEM_MEDIA_ARTIST, SYSTEM_WIND_DIRECTION, SYSTEM_WIND_SPEED, SYSTEM_MEDIA_TITLE, SYSTEM_MEDIA_ARTIST, SYSTEM_WIND_DIRECTION, SYSTEM_WIND_SPEED,
SYSTEM_OUTDOOR_TEMPERATURE, SYSTEM_INDOOR_TEMPERATURE, SYSTEM_ATMOSPHERIC_HUMIDITY, SYSTEM_OUTDOOR_TEMPERATURE, SYSTEM_INDOOR_TEMPERATURE, SYSTEM_ATMOSPHERIC_HUMIDITY,
SYSTEM_BAROMETRIC_PRESSURE, SYSTEM_ELECTRIC_POWER, SYSTEM_ELECTRIC_CURRENT, SYSTEM_ELECTRIC_VOLTAGE, SYSTEM_BAROMETRIC_PRESSURE, SYSTEM_ELECTRIC_POWER, SYSTEM_ELECTRIC_CURRENT, SYSTEM_ELECTRIC_VOLTAGE,
SYSTEM_ELECTRICAL_ENERGY); SYSTEM_ELECTRICAL_ENERGY, SYSTEM_UV_INDEX);
private final Map<LocalizedKey, ChannelType> localizedChannelTypeCache = new ConcurrentHashMap<>(); private final Map<LocalizedKey, ChannelType> localizedChannelTypeCache = new ConcurrentHashMap<>();

View File

@ -56,3 +56,5 @@ channel-type.system.electric-voltage.label = Electric Voltage
channel-type.system.electric-voltage.description = Current electric voltage channel-type.system.electric-voltage.description = Current electric voltage
channel-type.system.electrical-energy.label = Electrical Energy channel-type.system.electrical-energy.label = Electrical Energy
channel-type.system.electrical-energy.description = Current electrical energy channel-type.system.electrical-energy.description = Current electrical energy
channel-type.system.uv-index.label = UV Index
channel-type.system.uv-index.description = Current UV index

View File

@ -36,7 +36,7 @@ import org.openhab.core.types.StateOption;
@NonNullByDefault @NonNullByDefault
public class SystemWideChannelTypesTest extends JavaOSGiTest { public class SystemWideChannelTypesTest extends JavaOSGiTest {
private static final int NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES = 29; private static final int NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES = 30;
private @NonNullByDefault({}) ChannelTypeProvider systemChannelTypeProvider; private @NonNullByDefault({}) ChannelTypeProvider systemChannelTypeProvider;
@ -81,6 +81,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest {
assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_CURRENT, null)); assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_CURRENT, null));
assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_VOLTAGE, null)); assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_VOLTAGE, null));
assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_ENERGY, null)); assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ELECTRIC_ENERGY, null));
assertNotNull(systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_UV_INDEX, null));
} }
@Test @Test