]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bondhome] Add raw speed channel (#14155)
authorKeith T. Garner <kgarner@kgarner.com>
Thu, 12 Jan 2023 06:42:15 +0000 (00:42 -0600)
committerGitHub <noreply@github.com>
Thu, 12 Jan 2023 06:42:15 +0000 (07:42 +0100)
* [bondhome] add raw speed channel

* Add a channel for the raw speed value from the bond api

Signed-off-by: Keith T. Garner <kgarner@kgarner.com>
bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/BondHomeBindingConstants.java
bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java
bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/i18n/bondhome.properties
bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/thing/ChannelGroups.xml
bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/thing/Channels.xml

index 26ce4a2507f3449d47b622dd7930860030c50623..43f7dc45d5e476ae5842497e439058b88620eab3 100644 (file)
@@ -59,6 +59,7 @@ public class BondHomeBindingConstants {
     public static final String CHANNEL_GROUP_FAN = "fan";
     public static final String CHANNEL_FAN_POWER = CHANNEL_GROUP_FAN + "#power";
     public static final String CHANNEL_FAN_SPEED = CHANNEL_GROUP_FAN + "#speed";
+    public static final String CHANNEL_RAW_FAN_SPEED = CHANNEL_GROUP_FAN + "#rawSpeed";
     public static final String CHANNEL_FAN_BREEZE_STATE = CHANNEL_GROUP_FAN + "#breezeState";
     public static final String CHANNEL_FAN_BREEZE_MEAN = CHANNEL_GROUP_FAN + "#breezeMean";
     public static final String CHANNEL_FAN_BREEZE_VAR = CHANNEL_GROUP_FAN + "#breezeVariability";
index b6a51fbd290806c256b5cc2c555f2569fbf21414..89c7571b81e1b4ffd276e48abb91d453b5010052 100644 (file)
@@ -205,6 +205,27 @@ public class BondDeviceHandler extends BaseThingHandler {
                 }
                 break;
 
+            case CHANNEL_RAW_FAN_SPEED:
+                if (command instanceof DecimalType) {
+                    value = ((DecimalType) command).intValue();
+                    BondDeviceProperties devProperties = this.deviceProperties;
+                    if (devProperties != null) {
+                        if (value < 1) {
+                            // Interpret any 0 or less value as a request to turn off
+                            action = BondDeviceAction.TURN_OFF;
+                            value = null;
+                        } else {
+                            action = BondDeviceAction.SET_SPEED;
+                            value = Math.min(value, devProperties.maxSpeed);
+                        }
+                        logger.trace("Fan raw speed command with speed set as {}, action as {}", value, action);
+                        api.executeDeviceAction(deviceId, action, value);
+                    }
+                } else {
+                    logger.info("Unsupported command on raw fan speed channel");
+                }
+                break;
+
             case CHANNEL_FAN_BREEZE_STATE:
                 logger.trace("Fan enable/disable breeze command");
                 api.executeDeviceAction(deviceId,
@@ -548,6 +569,7 @@ public class BondDeviceHandler extends BaseThingHandler {
         logger.trace("Deleting channels based on the available actions");
         // Get the thing to edit
         ThingBuilder thingBuilder = editThing();
+        final BondDevice devInfo = this.deviceInfo;
 
         // Now, look at the whole list of possible channels
         List<Channel> possibleChannels = this.getThing().getChannels();
@@ -561,10 +583,14 @@ public class BondDeviceHandler extends BaseThingHandler {
             }
         }
         // Remove power channels if we have a dimmer channel for them;
-        // the dimmer channel already covers the power case
+        // the dimmer channel already covers the power case.
+        // Add the raw channel for advanced users if we're a ceiling fan.
         if (availableChannelIds.contains(CHANNEL_FAN_SPEED)) {
             availableChannelIds.remove(CHANNEL_POWER);
             availableChannelIds.remove(CHANNEL_FAN_POWER);
+            if (devInfo != null && devInfo.type == BondDeviceType.CEILING_FAN) {
+                availableChannelIds.add(CHANNEL_RAW_FAN_SPEED);
+            }
         }
         if (availableChannelIds.contains(CHANNEL_LIGHT_BRIGHTNESS)) {
             availableChannelIds.remove(CHANNEL_LIGHT_POWER);
@@ -631,6 +657,7 @@ public class BondDeviceHandler extends BaseThingHandler {
                 logger.info("Unable to convert fan speed to a percent for {}!", this.getThing().getLabel());
             }
             updateState(CHANNEL_FAN_SPEED, formPercentType(fanOn, value));
+            updateState(CHANNEL_RAW_FAN_SPEED, fanOn ? new DecimalType(updateState.speed) : DecimalType.ZERO);
         }
         updateState(CHANNEL_FAN_BREEZE_STATE, updateState.breeze[0] == 0 ? OnOffType.OFF : OnOffType.ON);
         updateState(CHANNEL_FAN_BREEZE_MEAN, new PercentType(updateState.breeze[1]));
index 13a35bc406da7fb2704a8c9fc6c1743e15870431..8fffa5074051639b224ed1ce9230ee359007b272 100644 (file)
@@ -71,6 +71,8 @@ channel-type.bondhome.enableChannelType.label = Enable Up or Down Light
 channel-type.bondhome.enableChannelType.description = Enables or disables the up or down light of the ceiling fan. The light must also be on to turn on the up light.
 channel-type.bondhome.fanSpeedChannelType.label = Fan Speed
 channel-type.bondhome.fanSpeedChannelType.description = Sets fan speed
+channel-type.bondhome.rawFanSpeedChannelType.label = Raw Fan Speed
+channel-type.bondhome.rawFanSpeedChannelType.description = Sets fan speed using raw Bond values
 channel-type.bondhome.flameChannelType.label = Flame Level
 channel-type.bondhome.flameChannelType.description = Turns on or adjust the flame level
 channel-type.bondhome.fpFanSpeedChannelType.label = Fireplace Fan Speed
index 358cb01aa8bf8b6c00bc6bc2ec83abcc81b2cdc2..1298d2397b735244268bb3ce729f4a2415eae981 100644 (file)
@@ -18,6 +18,7 @@
                <label>Ceiling Fan</label>
                <channels>
                        <channel id="speed" typeId="fanSpeedChannelType"/>
+                       <channel id="rawSpeed" typeId="rawFanSpeedChannelType"/>
                        <channel id="breezeState" typeId="breezeStateChannelType"/>
                        <channel id="breezeMean" typeId="breezeMeanChannelType"/>
                        <channel id="breezeVariability" typeId="breezeVariabilityChannelType"/>
index 9314fb03b12ffb8ef221f41ac8ed52d69a59ef85..d029a6c8f18d2a74ebaadfda128c909c58babb0d 100644 (file)
                <category>Heating</category>
        </channel-type>
 
+       <channel-type id="rawFanSpeedChannelType" advanced="true">
+               <item-type>Number</item-type>
+               <label>Raw Fan Speed</label>
+               <description>Sets fan speed using raw Bond values</description>
+               <category>Heating</category>
+       </channel-type>
+
        <channel-type id="breezeStateChannelType">
                <item-type>Switch</item-type>
                <label>Breeze Mode</label>