forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[venstarthermostat] more functions issue enhancement 10823 (openhab#1…
…1305) * Adding several functions to binding to mimic local API Signed-off-by: raveydavies <matthew.davies@skynet.be> * Adding functionality according to API Signed-off-by: raveydavies <matthew.davies@skynet.be> * Updating Read me with new capability Signed-off-by: raveydavies <matthew.davies@skynet.be> * Additional commit with requested changes to pull request Signed-off-by: raveydavies <matthew.davies@skynet.be> * Updates to address all comments on previous commit. Signed-off-by: raveydavies <matthew.davies@skynet.be> * Updates as requested in review. Signed-off-by: raveydavies <matthew.davies@skynet.be> * Corrections for check style warnings Signed-off-by: raveydavies <matthew.davies@skynet.be> * Updates to address feedback from lolodomo. Signed-off-by: raveydavies <matthew.davies@skynet.be> * Changes to address feedback from lolodomo's review Signed-off-by: raveydavies <matthew.davies@skynet.be> * FanState changed to Switch, Exception handling added as per review. Signed-off-by: raveydavies <matthew.davies@skynet.be> Signed-off-by: Nick Waterton <n.waterton@outlook.com>
- Loading branch information
1 parent
1f5ac60
commit 74824c7
Showing
21 changed files
with
1,064 additions
and
78 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
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
59 changes: 59 additions & 0 deletions
59
...stat/src/main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanMode.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,59 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.venstarthermostat.internal.dto; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* The {@link VenstarFanMode} represents the value of the fan mode returned | ||
* from the REST API. | ||
* | ||
* @author Matthew Davies - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public enum VenstarFanMode { | ||
AUTO(0, "auto", "Auto"), | ||
ON(1, "on", "On"); | ||
|
||
private int mode; | ||
private String name; | ||
private String friendlyName; | ||
|
||
VenstarFanMode(int mode, String name, String friendlyName) { | ||
this.mode = mode; | ||
this.name = name; | ||
this.friendlyName = friendlyName; | ||
} | ||
|
||
public int mode() { | ||
return mode; | ||
} | ||
|
||
public String modeName() { | ||
return name; | ||
} | ||
|
||
public String friendlyName() { | ||
return friendlyName; | ||
} | ||
|
||
public static VenstarFanMode fromInt(int mode) throws IllegalArgumentException { | ||
for (VenstarFanMode fm : values()) { | ||
if (fm.mode == mode) { | ||
return fm; | ||
} | ||
} | ||
|
||
throw (new IllegalArgumentException("Invalid fan mode " + mode)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ain/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanModeSerializer.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,40 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.venstarthermostat.internal.dto; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
/** | ||
* The {@link VenstarFanModeSerializer} parses fan mode values | ||
* from the REST API JSON. | ||
* | ||
* @author Matthew Davies - Initial contribution | ||
*/ | ||
|
||
public class VenstarFanModeSerializer implements JsonDeserializer<VenstarFanMode> { | ||
@Override | ||
public VenstarFanMode deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) | ||
throws JsonParseException { | ||
int key = element.getAsInt(); | ||
try { | ||
return VenstarFanMode.fromInt(key); | ||
} catch (IllegalArgumentException e) { | ||
throw new JsonParseException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.