mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 05:06:38 +00:00
✨ thermostat
card: follow same step logic as more-info (#2369)
* Follow same step logic as more-info * Address review comments * Address review comments * Address review comments and cleanup
This commit is contained in:
parent
88473581c2
commit
5a90edc893
@ -7,6 +7,9 @@ import {
|
|||||||
import { classMap } from "lit-html/directives/classMap";
|
import { classMap } from "lit-html/directives/classMap";
|
||||||
import { TemplateResult } from "lit-html";
|
import { TemplateResult } from "lit-html";
|
||||||
|
|
||||||
|
import "../../../components/ha-card";
|
||||||
|
import "../../../components/ha-icon";
|
||||||
|
|
||||||
import applyThemesOnElement from "../../../common/dom/apply_themes_on_element";
|
import applyThemesOnElement from "../../../common/dom/apply_themes_on_element";
|
||||||
import computeStateName from "../../../common/entity/compute_state_name";
|
import computeStateName from "../../../common/entity/compute_state_name";
|
||||||
|
|
||||||
@ -15,15 +18,12 @@ import { HomeAssistant, ClimateEntity } from "../../../types";
|
|||||||
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
||||||
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
||||||
import { LovelaceCardConfig } from "../../../data/lovelace";
|
import { LovelaceCardConfig } from "../../../data/lovelace";
|
||||||
|
|
||||||
import "../../../components/ha-card";
|
|
||||||
import "../../../components/ha-icon";
|
|
||||||
import { loadRoundslider } from "../../../resources/jquery.roundslider.ondemand";
|
import { loadRoundslider } from "../../../resources/jquery.roundslider.ondemand";
|
||||||
import { afterNextRender } from "../../../common/util/render-status";
|
import { afterNextRender } from "../../../common/util/render-status";
|
||||||
|
import { UNIT_F } from "../../../common/const";
|
||||||
|
|
||||||
const thermostatConfig = {
|
const thermostatConfig = {
|
||||||
radius: 150,
|
radius: 150,
|
||||||
step: 1,
|
|
||||||
circleShape: "pie",
|
circleShape: "pie",
|
||||||
startAngle: 315,
|
startAngle: 315,
|
||||||
width: 5,
|
width: 5,
|
||||||
@ -55,6 +55,14 @@ function formatTemp(temps: string[]): string {
|
|||||||
return temps.filter(Boolean).join("-");
|
return temps.filter(Boolean).join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function computeTemperatureStepSize(hass: HomeAssistant, config: Config) {
|
||||||
|
const stateObj = hass.states[config.entity];
|
||||||
|
if (stateObj.attributes.target_temp_step) {
|
||||||
|
return stateObj.attributes.target_temp_step;
|
||||||
|
}
|
||||||
|
return hass.config.unit_system.temperature === UNIT_F ? 1 : 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
||||||
implements LovelaceCard {
|
implements LovelaceCard {
|
||||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||||
@ -197,6 +205,7 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
: "min-range";
|
: "min-range";
|
||||||
|
|
||||||
const [sliderValue, uiValue] = this._genSliderValue(stateObj);
|
const [sliderValue, uiValue] = this._genSliderValue(stateObj);
|
||||||
|
const step = computeTemperatureStepSize(this.hass!, this._config!);
|
||||||
this._broadCard = this.clientWidth > 390;
|
this._broadCard = this.clientWidth > 390;
|
||||||
this._jQuery("#thermostat", this.shadowRoot).roundSlider({
|
this._jQuery("#thermostat", this.shadowRoot).roundSlider({
|
||||||
...thermostatConfig,
|
...thermostatConfig,
|
||||||
@ -207,6 +216,7 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
change: (value) => this._setTemperature(value),
|
change: (value) => this._setTemperature(value),
|
||||||
drag: (value) => this._dragEvent(value),
|
drag: (value) => this._dragEvent(value),
|
||||||
value: sliderValue,
|
value: sliderValue,
|
||||||
|
step,
|
||||||
});
|
});
|
||||||
this._updateSetTemp(uiValue);
|
this._updateSetTemp(uiValue);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user