Skip to content

Commit

Permalink
Merge pull request #479 from matt8707/forecast
Browse files Browse the repository at this point in the history
Fix sidebar forecast type race condition, closes #478
  • Loading branch information
matt8707 authored May 24, 2024
2 parents 44fb40f + a79e826 commit 068e829
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/lib/Sidebar/WeatherForecast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { WeatherIconSet, WeatherIconConditions, WeatherIconMapping } from '$lib/Weather';
import Icon from '@iconify/svelte';
import { getSupport } from '$lib/Utils';
import { onDestroy, tick } from 'svelte';
import { onDestroy } from 'svelte';
import { writable } from 'svelte/store';
export let sel: any;
Expand Down Expand Up @@ -32,9 +32,15 @@
$: if (sel?.entity_id) $entity_id = sel?.entity_id;
$: if (!sel?.forecast_type || sel?.forecast_type) $forecast_type = sel?.forecast_type;
// forecast_type fallback
$: defaultForecastType = Object.keys(supports)
?.find((key) => supports?.[key])
?.replace('FORECAST_', '')
?.toLowerCase();
// get forecast when not dragging
// and when entity_id or forecast_type changes
$: if (($forecast_type || !$forecast_type) && $entity_id && !$dragging) {
$: if (($forecast_type || !$forecast_type) && $entity_id && !$dragging && defaultForecastType) {
getForecast();
if (debug) {
Expand All @@ -50,20 +56,12 @@
if (busy) return;
busy = true;
await tick();
// cleanup old sub
if (unsubscribe) {
if (debug) console.debug('forecast unsubscribed');
unsubscribe?.();
}
// forecast_type fallback
const defaultForecastType = Object.keys(supports)
?.find((key) => supports[key])
?.replace('FORECAST_', '')
?.toLowerCase();
try {
unsubscribe = await $connection?.subscribeMessage(
(data: any) => {
Expand Down

0 comments on commit 068e829

Please sign in to comment.