Gauge Card: Fix if value is greater than max (#5887)

This commit is contained in:
Zack Arnett 2020-05-15 11:21:53 -04:00 committed by GitHub
parent c88439ba2f
commit 67a3f5d87b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,6 +131,14 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
const sliderBarColor = this._computeSeverity(state); const sliderBarColor = this._computeSeverity(state);
let value: number | undefined;
if (this._config.max === null || isNaN(this._config.max!)) {
value = undefined;
} else {
value = Math.min(this._config.max!, state);
}
return html` return html`
<ha-card <ha-card
@click=${this._handleClick} @click=${this._handleClick}
@ -143,7 +151,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
readonly readonly
arcLength="180" arcLength="180"
startAngle="180" startAngle="180"
.value=${state} .value=${value}
.min=${this._config.min} .min=${this._config.min}
.max=${this._config.max} .max=${this._config.max}
></round-slider> ></round-slider>
@ -243,6 +251,10 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
} }
private _measureCard() { private _measureCard() {
if (!this.isConnected) {
return;
}
if (this.offsetWidth < 200) { if (this.offsetWidth < 200) {
this.setAttribute("narrow", ""); this.setAttribute("narrow", "");
} else { } else {
@ -257,6 +269,10 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
static get styles(): CSSResult { static get styles(): CSSResult {
return css` return css`
:host {
display: block;
}
ha-card { ha-card {
cursor: pointer; cursor: pointer;
height: 100%; height: 100%;