]> git.basschouten.com Git - openhab-addons.git/commitdiff
[wemo] Add dimensions for power/energy channel types for Insight Switch. (#11208)
authorjlaur <jacob-github@vindvejr.dk>
Wed, 8 Sep 2021 18:36:03 +0000 (20:36 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Sep 2021 18:36:03 +0000 (20:36 +0200)
* Add dimensions for power/energy channel types for Insight Switch.

Fixes #11207

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.wemo/README.md
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java
bundles/org.openhab.binding.wemo/src/main/resources/OH-INF/thing/thing-types.xml
itests/org.openhab.binding.wemo.tests/src/main/java/org/openhab/binding/wemo/internal/handler/test/WemoHandlerTest.java

index 08142904bd55e906a5180eeb3f43da1c7c6cd6e3..0bb98e837c2957f09f248b29bb0d8b64f4220904 100644 (file)
@@ -40,59 +40,59 @@ MZ100 94103EA2B278xxxx [ deviceID="94103EA2B278xxxx" ]
 
 Devices support some of the following channels:
 
-| Channel Type        | Item Type | Description                                             | Available on Thing                                                                                                                                                    | 
-|---------------------|-----------|---------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| motionDetection     | Switch    | On if motion is detected, off otherwise. (Motion Sensor only) | Motion                                                                                                                                                          |
-| lastMotionDetected  | DateTime  | Date and Time when the last motion was detected. (Motion Sensor only) | Motion                                                                                                                                                  |
-| state               | Switch    | This channel controls the actual binary State of a Device or represents Motion Detection. | All but Dimmer, Crockpot, Airpurifier and Humidifier                                                                                                                     |
-| lastChangedAt       | DateTime  | Date and Time the device was last turned on or of. | Insight                                                                                                                                                                    |
-| lastOnFor           | Number    | Time in seconds an Insight device was last turned on for. | Insight                                                                                                                                                            |
-| onToday             | Number    | Time in seconds an Insight device has been switched on today. | Insight                                                                                                                                                        |
-| onTotal             | Number    | Time in seconds an Insight device has been switched on totally. | Insight                                                                                                                                                      |
-| timespan            | Number    | Time in seconds over which onTotal applies. Typically 2 weeks except first used. | Insight                                                                                                                                      |
-| averagePower        | Number    | Average power consumption in Watts. | Insight                                                                                                                                                                                  |
-| currentPower        | Number    | Current power consumption of an Insight device. 0 if switched off. | Insight                                                                                                                                                    |
-| energyToday         | Number    | Energy in Wh used today. | Insight                                                                                                                                                                                              |
-| energyTotal         | Number    | Energy in Wh used in total. | Insight                                                                                                                                                                                          |
-| standbyLimit        | Number    | Minimum energy draw in W to register device as switched on (default 8W, configurable via WeMo App).  | Insight                                                                                                                  |
-| onStandBy           | Switch    | Read-only indication of whether  or not the device plugged in to the insight switch is drawing more than the standby limit. | Insight                                                                                          |
-| relay               | Switch    | Switches the integrated relay contact close/open | Maker                                                                                                                                                                        |
-| sensor              | Switch    | Shows the state of the integrated sensor | Maker                                                                                                                                                                                |
-| coffeeMode          | String    | Operation mode of a WeMo Coffee Maker | CoffeeMaker                                                                                                                                                                            |
-| modeTime            | Number    | Current amount of time, in minutes, that the Coffee Maker has been in the current mode | CoffeeMaker                                                                                                                            |
-| timeRemaining       | Number    | Remaining brewing time of a WeMo Coffee Maker | CoffeeMaker                                                                                                                                                                    |
-| waterLevelReached   | Switch    | Indicates if the WeMo Coffee Maker needs to be refilled | CoffeeMaker                                                                                                                                                          |
-| cleanAdvise         | Switch    | Indicates if a WeMo Coffee Maker needs to be cleaned | CoffeeMaker                                                                                                                                                              |
-| filterAdvise        | Switch    | Indicates if a WeMo Coffee Maker needs to have the filter changed | CoffeeMaker                                                                                                                                                |
-| brewed              | DateTime  | Date/time the coffee maker last completed brewing coffee | CoffeeMaker                                                                                                                                                          |
-| lastCleaned         | DateTime  | Date/time the coffee maker last completed cleaning | CoffeeMaker                                                                                                                                                                |
-| brightness          | Number    | Brightness of a WeMo LED od Dimmwer. | LED, DimmerSwitch                                                                                                                                                                        |
-| faderCountDownTime  | Number    | Dimmer fading duration time in minutes | DimmerSwitch                                                                                                                                                                          |
-| faderEnabled        | Switch    | Switch the fader ON/OFF | DimmerSwitch                                                                                                                                                                                          |
-| timerStart          | Switch    | Switch the fading timer ON/OFF | DimmerSwitch                                                                                                                                                                                  |
-| nightMode           | Switch    | Switch the nightMode ON/OFF | DimmerSwitch                                                                                                                                                                                      |
-| startTime           | DateTime  | Time when the nightMode starts | DimmerSwitch                                                                                                                                                                                  |
-| endTime             | DateTime  | Time when the nightMode ends | DimmerSwitch                                                                                                                                                                                    |
-| nightModeBrightness | Number    | Brightness used in nightMode | DimmerSwitch                                                                                                                                                                                    |
-| cookMode            | String    | Shows the operation mode of a WeMo Crockpot (OFF, WARM, LOW, HIGH | Crockpot                                                                                                                                                                                    |
-| warmCookTime        | Number    | Shows the timer settings for warm cooking mode | Crockpot                                                                                                                                                                                    |
-| lowCookTime         | Number    | Shows the timer settings for low cooking mode | Crockpot                                                                                                                                                                                    |
-| highCookTime        | Number    | Shows the timer settings for high cooking mode | Crockpot                                                                                                                                                                                    |
-| cookedTime          | Number    | Shows the elapsed cooking time | Crockpot                                                                                                                                                                                    |
-| purifierMode        | String    | Runmode of Air Purifier (OFF, LOW, MED, HIGH, AUTO) | Air Purifier                                                                                                                                                                                    |
-| airQuality          | String    | Air quality (POOR, MODERATE, GOOD) | Air Purifier                                                                                                                                                                                    |
-| ionizer             | Switch    | Indicates whether the ionizer is switched ON or OFF | Air Purifier                                                                                                                                                                                    |
-| filterLife          | Number    | Indicates the remaining filter lifetime in Percent | Air Purifier, Humidifier                                                                                                                                                                                    |
-| expiredFilterTime   | Number    | Indicates whether the filter lifetime has expired or not | Air Purifier, Humidifier                                                                                                                                                                                    |
-| filterPresent       | Switch    | Indicates the presence of an air filter | Air Purifier                                                                                                                                                                                    |
-| humidifierMode      | String    | Runmode of Humidifier (OFF, MIN, LOW, MED, HIGH, MAX) | Humidifier                                                                                                                                                                                    |
-| desiredHumidity     | Number    | Shows desired humidity in Percent | Humidifier                                                                                                                                                                                    |
-| currentHumidity     | Number    | Shows current humidity in Percent | Humidifier                                                                                                                                                                                    |
-| heaterMode          | String    | Runmode of Heater (OFF, FROSTPROTECT, HIGH, LOW, ECO) | Heater                                                                                                                                                                                    |
-| currentTemp         | Number    | Shows current temperature | Heater                                                                                                                                                                                    |
-| targetTemp          | Number    | Shows target temperature  | Heater                                                                                                                                                                                    |
-| autoOffTime         | DateTime  | Time when the heater switches off | Heater                                                                                                                                                                                  |
-| heatingRemaining    | Number    | Shows the remaining heating time  | Heater                                                                                                                                                                                    |
+| Channel Type        | Item Type     | Description                                                                                                                | Available on Thing                                   | 
+|---------------------|---------------|----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|
+| motionDetection     | Switch        | On if motion is detected, off otherwise. (Motion Sensor only)                                                              | Motion                                               |
+| lastMotionDetected  | DateTime      | Date and Time when the last motion was detected. (Motion Sensor only)                                                      | Motion                                               |
+| state               | Switch        | This channel controls the actual binary State of a Device or represents Motion Detection.                                  | All but Dimmer, Crockpot, Airpurifier and Humidifier |
+| lastChangedAt       | DateTime      | Date and Time the device was last turned on or of.                                                                         | Insight                                              |
+| lastOnFor           | Number        | Time in seconds an Insight device was last turned on for.                                                                  | Insight                                              |
+| onToday             | Number        | Time in seconds an Insight device has been switched on today.                                                              | Insight                                              |
+| onTotal             | Number        | Time in seconds an Insight device has been switched on totally.                                                            | Insight                                              |
+| timespan            | Number        | Time in seconds over which onTotal applies. Typically 2 weeks except first used.                                           | Insight                                              |
+| averagePower        | Number:Power  | Average power consumption in Watts.                                                                                        | Insight                                              |
+| currentPower        | Number:Power  | Current power consumption of an Insight device. 0 if switched off.                                                         | Insight                                              |
+| energyToday         | Number:Energy | Energy in Wh used today.                                                                                                   | Insight                                              |
+| energyTotal         | Number:Energy | Energy in Wh used in total.                                                                                                | Insight                                              |
+| standbyLimit        | Number:Power  | Minimum energy draw in W to register device as switched on (default 8W, configurable via WeMo App).                        | Insight                                              |
+| onStandBy           | Switch        | Read-only indication of whether or not the device plugged in to the insight switch is drawing more than the standby limit. | Insight                                              |
+| relay               | Switch        | Switches the integrated relay contact close/open                                                                           | Maker                                                |
+| sensor              | Switch        | Shows the state of the integrated sensor                                                                                   | Maker                                                |
+| coffeeMode          | String        | Operation mode of a WeMo Coffee Maker                                                                                      | CoffeeMaker                                          |
+| modeTime            | Number        | Current amount of time, in minutes, that the Coffee Maker has been in the current mode                                     | CoffeeMaker                                          |
+| timeRemaining       | Number        | Remaining brewing time of a WeMo Coffee Maker                                                                              | CoffeeMaker                                          |
+| waterLevelReached   | Switch        | Indicates if the WeMo Coffee Maker needs to be refilled                                                                    | CoffeeMaker                                          |
+| cleanAdvise         | Switch        | Indicates if a WeMo Coffee Maker needs to be cleaned                                                                       | CoffeeMaker                                          |
+| filterAdvise        | Switch        | Indicates if a WeMo Coffee Maker needs to have the filter changed                                                          | CoffeeMaker                                          |
+| brewed              | DateTime      | Date/time the coffee maker last completed brewing coffee                                                                   | CoffeeMaker                                          |
+| lastCleaned         | DateTime      | Date/time the coffee maker last completed cleaning                                                                         | CoffeeMaker                                          |
+| brightness          | Number        | Brightness of a WeMo LED od Dimmwer.                                                                                       | LED, DimmerSwitch                                    |
+| faderCountDownTime  | Number        | Dimmer fading duration time in minutes                                                                                     | DimmerSwitch                                         |
+| faderEnabled        | Switch        | Switch the fader ON/OFF                                                                                                    | DimmerSwitch                                         |
+| timerStart          | Switch        | Switch the fading timer ON/OFF                                                                                             | DimmerSwitch                                         |
+| nightMode           | Switch        | Switch the nightMode ON/OFF                                                                                                | DimmerSwitch                                         |
+| startTime           | DateTime      | Time when the nightMode starts                                                                                             | DimmerSwitch                                         |
+| endTime             | DateTime      | Time when the nightMode ends                                                                                               | DimmerSwitch                                         |
+| nightModeBrightness | Number        | Brightness used in nightMode                                                                                               | DimmerSwitch                                         |
+| cookMode            | String        | Shows the operation mode of a WeMo Crockpot (OFF, WARM, LOW, HIGH                                                          | Crockpot                                             |
+| warmCookTime        | Number        | Shows the timer settings for warm cooking mode                                                                             | Crockpot                                             |
+| lowCookTime         | Number        | Shows the timer settings for low cooking mode                                                                              | Crockpot                                             |
+| highCookTime        | Number        | Shows the timer settings for high cooking mode                                                                             | Crockpot                                             |
+| cookedTime          | Number        | Shows the elapsed cooking time                                                                                             | Crockpot                                             |
+| purifierMode        | String        | Runmode of Air Purifier (OFF, LOW, MED, HIGH, AUTO)                                                                        | Air Purifier                                         |
+| airQuality          | String        | Air quality (POOR, MODERATE, GOOD)                                                                                         | Air Purifier                                         |
+| ionizer             | Switch        | Indicates whether the ionizer is switched ON or OFF                                                                        | Air Purifier                                         |
+| filterLife          | Number        | Indicates the remaining filter lifetime in Percent                                                                         | Air Purifier, Humidifier                             |
+| expiredFilterTime   | Number        | Indicates whether the filter lifetime has expired or not                                                                   | Air Purifier, Humidifier                             |
+| filterPresent       | Switch        | Indicates the presence of an air filter                                                                                    | Air Purifier                                         |
+| humidifierMode      | String        | Runmode of Humidifier (OFF, MIN, LOW, MED, HIGH, MAX)                                                                      | Humidifier                                           |
+| desiredHumidity     | Number        | Shows desired humidity in Percent                                                                                          | Humidifier                                           |
+| currentHumidity     | Number        | Shows current humidity in Percent                                                                                          | Humidifier                                           |
+| heaterMode          | String        | Runmode of Heater (OFF, FROSTPROTECT, HIGH, LOW, ECO)                                                                      | Heater                                               |
+| currentTemp         | Number        | Shows current temperature                                                                                                  | Heater                                               |
+| targetTemp          | Number        | Shows target temperature                                                                                                   | Heater                                               |
+| autoOffTime         | DateTime      | Time when the heater switches off                                                                                          | Heater                                               |
+| heatingRemaining    | Number        | Shows the remaining heating time                                                                                           | Heater                                               |
 
 
 ## Full Example
@@ -124,7 +124,7 @@ DateTime MotionDetected      { channel="wemo:Motion:Sensor1:lastMotionDetected"
 
 // Insight
 Switch InsightSwitch         { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:state" }
-Number InsightPower          { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:currentPower" }
+Number:Power InsightPower    { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:currentPower" }
 Number InsightLastOn         { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:lastOnFor" }
 Number InsightToday          { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:onToday" }
 Number InsightTotal          { channel="wemo:insight:Insight-1_0-xxxxxxxxxxxxxx:onTotal" }
index 41a53c4deb5fb136d823d28d217c8aa26155825e..50191917aab67ad3526457561d759b80c00f861b 100644 (file)
@@ -39,6 +39,8 @@ import org.openhab.core.io.transport.upnp.UpnpIOService;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.QuantityType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
@@ -245,13 +247,16 @@ public class WemoHandler extends AbstractWemoHandler implements UpnpIOParticipan
                 logger.trace("New InsightParam timespan '{}' for device '{}' received", timespan, getThing().getUID());
                 updateState(CHANNEL_TIMESPAN, timespan);
 
-                State averagePower = DecimalType.valueOf(splitInsightParams[6]); // natively given in W
+                State averagePower = new QuantityType<>(DecimalType.valueOf(splitInsightParams[6]), Units.WATT); // natively
+                                                                                                                 // given
+                                                                                                                 // in W
                 logger.trace("New InsightParam averagePower '{}' for device '{}' received", averagePower,
                         getThing().getUID());
                 updateState(CHANNEL_AVERAGEPOWER, averagePower);
 
                 BigDecimal currentMW = new BigDecimal(splitInsightParams[7]);
-                State currentPower = new DecimalType(currentMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate
+                State currentPower = new QuantityType<>(currentMW.divide(new BigDecimal(1000), 0, RoundingMode.HALF_UP),
+                        Units.WATT); // recalculate
                 // mW to W
                 logger.trace("New InsightParam currentPower '{}' for device '{}' received", currentPower,
                         getThing().getUID());
@@ -259,29 +264,30 @@ public class WemoHandler extends AbstractWemoHandler implements UpnpIOParticipan
 
                 BigDecimal energyTodayMWMin = new BigDecimal(splitInsightParams[8]);
                 // recalculate mW-mins to Wh
-                State energyToday = new DecimalType(
-                        energyTodayMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP));
+                State energyToday = new QuantityType<>(
+                        energyTodayMWMin.divide(new BigDecimal(60000), 0, RoundingMode.HALF_UP), Units.WATT_HOUR);
                 logger.trace("New InsightParam energyToday '{}' for device '{}' received", energyToday,
                         getThing().getUID());
                 updateState(CHANNEL_ENERGYTODAY, energyToday);
 
                 BigDecimal energyTotalMWMin = new BigDecimal(splitInsightParams[9]);
                 // recalculate mW-mins to Wh
-                State energyTotal = new DecimalType(
-                        energyTotalMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP));
+                State energyTotal = new QuantityType<>(
+                        energyTotalMWMin.divide(new BigDecimal(60000), 0, RoundingMode.HALF_UP), Units.WATT_HOUR);
                 logger.trace("New InsightParam energyTotal '{}' for device '{}' received", energyTotal,
                         getThing().getUID());
                 updateState(CHANNEL_ENERGYTOTAL, energyTotal);
 
                 BigDecimal standByLimitMW = new BigDecimal(splitInsightParams[10]);
-                State standByLimit = new DecimalType(standByLimitMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate
+                State standByLimit = new QuantityType<>(
+                        standByLimitMW.divide(new BigDecimal(1000), 0, RoundingMode.HALF_UP), Units.WATT); // recalculate
                 // mW to W
                 logger.trace("New InsightParam standByLimit '{}' for device '{}' received", standByLimit,
                         getThing().getUID());
                 updateState(CHANNEL_STANDBYLIMIT, standByLimit);
 
-                if (currentMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP).intValue() > standByLimitMW
-                        .divide(new BigDecimal(1000), RoundingMode.HALF_UP).intValue()) {
+                if (currentMW.divide(new BigDecimal(1000), 0, RoundingMode.HALF_UP).intValue() > standByLimitMW
+                        .divide(new BigDecimal(1000), 0, RoundingMode.HALF_UP).intValue()) {
                     updateState(CHANNEL_ONSTANDBY, OnOffType.OFF);
                 } else {
                     updateState(CHANNEL_ONSTANDBY, OnOffType.ON);
index abeed8e6bcfc29b23707015d76e9e4bdaf783f9a..f60e7a507a1741260dce394c5899eec08444e4ca 100644 (file)
        </channel-type>
 
        <channel-type id="averagePower" advanced="true">
-               <item-type>Number</item-type>
+               <item-type>Number:Power</item-type>
                <label>Average Power</label>
                <description>The average power consumption</description>
                <category>Energy</category>
-               <state pattern="%.1f W"/>
+               <state pattern="%.0f %unit%"/>
        </channel-type>
 
        <channel-type id="currentPower">
-               <item-type>Number</item-type>
+               <item-type>Number:Power</item-type>
                <label>Power</label>
                <description>The current power consumption</description>
                <category>Energy</category>
-               <state pattern="%.1f W"/>
+               <state pattern="%.0f %unit%"/>
        </channel-type>
 
        <channel-type id="energyToday" advanced="true">
-               <item-type>Number</item-type>
+               <item-type>Number:Energy</item-type>
                <label>Energy Today</label>
                <description>Todays power consumption</description>
                <category>Energy</category>
-               <state pattern="%.1f Wh"/>
+               <state pattern="%.0f %unit%"/>
        </channel-type>
 
        <channel-type id="energyTotal" advanced="true">
-               <item-type>Number</item-type>
+               <item-type>Number:Energy</item-type>
                <label>Energy Total</label>
                <description>Total power consumption</description>
                <category>Energy</category>
-               <state pattern="%.1f Wh"/>
+               <state pattern="%.0f %unit%"/>
        </channel-type>
 
        <channel-type id="standByLimit" advanced="true">
-               <item-type>Number</item-type>
+               <item-type>Number:Power</item-type>
                <label>StandBy Limit</label>
-               <description>Total power consumption</description>
+               <description>Minimum energy draw to register device as switched on</description>
                <category>Energy</category>
-               <state pattern="%.1f W"/>
+               <state pattern="%.0f %unit%"/>
        </channel-type>
 
        <channel-type id="onStandBy" advanced="true">
                <description>Allows to switch the timer ON/OFF</description>
        </channel-type>
 
-
        <channel-type id="nightMode" advanced="true">
                <item-type>Switch</item-type>
                <label>NightMode OFF/ON</label>
index 144fa25e62329811ca082855620247926d5a95fb..c317b9dc5e4bd63f7a689d9f4a01e87a956907d0 100644 (file)
@@ -25,6 +25,8 @@ import org.openhab.binding.wemo.internal.handler.WemoHandler;
 import org.openhab.binding.wemo.internal.http.WemoHttpCall;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.QuantityType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingStatusDetail;
@@ -122,7 +124,7 @@ public class WemoHandlerTest {
     @Test
     public void assertThatChannelAVERAGEPOWERIsUpdatedOnReceivedValue() {
         insightParams.avgPower = POWER_PARAM;
-        State expectedStateType = new DecimalType(POWER_PARAM);
+        State expectedStateType = new QuantityType<>(POWER_PARAM, Units.WATT);
         String expectedChannel = CHANNEL_AVERAGEPOWER;
 
         testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());