Skip to content

Commit 0fe4bfb

Browse files
committed
feat(config): add show_animations option to disable canvas animations
Canvas weather animations can render light-colored elements (white clouds, sun rays) over white card text, making it unreadable. Add a show_animations config flag (default: true) that completely disables the canvas when set to false — no DOM node is created, the RAF loop never starts, and the animation manager is destroyed on live config change. Also surfaces the toggle in the visual card editor and adds translations for all 9 supported locales.
1 parent 2944c19 commit 0fe4bfb

15 files changed

Lines changed: 53 additions & 22 deletions

File tree

dynamic-weather-card.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/card.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ export class AnimatedWeatherCard extends LitElement {
9191

9292
updated(changedProperties: Map<string, unknown>): void {
9393
super.updated(changedProperties);
94+
95+
if (changedProperties.has('config')) {
96+
const prev = changedProperties.get('config') as WeatherCardConfigInternal | undefined;
97+
const wasAnimating = prev ? prev.showAnimations !== false : true;
98+
const isAnimating = this.config.showAnimations !== false;
99+
if (wasAnimating && !isAnimating) {
100+
this.animationManager.destroy();
101+
} else if (!wasAnimating && isAnimating) {
102+
this.updateComplete.then(() => {
103+
const container = this.shadowRoot?.querySelector('.canvas-container');
104+
if (container) this.animationManager.setup(container);
105+
});
106+
}
107+
}
108+
94109
if (changedProperties.has('hass') || changedProperties.has('config')) {
95110
const entity = this.config.entity;
96111
const showDaily = this.config.showDailyForecast ?? false;
@@ -177,6 +192,7 @@ export class AnimatedWeatherCard extends LitElement {
177192
overlayOpacity: config.overlay_opacity !== undefined ? config.overlay_opacity : DEFAULT_CONFIG.overlayOpacity,
178193
language: config.language || DEFAULT_CONFIG.language,
179194
windSpeedUnit: config.wind_speed_unit || DEFAULT_CONFIG.windSpeedUnit,
195+
showAnimations: config.show_animations !== false,
180196
sunriseEntity: config.sunrise_entity || null,
181197
sunsetEntity: config.sunset_entity || null,
182198
templowAttribute: config.templow_attribute || null,
@@ -259,7 +275,7 @@ export class AnimatedWeatherCard extends LitElement {
259275
@pointercancel=${(e: PointerEvent) => this.actionHandler.handlePointerUp(e)}
260276
>
261277
<div class="${cardClasses}" style="min-height: ${minHeight}; ${bgStyle}; ${overlayStyle} cursor: pointer;">
262-
<div class="canvas-container"></div>
278+
${this.config.showAnimations !== false ? html`<div class="canvas-container"></div>` : ''}
263279
<div class="content">
264280
${this.config.name && this.config.name.trim() !== '' ? html`
265281
<div class="header">

src/components/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class DynamicWeatherCardEditor extends LitElement {
3232
show_daily_forecast: DEFAULT_CONFIG.showDailyForecast,
3333
daily_forecast_days: DEFAULT_CONFIG.dailyForecastDays,
3434
show_sunrise_sunset: DEFAULT_CONFIG.showSunriseSunset,
35+
show_animations: DEFAULT_CONFIG.showAnimations,
3536
show_clock: DEFAULT_CONFIG.showClock,
3637
clock_position: DEFAULT_CONFIG.clockPosition,
3738
clock_format: DEFAULT_CONFIG.clockFormat,
@@ -96,6 +97,7 @@ export class DynamicWeatherCardEditor extends LitElement {
9697
}
9798
}
9899
},
100+
{ name: 'show_animations', selector: { boolean: {} } },
99101
{ name: 'overlay_opacity', selector: { number: { min: 0, max: 1, step: 0.05, mode: 'box' } } },
100102
{
101103
name: 'language',

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ export const DEFAULT_CONFIG: Required<Omit<WeatherCardConfig, 'entity' | 'type'>
4141
overlayOpacity: 0.1,
4242
language: 'auto',
4343
height: null,
44-
windSpeedUnit: 'ms'
44+
windSpeedUnit: 'ms',
45+
showAnimations: true
4546
};

src/internationalization/locales/de/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_hu': 'Ungarisch',
7272
'wind_speed_unit': 'Einheit der Windgeschwindigkeit',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Animationen anzeigen'
7576
},
7677
'demo': {
7778
'pageTitle': 'Dynamische Wetterkarte',

src/internationalization/locales/en/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_hu': 'Hungarian',
7272
'wind_speed_unit': 'Wind Speed Unit',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Show Animations'
7576
},
7677
'demo': {
7778
'pageTitle': 'Dynamic Weather Card',

src/internationalization/locales/es/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_hu': 'Húngaro',
7272
'wind_speed_unit': 'Unidad de velocidad del viento',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Mostrar animaciones'
7576
},
7677
'demo': {
7778
'pageTitle': 'Tarjeta Meteorológica Dinámica',

src/internationalization/locales/fr/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_hu': 'Hongrois',
7272
'wind_speed_unit': 'Unité de vitesse du vent',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Afficher les animations'
7576
},
7677
'demo': {
7778
'pageTitle': 'Carte Météo Dynamique',

src/internationalization/locales/hu/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_sk': 'Szlovák',
7272
'wind_speed_unit': 'Szélsebesség egység',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Animációk megjelenítése'
7576
},
7677
'demo': {
7778
'pageTitle': 'Dynamic Weather Card',

src/internationalization/locales/it/translation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const translation: Translation = {
7171
'language_hu': 'Ungherese',
7272
'wind_speed_unit': 'Unità velocità del vento',
7373
'wind_speed_unit_ms': 'm/s',
74-
'wind_speed_unit_kmh': 'km/h'
74+
'wind_speed_unit_kmh': 'km/h',
75+
'show_animations': 'Mostra animazioni'
7576
},
7677
'demo': {
7778
'pageTitle': 'Dynamic Weather Card',

0 commit comments

Comments
 (0)