Skip to content

Commit

Permalink
[homeconnect] 2 channels added for washer appliance
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Jul 31, 2021
1 parent 7e84fe4 commit c363678
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.binding.homeconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ After the bridge has been added and authorized, devices are discovered automatic
| laundry_care_washer_less_ironing | Switch | true | This status indicates whether less ironing is activated for a washer program of the home appliance. | washer, washerdryer |
| laundry_care_washer_pre_wash | Switch | true | This status indicates whether the pre-wash is activated for a washer program of the home appliance. | washer, washerdryer |
| laundry_care_washer_rinse_plus | String | true | This status defines the number of additional rinses of a washer program of the home appliance. | washer, washerdryer |
| laundry_care_washer_rinse_hold | Switch | true | This status indicates whether the spin function is deactivated for a washer program of the home appliance (washing will remain in the water after the last rinse cycle). | washer, washerdryer |
| laundry_care_washer_soak | Switch | true | This status indicates whether the soaking is activated for a washer program of the home appliance. | washer, washerdryer |
| laundry_care_washer_load_recommendation | Number:Mass | true | This channel indicates the maximum laundry load recommended for a program of the home appliance. | washer, washerdryer |
| program_energy | Number:Dimensionless | true | This channel provides the estimated energy required in percentage for a program of the home appliance. | washer, washerdryer |
| program_water | Number:Dimensionless | true | This channel provides the estimated water required in percentage for a program of the home appliance. | washer, washerdryer |
| dryer_drying_target | String | false | This status defines the desired dryness of a program of the home appliance. | dryer, washerdryer |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public class HomeConnectBindingConstants {
public static final String CHANNEL_WASHER_LESS_IRONING = "laundry_care_washer_less_ironing";
public static final String CHANNEL_WASHER_PRE_WASH = "laundry_care_washer_pre_wash";
public static final String CHANNEL_WASHER_RINSE_PLUS = "laundry_care_washer_rinse_plus";
public static final String CHANNEL_WASHER_RINSE_HOLD = "laundry_care_washer_rinse_hold";
public static final String CHANNEL_WASHER_SOAK = "laundry_care_washer_soak";
public static final String CHANNEL_WASHER_LOAD_RECOMMENDATION = "laundry_care_washer_load_recommendation";
public static final String CHANNEL_PROGRAM_ENERGY = "program_energy";
public static final String CHANNEL_PROGRAM_WATER = "program_water";
public static final String CHANNEL_REFRIGERATOR_SETPOINT_TEMPERATURE = "setpoint_temperature_refrigerator";
Expand Down Expand Up @@ -188,7 +190,9 @@ public class HomeConnectBindingConstants {
public static final String OPTION_WASHER_LESS_IRONING = "LaundryCare.Washer.Option.LessIroning";
public static final String OPTION_WASHER_PRE_WASH = "LaundryCare.Washer.Option.Prewash";
public static final String OPTION_WASHER_RINSE_PLUS = "LaundryCare.Washer.Option.RinsePlus";
public static final String OPTION_WASHER_RINSE_HOLD = "LaundryCare.Washer.Option.RinseHold";
public static final String OPTION_WASHER_SOAK = "LaundryCare.Washer.Option.Soak";
public static final String OPTION_WASHER_LOAD_RECOMMENDATION = "LaundryCare.Common.Option.LoadRecommendation";
public static final String OPTION_WASHER_ENERGY_FORECAST = "BSH.Common.Option.EnergyForecast";
public static final String OPTION_WASHER_WATER_FORECAST = "BSH.Common.Option.WaterForecast";
public static final String OPTION_DRYER_DRYING_TARGET = "LaundryCare.Dryer.Option.DryingTarget";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants.*;
import static org.openhab.binding.homeconnect.internal.client.model.EventType.*;
import static org.openhab.core.library.unit.ImperialUnits.FAHRENHEIT;
import static org.openhab.core.library.unit.SIUnits.CELSIUS;
import static org.openhab.core.library.unit.SIUnits.*;
import static org.openhab.core.library.unit.Units.*;
import static org.openhab.core.thing.ThingStatus.*;

Expand All @@ -35,6 +35,7 @@

import javax.measure.UnconvertibleException;
import javax.measure.Unit;
import javax.measure.quantity.Mass;
import javax.measure.quantity.Temperature;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -675,6 +676,24 @@ protected Unit<Temperature> mapTemperature(@Nullable String unit) {
}
}

/**
* Map unit string (returned by home connect api) to Unit
*
* @param unit String eg. "gram"
* @return Unit
*/
protected Unit<Mass> mapMass(@Nullable String unit) {
if (unit == null) {
return GRAM;
} else if (unit.equalsIgnoreCase("gram")) {
return GRAM;
} else if (unit.equalsIgnoreCase("kilogram")) {
return KILOGRAM;
} else {
return GRAM;
}
}

/**
* Map hex representation of color to HSB type.
*
Expand Down Expand Up @@ -1405,7 +1424,8 @@ protected void processProgramOptions(List<Option> options) {

Map.of(CHANNEL_WASHER_IDOS1, OPTION_WASHER_IDOS_1_ACTIVE, CHANNEL_WASHER_IDOS2, OPTION_WASHER_IDOS_2_ACTIVE,
CHANNEL_WASHER_LESS_IRONING, OPTION_WASHER_LESS_IRONING, CHANNEL_WASHER_PRE_WASH,
OPTION_WASHER_PRE_WASH, CHANNEL_WASHER_SOAK, OPTION_WASHER_SOAK)
OPTION_WASHER_PRE_WASH, CHANNEL_WASHER_SOAK, OPTION_WASHER_SOAK, CHANNEL_WASHER_RINSE_HOLD,
OPTION_WASHER_RINSE_HOLD)
.forEach((channel, option) -> setOnOffChannelFromOption(channel, options, option, OnOffType.OFF));

setStringChannelFromOption(CHANNEL_HOOD_INTENSIVE_LEVEL, options, OPTION_HOOD_INTENSIVE_LEVEL,
Expand Down Expand Up @@ -1435,6 +1455,8 @@ protected void processProgramOptions(List<Option> options) {
: null);
setStringChannelFromOption(CHANNEL_WASHER_RINSE_PLUS, options, OPTION_WASHER_RINSE_PLUS,
new StringType("LaundryCare.Washer.EnumType.RinsePlus.Off"));
setQuantityChannelFromOption(CHANNEL_WASHER_LOAD_RECOMMENDATION, options, OPTION_WASHER_LOAD_RECOMMENDATION,
unit -> mapMass(unit), UnDefType.UNDEF);
setQuantityChannelFromOption(CHANNEL_PROGRAM_ENERGY, options, OPTION_WASHER_ENERGY_FORECAST, unit -> PERCENT,
UnDefType.UNDEF);
setQuantityChannelFromOption(CHANNEL_PROGRAM_WATER, options, OPTION_WASHER_WATER_FORECAST, unit -> PERCENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_RINSE_PLUS,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_RINSE_HOLD,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_SOAK,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_LOAD_RECOMMENDATION,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_PROGRAM_ENERGY,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_PROGRAM_WATER,
Expand Down Expand Up @@ -120,7 +124,9 @@ protected boolean isChannelLinkedToProgramOptionNotFullySupportedByApi() {
|| (getThingChannel(CHANNEL_WASHER_LESS_IRONING).isPresent() && isLinked(CHANNEL_WASHER_LESS_IRONING))
|| (getThingChannel(CHANNEL_WASHER_PRE_WASH).isPresent() && isLinked(CHANNEL_WASHER_PRE_WASH))
|| (getThingChannel(CHANNEL_WASHER_RINSE_PLUS).isPresent() && isLinked(CHANNEL_WASHER_RINSE_PLUS))
|| getLinkedChannel(CHANNEL_WASHER_RINSE_HOLD).isPresent()
|| (getThingChannel(CHANNEL_WASHER_SOAK).isPresent() && isLinked(CHANNEL_WASHER_SOAK))
|| getLinkedChannel(CHANNEL_WASHER_LOAD_RECOMMENDATION).isPresent()
|| (getThingChannel(CHANNEL_PROGRAM_ENERGY).isPresent() && isLinked(CHANNEL_PROGRAM_ENERGY))
|| (getThingChannel(CHANNEL_PROGRAM_WATER).isPresent() && isLinked(CHANNEL_PROGRAM_WATER));
}
Expand Down Expand Up @@ -172,7 +178,10 @@ protected void resetProgramStateChannels(boolean offline) {
getThingChannel(CHANNEL_WASHER_LESS_IRONING).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_PRE_WASH).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_RINSE_PLUS).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getLinkedChannel(CHANNEL_WASHER_RINSE_HOLD).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_SOAK).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getLinkedChannel(CHANNEL_WASHER_LOAD_RECOMMENDATION)
.ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_PROGRAM_ENERGY).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_PROGRAM_WATER).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_DRYER_DRYING_TARGET).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_RINSE_PLUS,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_RINSE_HOLD,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_SOAK,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_LOAD_RECOMMENDATION,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_PROGRAM_ENERGY,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_PROGRAM_WATER,
Expand Down Expand Up @@ -171,7 +175,9 @@ protected boolean isChannelLinkedToProgramOptionNotFullySupportedByApi() {
|| (getThingChannel(CHANNEL_WASHER_LESS_IRONING).isPresent() && isLinked(CHANNEL_WASHER_LESS_IRONING))
|| (getThingChannel(CHANNEL_WASHER_PRE_WASH).isPresent() && isLinked(CHANNEL_WASHER_PRE_WASH))
|| (getThingChannel(CHANNEL_WASHER_RINSE_PLUS).isPresent() && isLinked(CHANNEL_WASHER_RINSE_PLUS))
|| getLinkedChannel(CHANNEL_WASHER_RINSE_HOLD).isPresent()
|| (getThingChannel(CHANNEL_WASHER_SOAK).isPresent() && isLinked(CHANNEL_WASHER_SOAK))
|| getLinkedChannel(CHANNEL_WASHER_LOAD_RECOMMENDATION).isPresent()
|| (getThingChannel(CHANNEL_PROGRAM_ENERGY).isPresent() && isLinked(CHANNEL_PROGRAM_ENERGY))
|| (getThingChannel(CHANNEL_PROGRAM_WATER).isPresent() && isLinked(CHANNEL_PROGRAM_WATER));
}
Expand Down Expand Up @@ -231,7 +237,10 @@ protected void resetProgramStateChannels(boolean offline) {
getThingChannel(CHANNEL_WASHER_LESS_IRONING).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_PRE_WASH).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_RINSE_PLUS).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getLinkedChannel(CHANNEL_WASHER_RINSE_HOLD).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_WASHER_SOAK).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getLinkedChannel(CHANNEL_WASHER_LOAD_RECOMMENDATION)
.ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_PROGRAM_ENERGY).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
getThingChannel(CHANNEL_PROGRAM_WATER).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
<channel id="laundry_care_washer_less_ironing" typeId="laundry_care_washer_less_ironing"/>
<channel id="laundry_care_washer_pre_wash" typeId="laundry_care_washer_pre_wash"/>
<channel id="laundry_care_washer_rinse_plus" typeId="laundry_care_washer_rinse_plus"/>
<channel id="laundry_care_washer_rinse_hold" typeId="laundry_care_washer_rinse_hold"/>
<channel id="laundry_care_washer_soak" typeId="laundry_care_washer_soak"/>
<channel id="laundry_care_washer_load_recommendation" typeId="laundry_care_washer_load_recommendation"/>
<channel id="program_energy" typeId="program_energy"/>
<channel id="program_water" typeId="program_water"/>
<channel id="basic_actions_state" typeId="basic_actions_state"/>
Expand Down Expand Up @@ -153,7 +155,9 @@
<channel id="laundry_care_washer_less_ironing" typeId="laundry_care_washer_less_ironing"/>
<channel id="laundry_care_washer_pre_wash" typeId="laundry_care_washer_pre_wash"/>
<channel id="laundry_care_washer_rinse_plus" typeId="laundry_care_washer_rinse_plus"/>
<channel id="laundry_care_washer_rinse_hold" typeId="laundry_care_washer_rinse_hold"/>
<channel id="laundry_care_washer_soak" typeId="laundry_care_washer_soak"/>
<channel id="laundry_care_washer_load_recommendation" typeId="laundry_care_washer_load_recommendation"/>
<channel id="program_energy" typeId="program_energy"/>
<channel id="program_water" typeId="program_water"/>
<channel id="dryer_drying_target" typeId="dryer_drying_target"/>
Expand Down Expand Up @@ -547,12 +551,25 @@
</options>
</state>
</channel-type>
<channel-type id="laundry_care_washer_rinse_hold" advanced="true">
<item-type>Switch</item-type>
<label>Rinse Hold</label>
<description>This status indicates whether the spin function is deactivated for a washer program of the home appliance
(washing will remain in the water after the last rinse cycle).</description>
<state readOnly="true"/>
</channel-type>
<channel-type id="laundry_care_washer_soak" advanced="true">
<item-type>Switch</item-type>
<label>Soaking</label>
<description>This status indicates whether the soaking is activated for a washer program of the home appliance.</description>
<state readOnly="true"/>
</channel-type>
<channel-type id="laundry_care_washer_load_recommendation" advanced="true">
<item-type>Number:Mass</item-type>
<label>Load Recommendation</label>
<description>This channel indicates the maximum laundry load recommended for a program of the home appliance.</description>
<state readOnly="true" min="0" pattern="%d %unit%"/>
</channel-type>
<channel-type id="program_energy" advanced="true">
<item-type>Number:Dimensionless</item-type>
<label>Program Energy</label>
Expand Down

0 comments on commit c363678

Please sign in to comment.