Use core temperature units for climate entities. (#1580)

This commit is contained in:
Jerad Meisner 2018-08-17 00:29:42 -07:00 committed by Paulus Schoutsen
parent 5cf5e6ec6c
commit c025df2974
2 changed files with 17 additions and 15 deletions

View File

@ -35,7 +35,7 @@ class HaClimateState extends LocalizeMixin(PolymerElement) {
<span class="state-label"> <span class="state-label">
[[_localizeState(stateObj.state)]] [[_localizeState(stateObj.state)]]
</span> </span>
[[computeTarget(stateObj)]] [[computeTarget(hass, stateObj)]]
</div> </div>
<template is="dom-if" if="[[currentStatus]]"> <template is="dom-if" if="[[currentStatus]]">
@ -52,33 +52,35 @@ class HaClimateState extends LocalizeMixin(PolymerElement) {
stateObj: Object, stateObj: Object,
currentStatus: { currentStatus: {
type: String, type: String,
computed: 'computeCurrentStatus(stateObj)', computed: 'computeCurrentStatus(hass, stateObj)',
}, },
}; };
} }
computeCurrentStatus(stateObj) { computeCurrentStatus(hass, stateObj) {
if (!hass || !stateObj) return null;
if (stateObj.attributes.current_temperature != null) { if (stateObj.attributes.current_temperature != null) {
return `${stateObj.attributes.current_temperature} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.current_temperature} ${hass.config.core.unit_system.temperature}`;
} }
if (stateObj.attributes.current_humidity != null) { if (stateObj.attributes.current_humidity != null) {
return `${stateObj.attributes.current_humidity} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.current_humidity} %`;
} }
return null; return null;
} }
computeTarget(stateObj) { computeTarget(hass, stateObj) {
if (!hass || !stateObj) return null;
// We're using "!= null" on purpose so that we match both null and undefined. // We're using "!= null" on purpose so that we match both null and undefined.
if (stateObj.attributes.target_temp_low != null && if (stateObj.attributes.target_temp_low != null &&
stateObj.attributes.target_temp_high != null) { stateObj.attributes.target_temp_high != null) {
return `${stateObj.attributes.target_temp_low} - ${stateObj.attributes.target_temp_high} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.target_temp_low} - ${stateObj.attributes.target_temp_high} ${hass.config.core.unit_system.temperature}`;
} else if (stateObj.attributes.temperature != null) { } else if (stateObj.attributes.temperature != null) {
return `${stateObj.attributes.temperature} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.temperature} ${hass.config.core.unit_system.temperature}`;
} else if (stateObj.attributes.target_humidity_low != null && } else if (stateObj.attributes.target_humidity_low != null &&
stateObj.attributes.target_humidity_high != null) { stateObj.attributes.target_humidity_high != null) {
return `${stateObj.attributes.target_humidity_low} - ${stateObj.attributes.target_humidity_high} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.target_humidity_low} - ${stateObj.attributes.target_humidity_high} %`;
} else if (stateObj.attributes.humidity != null) { } else if (stateObj.attributes.humidity != null) {
return `${stateObj.attributes.humidity} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.humidity} %`;
} }
return ''; return '';

View File

@ -125,13 +125,13 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) {
<div class$="[[stateObj.attributes.operation_mode]]"> <div class$="[[stateObj.attributes.operation_mode]]">
<div hidden$="[[!supportsTemperatureControls(stateObj)]]">[[localize('ui.card.climate.target_temperature')]]</div> <div hidden$="[[!supportsTemperatureControls(stateObj)]]">[[localize('ui.card.climate.target_temperature')]]</div>
<template is="dom-if" if="[[supportsTemperature(stateObj)]]"> <template is="dom-if" if="[[supportsTemperature(stateObj)]]">
<ha-climate-control value="[[stateObj.attributes.temperature]]" units="[[stateObj.attributes.unit_of_measurement]]" step="[[computeTemperatureStepSize(stateObj)]]" min="[[stateObj.attributes.min_temp]]" max="[[stateObj.attributes.max_temp]]" on-change="targetTemperatureChanged"> <ha-climate-control value="[[stateObj.attributes.temperature]]" units="[[hass.config.core.unit_system.temperature]]" step="[[computeTemperatureStepSize(hass, stateObj)]]" min="[[stateObj.attributes.min_temp]]" max="[[stateObj.attributes.max_temp]]" on-change="targetTemperatureChanged">
</ha-climate-control> </ha-climate-control>
</template> </template>
<template is="dom-if" if="[[supportsTemperatureRange(stateObj)]]"> <template is="dom-if" if="[[supportsTemperatureRange(stateObj)]]">
<ha-climate-control value="[[stateObj.attributes.target_temp_low]]" units="[[stateObj.attributes.unit_of_measurement]]" step="[[computeTemperatureStepSize(stateObj)]]" min="[[stateObj.attributes.min_temp]]" max="[[stateObj.attributes.target_temp_high]]" class="range-control-left" on-change="targetTemperatureLowChanged"> <ha-climate-control value="[[stateObj.attributes.target_temp_low]]" units="[[hass.config.core.unit_system.temperature]]" step="[[computeTemperatureStepSize(hass, stateObj)]]" min="[[stateObj.attributes.min_temp]]" max="[[stateObj.attributes.target_temp_high]]" class="range-control-left" on-change="targetTemperatureLowChanged">
</ha-climate-control> </ha-climate-control>
<ha-climate-control value="[[stateObj.attributes.target_temp_high]]" units="[[stateObj.attributes.unit_of_measurement]]" step="[[computeTemperatureStepSize(stateObj)]]" min="[[stateObj.attributes.target_temp_low]]" max="[[stateObj.attributes.max_temp]]" class="range-control-right" on-change="targetTemperatureHighChanged"> <ha-climate-control value="[[stateObj.attributes.target_temp_high]]" units="[[hass.config.core.unit_system.temperature]]" step="[[computeTemperatureStepSize(hass, stateObj)]]" min="[[stateObj.attributes.target_temp_low]]" max="[[stateObj.attributes.max_temp]]" class="range-control-right" on-change="targetTemperatureHighChanged">
</ha-climate-control> </ha-climate-control>
</template> </template>
</div> </div>
@ -290,10 +290,10 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) {
} }
} }
computeTemperatureStepSize(stateObj) { computeTemperatureStepSize(hass, stateObj) {
if (stateObj.attributes.target_temp_step) { if (stateObj.attributes.target_temp_step) {
return stateObj.attributes.target_temp_step; return stateObj.attributes.target_temp_step;
} else if (stateObj.attributes.unit_of_measurement.indexOf('F') !== -1) { } else if (hass.config.core.unit_system.temperature.indexOf('F') !== -1) {
return 1; return 1;
} }
return 0.5; return 0.5;