Skip to content

Commit fbd40dc

Browse files
committed
Merge pull request openhab#3950 from watou/nest-fix-3944
[nest] Allow setting setpoints with decimals
2 parents df45d18 + c8958fd commit fbd40dc

File tree

1 file changed

+20
-8
lines changed
  • bundles/binding/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/messages

1 file changed

+20
-8
lines changed

bundles/binding/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/messages/DataModel.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.io.UnsupportedEncodingException;
1212
import java.lang.reflect.InvocationTargetException;
13+
import java.math.BigDecimal;
1314
import java.net.URLDecoder;
1415
import java.util.Date;
1516
import java.util.HashMap;
@@ -120,6 +121,17 @@ public Object convert(Class type, Object value) {
120121
}
121122
}
122123
}, ColorState.class);
124+
convertUtils.register(new Converter() {
125+
@SuppressWarnings("rawtypes")
126+
@Override
127+
public Object convert(Class type, Object value) {
128+
if (value instanceof DecimalType) {
129+
return ((DecimalType) value).toBigDecimal();
130+
} else {
131+
return null;
132+
}
133+
}
134+
}, BigDecimal.class);
123135
convertUtils.register(new Converter() {
124136
@SuppressWarnings("rawtypes")
125137
@Override
@@ -195,7 +207,7 @@ public void setThermostats_by_id(Map<String, Thermostat> thermostats_by_id) {
195207

196208
/**
197209
* Return the thermostats map, mapped by name.
198-
*
210+
*
199211
* @return the thermostats_by_name;
200212
*/
201213
@JsonIgnore
@@ -324,7 +336,7 @@ public String getKey(String expression) {
324336

325337
/**
326338
* Return a JavaBean property by name.
327-
*
339+
*
328340
* @param name
329341
* the named property to return
330342
* @return the named property's value
@@ -345,7 +357,7 @@ public Object getProperty(String name)
345357
/**
346358
* Set the specified property value, performing type conversions as required to conform to the type of the
347359
* destination property.
348-
*
360+
*
349361
* @param name
350362
* property name (can be nested/indexed/mapped/combo)
351363
* @param value
@@ -379,7 +391,7 @@ public void setDevices(Devices devices) {
379391

380392
/**
381393
* Convenience method so property specs don't have to include "devices." in each one.
382-
*
394+
*
383395
* @return name-based map of thermostats
384396
*/
385397
@JsonIgnore
@@ -389,7 +401,7 @@ public Map<String, Thermostat> getThermostats() {
389401

390402
/**
391403
* Convenience method so property specs don't have to include "devices." in each one.
392-
*
404+
*
393405
* @return name-based map of smoke_co_alarms
394406
*/
395407
@JsonIgnore
@@ -399,7 +411,7 @@ public Map<String, SmokeCOAlarm> getSmoke_co_alarms() {
399411

400412
/**
401413
* Convenience method so property specs don't have to include "devices." in each one.
402-
*
414+
*
403415
* @return name-based map of cameras
404416
*/
405417
@JsonIgnore
@@ -475,7 +487,7 @@ public void sync() {
475487
* This method returns a new data model containing only the affected Structure, Thermostat, SmokeCOAlarm or Camera,
476488
* and only the property of the bean that was changed. This new DataModel object can be sent to the Nest API in
477489
* order to perform an update via HTTP PUT.
478-
*
490+
*
479491
* @param property
480492
* the property to change
481493
* @param newState
@@ -562,7 +574,7 @@ public DataModel updateDataModel(String property, Object newState)
562574

563575
/**
564576
* Lastly, set the property into the update data model
565-
*
577+
*
566578
* TODO: cannot update a binding string of the form "=[structures(Name).thermostats(Name).X]" or
567579
* "=[structures(Name).smoke_co_alarms(Name).X]" because the name-based map of structures is not present in the
568580
* updateDataModel

0 commit comments

Comments
 (0)