2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
14 package org.openhab.binding.mqtt.espmilighthub.internal;
16 import static org.openhab.binding.mqtt.espmilighthub.internal.EspMilightHubBindingConstants.*;
18 import java.math.BigDecimal;
19 import java.util.Locale;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.thing.Channel;
24 import org.openhab.core.thing.ThingRegistry;
25 import org.openhab.core.thing.type.DynamicStateDescriptionProvider;
26 import org.openhab.core.types.StateDescription;
27 import org.openhab.core.types.StateDescriptionFragmentBuilder;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31 import org.slf4j.LoggerFactory;
34 * Provides custom state descriptions for system.color-temperature-absolute channels.
36 * @author Cody Cutrer - Initial contribution
38 @Component(service = DynamicStateDescriptionProvider.class)
40 public class EspMilightStateDescriptionProvider implements DynamicStateDescriptionProvider {
41 private final ThingRegistry thingRegistry;
44 public EspMilightStateDescriptionProvider(@Reference ThingRegistry thingRegistry) {
45 this.thingRegistry = thingRegistry;
49 public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original,
50 @Nullable Locale locale) {
51 var logger = LoggerFactory.getLogger(EspMilightStateDescriptionProvider.class);
52 var channelUID = channel.getUID();
53 var thing = thingRegistry.get(channelUID.getThingUID());
54 if (thing == null || !SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())
55 || !channelUID.getId().equals(CHANNEL_COLOURTEMP_ABS)) {
59 StateDescriptionFragmentBuilder builder;
60 if (original != null) {
61 builder = StateDescriptionFragmentBuilder.create(original);
63 builder = StateDescriptionFragmentBuilder.create();
65 builder.withMinimum(BIG_DECIMAL_153).withMaximum(BIG_DECIMAL_370).withStep(BigDecimal.ONE)
66 .withPattern("%d mired");
67 return builder.build().toStateDescription();