-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[various] Lamp handlers expose min/max Color Temperature in state des…
…cription (#17641) * Lamp handlers expose min/max Colour Temperature in state description * add color temperature validit and range checks Signed-off-by: AndrewFG <[email protected]>
- Loading branch information
Showing
10 changed files
with
260 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...src/main/java/org/openhab/binding/lifx/internal/handler/LifxStateDescriptionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.lifx.internal.handler; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.events.EventPublisher; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider; | ||
import org.openhab.core.thing.events.ThingEventFactory; | ||
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService; | ||
import org.openhab.core.thing.link.ItemChannelLinkRegistry; | ||
import org.openhab.core.thing.type.DynamicStateDescriptionProvider; | ||
import org.openhab.core.types.StateDescription; | ||
import org.openhab.core.types.StateDescriptionFragment; | ||
import org.openhab.core.types.StateDescriptionFragmentBuilder; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* The {@link LifxStateDescriptionProvider} provides dynamic state description minimum and maximum vales of color | ||
* temperature channels whose capabilities are dynamically determined at runtime. | ||
* | ||
* @author Andrew Fiddian-Green - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
@Component(service = { DynamicStateDescriptionProvider.class, LifxStateDescriptionProvider.class }) | ||
public class LifxStateDescriptionProvider extends BaseDynamicStateDescriptionProvider { | ||
|
||
private final Map<ChannelUID, StateDescriptionFragment> stateDescriptionFragments = new ConcurrentHashMap<>(); | ||
|
||
@Activate | ||
public LifxStateDescriptionProvider(final @Reference EventPublisher eventPublisher, | ||
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry, | ||
final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) { | ||
this.eventPublisher = eventPublisher; | ||
this.itemChannelLinkRegistry = itemChannelLinkRegistry; | ||
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService; | ||
} | ||
|
||
@Override | ||
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original, | ||
@Nullable Locale locale) { | ||
StateDescriptionFragment stateDescriptionFragment = stateDescriptionFragments.get(channel.getUID()); | ||
return stateDescriptionFragment != null ? stateDescriptionFragment.toStateDescription() | ||
: super.getStateDescription(channel, original, locale); | ||
} | ||
|
||
/** | ||
* Set the state description minimum and maximum values and pattern in Kelvin for the given channel UID | ||
*/ | ||
public void setMinMaxKelvin(ChannelUID channelUID, long minKelvin, long maxKelvin) { | ||
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID); | ||
StateDescriptionFragment newStateDescriptionFragment = StateDescriptionFragmentBuilder.create() | ||
.withMinimum(BigDecimal.valueOf(minKelvin)).withMaximum(BigDecimal.valueOf(maxKelvin)) | ||
.withStep(BigDecimal.valueOf(100)).withPattern("%.0f K").build(); | ||
if (!newStateDescriptionFragment.equals(oldStateDescriptionFragment)) { | ||
stateDescriptionFragments.put(channelUID, newStateDescriptionFragment); | ||
ItemChannelLinkRegistry itemChannelLinkRegistry = this.itemChannelLinkRegistry; | ||
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID, | ||
itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(), | ||
newStateDescriptionFragment, oldStateDescriptionFragment)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../java/org/openhab/binding/nanoleaf/internal/handler/NanoLeafStateDescriptionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.nanoleaf.internal.handler; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.events.EventPublisher; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider; | ||
import org.openhab.core.thing.events.ThingEventFactory; | ||
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService; | ||
import org.openhab.core.thing.link.ItemChannelLinkRegistry; | ||
import org.openhab.core.thing.type.DynamicStateDescriptionProvider; | ||
import org.openhab.core.types.StateDescription; | ||
import org.openhab.core.types.StateDescriptionFragment; | ||
import org.openhab.core.types.StateDescriptionFragmentBuilder; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* The {@link NanoLeafStateDescriptionProvider} provides dynamic state description minimum and maximum vales of color | ||
* temperature channels whose capabilities are dynamically determined at runtime. | ||
* | ||
* @author Andrew Fiddian-Green - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
@Component(service = { DynamicStateDescriptionProvider.class, NanoLeafStateDescriptionProvider.class }) | ||
public class NanoLeafStateDescriptionProvider extends BaseDynamicStateDescriptionProvider { | ||
|
||
private final Map<ChannelUID, StateDescriptionFragment> stateDescriptionFragments = new ConcurrentHashMap<>(); | ||
|
||
@Activate | ||
public NanoLeafStateDescriptionProvider(final @Reference EventPublisher eventPublisher, | ||
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry, | ||
final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) { | ||
this.eventPublisher = eventPublisher; | ||
this.itemChannelLinkRegistry = itemChannelLinkRegistry; | ||
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService; | ||
} | ||
|
||
@Override | ||
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original, | ||
@Nullable Locale locale) { | ||
StateDescriptionFragment stateDescriptionFragment = stateDescriptionFragments.get(channel.getUID()); | ||
return stateDescriptionFragment != null ? stateDescriptionFragment.toStateDescription() | ||
: super.getStateDescription(channel, original, locale); | ||
} | ||
|
||
/** | ||
* Set the state description minimum and maximum values and pattern in Kelvin for the given channel UID | ||
*/ | ||
public void setMinMaxKelvin(ChannelUID channelUID, long minKelvin, long maxKelvin) { | ||
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID); | ||
StateDescriptionFragment newStateDescriptionFragment = StateDescriptionFragmentBuilder.create() | ||
.withMinimum(BigDecimal.valueOf(minKelvin)).withMaximum(BigDecimal.valueOf(maxKelvin)) | ||
.withStep(BigDecimal.valueOf(100)).withPattern("%.0f K").build(); | ||
if (!newStateDescriptionFragment.equals(oldStateDescriptionFragment)) { | ||
stateDescriptionFragments.put(channelUID, newStateDescriptionFragment); | ||
ItemChannelLinkRegistry itemChannelLinkRegistry = this.itemChannelLinkRegistry; | ||
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID, | ||
itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(), | ||
newStateDescriptionFragment, oldStateDescriptionFragment)); | ||
} | ||
} | ||
} |
Oops, something went wrong.