From e141b4dbee1df6a4e12d9776c69390beed569a9c Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Tue, 11 Mar 2025 06:57:43 -0700 Subject: [PATCH] Disable energy distribution animation if `prefers-reduced-motion` is set (#24581) * Disable energy distribution animation if prefers-reduced-motion is set * Move check to willUpdate. Remove circle circumference animation --- .../energy/hui-energy-distribution-card.ts | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts index 4f455b2d0b..54fb147c27 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts @@ -47,6 +47,8 @@ class HuiEnergyDistrubutionCard @state() private _data?: EnergyData; + @state() private _animate = true; + protected hassSubscribeRequiredHostProps = ["_config"]; public setConfig(config: EnergyDistributionCardConfig): void { @@ -78,6 +80,12 @@ class HuiEnergyDistrubutionCard ); } + protected willUpdate() { + if (!this.hasUpdated && matchMedia("(prefers-reduced-motion)").matches) { + this._animate = false; + } + } + protected render() { if (!this._config) { return nothing; @@ -349,7 +357,7 @@ class HuiEnergyDistrubutionCard - ${gasUsage + ${gasUsage && this._animate ? svg` - ${waterUsage + ${waterUsage && this._animate ? svg` - ${waterUsage + ${waterUsage && this._animate ? svg` - ${returnedToGrid && hasSolarProduction + ${returnedToGrid && hasSolarProduction && this._animate ? svg` ` : ""} - ${solarConsumption + ${solarConsumption && this._animate ? svg` ` : ""} - ${gridConsumption + ${gridConsumption && this._animate ? svg` ` : ""} - ${solarToBattery + ${solarToBattery && this._animate ? svg` ` : ""} - ${batteryConsumption + ${batteryConsumption && this._animate ? svg` ` : ""} - ${batteryFromGrid + ${batteryFromGrid && this._animate ? svg` ` : ""} - ${batteryToGrid + ${batteryToGrid && this._animate ? svg`