Add minimal UI for climate and water entity without target (#18666)

This commit is contained in:
Paul Bottein 2023-11-16 12:16:37 +01:00 committed by GitHub
parent f3f63d95b5
commit 98cdbb4559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 49 deletions

View File

@ -66,6 +66,9 @@ export class HaControlCircularSlider extends LitElement {
@property({ type: Boolean, reflect: true }) @property({ type: Boolean, reflect: true })
public disabled = false; public disabled = false;
@property({ type: Boolean, reflect: true })
public readonly = false;
@property({ type: Boolean }) @property({ type: Boolean })
public dual?: boolean; public dual?: boolean;
@ -258,7 +261,7 @@ export class HaControlCircularSlider extends LitElement {
e.srcEvent.preventDefault(); e.srcEvent.preventDefault();
}); });
this._mc.on("panstart", (e) => { this._mc.on("panstart", (e) => {
if (this.disabled) return; if (this.disabled || this.readonly) return;
const percentage = this._getPercentageFromEvent(e); const percentage = this._getPercentageFromEvent(e);
const raw = this._percentageToValue(percentage); const raw = this._percentageToValue(percentage);
this._activeSlider = this._findActiveSlider(raw); this._activeSlider = this._findActiveSlider(raw);
@ -266,11 +269,11 @@ export class HaControlCircularSlider extends LitElement {
this.shadowRoot?.getElementById("#slider")?.focus(); this.shadowRoot?.getElementById("#slider")?.focus();
}); });
this._mc.on("pancancel", () => { this._mc.on("pancancel", () => {
if (this.disabled) return; if (this.disabled || this.readonly) return;
this._activeSlider = undefined; this._activeSlider = undefined;
}); });
this._mc.on("panmove", (e) => { this._mc.on("panmove", (e) => {
if (this.disabled) return; if (this.disabled || this.readonly) return;
const percentage = this._getPercentageFromEvent(e); const percentage = this._getPercentageFromEvent(e);
const raw = this._percentageToValue(percentage); const raw = this._percentageToValue(percentage);
const bounded = this._boundedValue(raw); const bounded = this._boundedValue(raw);
@ -281,7 +284,7 @@ export class HaControlCircularSlider extends LitElement {
} }
}); });
this._mc.on("panend", (e) => { this._mc.on("panend", (e) => {
if (this.disabled) return; if (this.disabled || this.readonly) return;
const percentage = this._getPercentageFromEvent(e); const percentage = this._getPercentageFromEvent(e);
const raw = this._percentageToValue(percentage); const raw = this._percentageToValue(percentage);
const bounded = this._boundedValue(raw); const bounded = this._boundedValue(raw);
@ -296,7 +299,7 @@ export class HaControlCircularSlider extends LitElement {
this._activeSlider = undefined; this._activeSlider = undefined;
}); });
this._mc.on("singletap", (e) => { this._mc.on("singletap", (e) => {
if (this.disabled) return; if (this.disabled || this.readonly) return;
const percentage = this._getPercentageFromEvent(e); const percentage = this._getPercentageFromEvent(e);
const raw = this._percentageToValue(percentage); const raw = this._percentageToValue(percentage);
this._activeSlider = this._findActiveSlider(raw); this._activeSlider = this._findActiveSlider(raw);
@ -436,11 +439,15 @@ export class HaControlCircularSlider extends LitElement {
? current <= target ? current <= target
: false; : false;
const activeArc = showActive const showTarget = value != null;
? mode === "end"
? this._strokeDashArc(target, current) const activeArc = showTarget
: this._strokeDashArc(current, target) ? showActive
: this._strokeCircleDashArc(target); ? mode === "end"
? this._strokeDashArc(target, current)
: this._strokeDashArc(current, target)
: this._strokeCircleDashArc(target)
: undefined;
const coloredArc = const coloredArc =
mode === "full" mode === "full"
@ -449,7 +456,9 @@ export class HaControlCircularSlider extends LitElement {
? this._strokeDashArc(target, limit) ? this._strokeDashArc(target, limit)
: this._strokeDashArc(limit, target); : this._strokeDashArc(limit, target);
const targetCircle = this._strokeCircleDashArc(target); const targetCircle = showTarget
? this._strokeCircleDashArc(target)
: undefined;
const currentCircle = const currentCircle =
this.current != null && this.current != null &&
@ -473,26 +482,33 @@ export class HaControlCircularSlider extends LitElement {
stroke-dasharray=${coloredArc[0]} stroke-dasharray=${coloredArc[0]}
stroke-dashoffset=${coloredArc[1]} stroke-dashoffset=${coloredArc[1]}
/> />
<path ${
.id=${id} activeArc
d=${path} ? svg`
class="arc arc-active ${classMap({ [id]: true })}" <path
stroke-dasharray=${activeArc[0]} .id=${id}
stroke-dashoffset=${activeArc[1]} d=${path}
role="slider" class="arc arc-active ${classMap({ [id]: true })}"
tabindex="0" stroke-dasharray=${activeArc[0]}
aria-valuemin=${this.min} stroke-dashoffset=${activeArc[1]}
aria-valuemax=${this.max} role="slider"
aria-valuenow=${ tabindex="0"
this._localValue != null aria-valuemin=${this.min}
? this._steppedValue(this._localValue) aria-valuemax=${this.max}
: undefined aria-valuenow=${
} this._localValue != null
aria-disabled=${this.disabled} ? this._steppedValue(this._localValue)
aria-label=${ifDefined(this.lowLabel ?? this.label)} : undefined
@keydown=${this._handleKeyDown} }
@keyup=${this._handleKeyUp} aria-disabled=${this.disabled}
/> aria-readonly=${this.readonly}
aria-label=${ifDefined(this.lowLabel ?? this.label)}
@keydown=${this._handleKeyDown}
@keyup=${this._handleKeyUp}
/>
`
: nothing
}
${ ${
currentCircle currentCircle
? svg` ? svg`
@ -505,18 +521,24 @@ export class HaControlCircularSlider extends LitElement {
` `
: nothing : nothing
} }
<path ${
class="target-border ${classMap({ [id]: true })}" targetCircle
d=${path} ? svg`
stroke-dasharray=${targetCircle[0]} <path
stroke-dashoffset=${targetCircle[1]} class="target-border ${classMap({ [id]: true })}"
/> d=${path}
<path stroke-dasharray=${targetCircle[0]}
class="target" stroke-dashoffset=${targetCircle[1]}
d=${path} />
stroke-dasharray=${targetCircle[0]} <path
stroke-dashoffset=${targetCircle[1]} class="target"
/> d=${path}
stroke-dasharray=${targetCircle[0]}
stroke-dashoffset=${targetCircle[1]}
/>
`
: nothing
}
</g> </g>
`; `;
} }
@ -568,7 +590,7 @@ export class HaControlCircularSlider extends LitElement {
/> />
` `
: nothing} : nothing}
${lowValue != null ${lowValue != null || this.mode === "full"
? this.renderArc( ? this.renderArc(
this.dual ? "low" : "value", this.dual ? "low" : "value",
lowValue, lowValue,
@ -615,7 +637,8 @@ export class HaControlCircularSlider extends LitElement {
#display { #display {
pointer-events: none; pointer-events: none;
} }
:host([disabled]) #interaction { :host([disabled]) #interaction,
:host([readonly]) #interaction {
cursor: initial; cursor: initial;
} }

View File

@ -159,6 +159,21 @@ export class HaMoreInfoClimateTemperature extends LitElement {
`; `;
} }
if (
!supportsFeature(
this.stateObj,
ClimateEntityFeature.TARGET_TEMPERATURE
) &&
!supportsFeature(
this.stateObj,
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
) {
return html`
<p class="label">${this.hass.formatEntityState(this.stateObj)}</p>
`;
}
const action = this.stateObj.attributes.hvac_action; const action = this.stateObj.attributes.hvac_action;
const actionLabel = this.hass.formatEntityAttributeValue( const actionLabel = this.hass.formatEntityAttributeValue(
@ -383,15 +398,17 @@ export class HaMoreInfoClimateTemperature extends LitElement {
<div <div
class="container" class="container"
style=${styleMap({ style=${styleMap({
"--action-color": actionColor, "--state-color": stateColor,
})} })}
> >
<ha-control-circular-slider <ha-control-circular-slider
mode="full"
.current=${this.stateObj.attributes.current_temperature} .current=${this.stateObj.attributes.current_temperature}
.min=${this._min} .min=${this._min}
.max=${this._max} .max=${this._max}
.step=${this._step} .step=${this._step}
disabled readonly
.disabled=${!active}
> >
</ha-control-circular-slider> </ha-control-circular-slider>
<div class="info"> <div class="info">

View File

@ -99,6 +99,17 @@ export class HaMoreInfoWaterHeaterTemperature extends LitElement {
`; `;
} }
if (
!supportsFeature(
this.stateObj,
WaterHeaterEntityFeature.TARGET_TEMPERATURE
)
) {
return html`
<p class="label">${this.hass.formatEntityState(this.stateObj)}</p>
`;
}
return html` return html`
<p class="label"> <p class="label">
${this.hass.localize( ${this.hass.localize(
@ -202,13 +213,20 @@ export class HaMoreInfoWaterHeaterTemperature extends LitElement {
} }
return html` return html`
<div class="container"> <div
class="container"
style=${styleMap({
"--state-color": stateColor,
})}
>
<ha-control-circular-slider <ha-control-circular-slider
mode="full"
.current=${this.stateObj.attributes.current_temperature} .current=${this.stateObj.attributes.current_temperature}
.min=${this._min} .min=${this._min}
.max=${this._max} .max=${this._max}
.step=${this._step} .step=${this._step}
disabled readonly
.disabled=${!active}
> >
</ha-control-circular-slider> </ha-control-circular-slider>
<div class="info"> <div class="info">