-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zigbee] Add a color temperature absolute channel (#868)
* [zigbee] Add color temperature absolute channel Signed-off-by: AndrewFG <[email protected]> * adopt reviewer suggestions Signed-off-by: AndrewFG <[email protected]> * doc and quality improvements Signed-off-by: AndrewFG <[email protected]> * tweaks and refactoring Signed-off-by: AndrewFG <[email protected]> * fix channel type id; add documentation Signed-off-by: AndrewFG <[email protected]> --------- Signed-off-by: AndrewFG <[email protected]>
- Loading branch information
Showing
5 changed files
with
108 additions
and
11 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
94 changes: 94 additions & 0 deletions
94
.../java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTempAbsolute.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,94 @@ | ||
/** | ||
* 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.zigbee.internal.converter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.openhab.binding.zigbee.ZigBeeBindingConstants; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.library.unit.Units; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.openhab.core.thing.binding.builder.ChannelBuilder; | ||
import org.openhab.core.types.Command; | ||
import org.openhab.core.types.StateDescriptionFragmentBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.zsmartsystems.zigbee.ZigBeeEndpoint; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttribute; | ||
import com.zsmartsystems.zigbee.zcl.clusters.ZclColorControlCluster; | ||
import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToColorTemperatureCommand; | ||
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType; | ||
|
||
/** | ||
* Channel converter for absolute color temperature based on {@link ZigBeeConverterColorTemperature}, that converts | ||
* between the color control cluster and a QuantityType<Temperature> channel. | ||
* | ||
* @author Andrew Fiddian-Green - Initial Contribution | ||
*/ | ||
public class ZigBeeConverterColorTempAbsolute extends ZigBeeConverterColorTemperature { | ||
|
||
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterColorTempAbsolute.class); | ||
|
||
@Override | ||
public boolean initializeConverter(ZigBeeThingHandler thing) { | ||
if (super.initializeConverter(thing)) { | ||
stateDescription = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.valueOf(kelvinMin)) | ||
.withMaximum(BigDecimal.valueOf(kelvinMax)).withStep(BigDecimal.valueOf(100)).withPattern("%.0f K") | ||
.build().toStateDescription(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void handleCommand(final Command command) { | ||
if (command instanceof QuantityType<?> quantity) { | ||
QuantityType<?> mired = quantity.toInvertibleUnit(Units.MIRED); | ||
if (mired != null) { | ||
MoveToColorTemperatureCommand zclCommand = new MoveToColorTemperatureCommand(mired.intValue(), 10); | ||
monitorCommandResponse(command, clusterColorControl.sendCommand(zclCommand)); | ||
} | ||
return; | ||
} | ||
super.handleCommand(command); | ||
} | ||
|
||
@Override | ||
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | ||
return super.getChannel(thingUID, endpoint) == null ? null | ||
: ChannelBuilder | ||
.create(createChannelUID(thingUID, endpoint, | ||
ZigBeeBindingConstants.CHANNEL_NAME_COLOR_TEMP_ABSOLUTE), | ||
ZigBeeBindingConstants.ITEM_TYPE_NUMBER_TEMPERATURE) | ||
.withType(ZigBeeBindingConstants.CHANNEL_COLOR_TEMP_ABSOLUTE) | ||
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_COLOR_TEMPERATURE) | ||
.withProperties(createProperties(endpoint)).build(); | ||
} | ||
|
||
@Override | ||
public void attributeUpdated(ZclAttribute attribute, Object val) { | ||
if (attribute.getClusterType() == ZclClusterType.COLOR_CONTROL | ||
&& attribute.getId() == ZclColorControlCluster.ATTR_COLORTEMPERATURE) { | ||
logger.debug("{}: ZigBee attribute reports {} on endpoint {}", endpoint.getIeeeAddress(), attribute, | ||
endpoint.getEndpointId()); | ||
if (val instanceof Integer mired) { | ||
updateChannelState(QuantityType.valueOf(mired, Units.MIRED)); | ||
} | ||
return; | ||
} | ||
super.attributeUpdated(attribute, val); | ||
} | ||
} |
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