mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Extract climate state into a separate component (#820)
This commit is contained in:
parent
50ed7678a1
commit
3c95559f33
56
src/components/ha-climate-state.html
Normal file
56
src/components/ha-climate-state.html
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
|
||||||
|
|
||||||
|
<dom-module id="ha-climate-state">
|
||||||
|
<template>
|
||||||
|
<style>
|
||||||
|
.target {
|
||||||
|
color: var(--primary-text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.current {
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-label {
|
||||||
|
font-weight: bold;
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class='target'>
|
||||||
|
<span class="state-label">
|
||||||
|
[[stateObj.state]]
|
||||||
|
</span>
|
||||||
|
[[computeTargetTemperature(stateObj)]]
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='current'>
|
||||||
|
Currently: [[stateObj.attributes.current_temperature]]
|
||||||
|
[[stateObj.attributes.unit_of_measurement]]
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</dom-module>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
class HaClimateState extends Polymer.Element {
|
||||||
|
static get is() { return 'ha-climate-state'; }
|
||||||
|
|
||||||
|
static get properties() {
|
||||||
|
return {
|
||||||
|
stateObj: Object,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
computeTargetTemperature(stateObj) {
|
||||||
|
if (stateObj.attributes.target_temp_low &&
|
||||||
|
stateObj.attributes.target_temp_high) {
|
||||||
|
return `${stateObj.attributes.target_temp_low} - ${stateObj.attributes.target_temp_high} ${stateObj.attributes.unit_of_measurement}`;
|
||||||
|
} else if (stateObj.attributes.temperature) {
|
||||||
|
return `${stateObj.attributes.temperature} ${stateObj.attributes.unit_of_measurement}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customElements.define(HaClimateState.is, HaClimateState);
|
||||||
|
</script>
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
|
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
|
||||||
|
|
||||||
|
<link rel="import" href="../components/ha-climate-state.html">
|
||||||
<link rel="import" href="../components/entity/state-info.html">
|
<link rel="import" href="../components/entity/state-info.html">
|
||||||
|
|
||||||
<dom-module id="state-card-climate">
|
<dom-module id="state-card-climate">
|
||||||
@ -13,44 +14,15 @@
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.state {
|
ha-climate-state {
|
||||||
margin-left: 16px;
|
margin-left: 16px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.target {
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.current {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.state-label {
|
|
||||||
font-weight: bold;
|
|
||||||
text-transform: capitalize;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class='horizontal justified layout'>
|
<div class='horizontal justified layout'>
|
||||||
<state-info state-obj="[[stateObj]]" in-dialog='[[inDialog]]'></state-info>
|
<state-info state-obj="[[stateObj]]" in-dialog='[[inDialog]]'></state-info>
|
||||||
<div class='state'>
|
<ha-climate-state state-obj="[[stateObj]]"></ha-climate-state>
|
||||||
<div class='target'>
|
|
||||||
<span class="state-label">
|
|
||||||
[[stateObj.state]]
|
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
[[computeTargetTemperature(stateObj)]]
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class='current'>
|
|
||||||
<span>Currently: </span>
|
|
||||||
<span>[[stateObj.attributes.current_temperature]]</span>
|
|
||||||
<span> </span>
|
|
||||||
<span>[[stateObj.attributes.unit_of_measurement]]</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
@ -68,22 +40,6 @@ class StateCardClimate extends Polymer.Element {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
computeTargetTemperature(stateObj) {
|
|
||||||
var stateTemp = '';
|
|
||||||
|
|
||||||
if (stateObj.attributes.target_temp_low &&
|
|
||||||
stateObj.attributes.target_temp_high) {
|
|
||||||
stateTemp = stateObj.attributes.target_temp_low + ' - ' +
|
|
||||||
stateObj.attributes.target_temp_high + ' ' +
|
|
||||||
stateObj.attributes.unit_of_measurement;
|
|
||||||
} else if (stateObj.attributes.temperature) {
|
|
||||||
stateTemp = stateObj.attributes.temperature + ' ' +
|
|
||||||
stateObj.attributes.unit_of_measurement;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateTemp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
customElements.define(StateCardClimate.is, StateCardClimate);
|
customElements.define(StateCardClimate.is, StateCardClimate);
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user