Skip to content

Commit

Permalink
Merge pull request openhab#2659 from watou/nest-hvac-state
Browse files Browse the repository at this point in the history
[Nest] Enh: Add hvac_state property to thermostat object - Closes openhab#2658
  • Loading branch information
teichsta committed May 27, 2015
2 parents b220385 + 10858e8 commit da4ed5f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.codehaus.jackson.annotate.JsonProperty;
import org.openhab.binding.nest.internal.messages.Structure.AwayState;
import org.openhab.binding.nest.internal.messages.Thermostat.HvacMode;
import org.openhab.binding.nest.internal.messages.Thermostat.HvacState;
import org.openhab.binding.nest.internal.messages.SmokeCOAlarm.AlarmState;
import org.openhab.binding.nest.internal.messages.SmokeCOAlarm.BatteryHealth;
import org.openhab.binding.nest.internal.messages.SmokeCOAlarm.ColorState;
Expand Down Expand Up @@ -73,6 +74,17 @@ public Object convert(Class type, Object value) {
}
}
}, HvacMode.class);
convertUtils.register(new Converter() {
@SuppressWarnings("rawtypes")
@Override
public Object convert(Class type, Object value) {
if (value instanceof StringType) {
return HvacState.forValue(value.toString());
} else {
return null;
}
}
}, HvacState.class);
convertUtils.register(new Converter() {
@SuppressWarnings("rawtypes")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ public String toString() {
}
}

/**
* Possible values for hvac_state
*/
public static enum HvacState {
HEATING("heating"), COOLING("cooling"), OFF("off");

private final String state;

private HvacState(String state) {
this.state = state;
}

@JsonValue
public String value() {
return state;
}

@JsonCreator
public static HvacState forValue(String v) {
for (HvacState hs : HvacState.values()) {
if (hs.state.equals(v)) {
return hs;
}
}
throw new IllegalArgumentException("Invalid hvac_state: " + v);
}

@Override
public String toString() {
return this.state;
}
}

private Boolean can_cool;
private Boolean can_heat;
private Boolean is_using_emergency_heat;
Expand All @@ -82,6 +115,7 @@ public String toString() {
private BigDecimal ambient_temperature_f;
private BigDecimal ambient_temperature_c;
private BigDecimal humidity;
private HvacState hvac_state;

public Thermostat(@JsonProperty("device_id") String device_id) {
super(device_id);
Expand Down Expand Up @@ -331,6 +365,14 @@ public BigDecimal getHumidity() {
return this.humidity;
}

/**
* @return Indicates HVAC system heating/cooling/off state.
*/
@JsonProperty("hvac_state")
public HvacState getHvac_state() {
return this.hvac_state;
}

@Override
public String toString() {
final ToStringBuilder builder = createToStringBuilder();
Expand All @@ -357,6 +399,7 @@ public String toString() {
builder.append("ambient_temperature_f", this.ambient_temperature_f);
builder.append("ambient_temperature_c", this.ambient_temperature_c);
builder.append("humidity", this.humidity);
builder.append("hvac_state", this.hvac_state);

return builder.toString();
}
Expand Down

0 comments on commit da4ed5f

Please sign in to comment.