This repository was archived by the owner on May 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added support to Netatmo for unit system and pressure unit #2820
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
...nding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoPressureUnit.java
This file contains hidden or 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,62 @@ | ||
| /** | ||
| * Copyright (c) 2010-2015, openHAB.org and others. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| */ | ||
| package org.openhab.binding.netatmo.internal; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
|
|
||
| /** | ||
| * @author Rob Nielsen | ||
| * @since 1.8.0 | ||
| * | ||
| * This enum holds all the different pressure units for the Netatmo | ||
| * binding, along with conversion methods | ||
| */ | ||
| public enum NetatmoPressureUnit { | ||
| MBAR("mbar"), INHG("inHg"), MMHG("mmHg"); | ||
|
|
||
| public static final NetatmoPressureUnit DEFAULT_PRESSURE_UNIT = NetatmoPressureUnit.MBAR; | ||
| private static final BigDecimal MBAR_TO_INHG = new BigDecimal(0.02952998751); | ||
|
|
||
| private static final BigDecimal MBAR_TO_MMHG = new BigDecimal(0.750061683); | ||
|
|
||
| String pressureUnit; | ||
|
|
||
| private NetatmoPressureUnit(String pressureUnit) { | ||
| this.pressureUnit = pressureUnit; | ||
| } | ||
|
|
||
| public String getpressureUnit() { | ||
| return pressureUnit; | ||
| } | ||
|
|
||
| public static NetatmoPressureUnit fromString(String pressureUnit) { | ||
| if (!StringUtils.isEmpty(pressureUnit)) { | ||
| for (NetatmoPressureUnit pressureUnitType : NetatmoPressureUnit | ||
| .values()) { | ||
| if (pressureUnitType.toString().equalsIgnoreCase(pressureUnit)) { | ||
| return pressureUnitType; | ||
| } | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Invalid pressureUnit: " | ||
| + pressureUnit); | ||
| } | ||
|
|
||
| public BigDecimal convertPressure(BigDecimal value) { | ||
| if (this == DEFAULT_PRESSURE_UNIT) { | ||
| return value; | ||
| } else if (this == INHG) { | ||
| return value.multiply(MBAR_TO_INHG); | ||
| } else { // MMGH | ||
| return value.multiply(MBAR_TO_MMHG); | ||
| } | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoUnitSystem.java
This file contains hidden or 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,79 @@ | ||
| /** | ||
| * Copyright (c) 2010-2015, openHAB.org and others. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| */ | ||
| package org.openhab.binding.netatmo.internal; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
|
|
||
| /** | ||
| * @author Rob Nielsen | ||
| * @since 1.8.0 | ||
| * | ||
| * This enum holds all the different unit systems for the Netatmo binding, | ||
| * along with conversion methods | ||
| */ | ||
| public enum NetatmoUnitSystem { | ||
| M("Metric"), US("US"); | ||
|
|
||
| public static final NetatmoUnitSystem DEFAULT_UNIT_SYSTEM = NetatmoUnitSystem.M; | ||
|
|
||
| private static final double METERS_TO_FEET = 3.2808399; | ||
|
|
||
| private static final BigDecimal MM_TO_INCHES = new BigDecimal(0.0393700787); | ||
|
|
||
| private static final BigDecimal ONE_POINT_EIGHT = new BigDecimal(1.8); | ||
|
|
||
| private static final BigDecimal THIRTY_TWO = new BigDecimal(32); | ||
|
|
||
| String unitSystem; | ||
|
|
||
| private NetatmoUnitSystem(String unitSystem) { | ||
| this.unitSystem = unitSystem; | ||
| } | ||
|
|
||
| public String getunitSystem() { | ||
| return unitSystem; | ||
| } | ||
|
|
||
| public static NetatmoUnitSystem fromString(String unitSystem) { | ||
| if (!StringUtils.isEmpty(unitSystem)) { | ||
| for (NetatmoUnitSystem unitSystemType : NetatmoUnitSystem.values()) { | ||
| if (unitSystemType.toString().equalsIgnoreCase(unitSystem)) { | ||
| return unitSystemType; | ||
| } | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Invalid unitSystem: " + unitSystem); | ||
| } | ||
|
|
||
| public double convertAltitude(double value) { | ||
| if (this == DEFAULT_UNIT_SYSTEM) { | ||
| return value; | ||
| } | ||
|
|
||
| return value * METERS_TO_FEET; | ||
| } | ||
|
|
||
| public BigDecimal convertRain(BigDecimal value) { | ||
| if (this == DEFAULT_UNIT_SYSTEM) { | ||
| return value; | ||
| } | ||
|
|
||
| return value.multiply(MM_TO_INCHES); | ||
| } | ||
|
|
||
| public BigDecimal convertTemp(BigDecimal value) { | ||
| if (this == DEFAULT_UNIT_SYSTEM) { | ||
| return value; | ||
| } | ||
|
|
||
| return value.multiply(ONE_POINT_EIGHT).add(THIRTY_TWO); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should convertAltitude work in BigDecimal instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to keep the code as similar as before