diff --git a/src/lib/Modal/WeatherForecastConfig.svelte b/src/lib/Modal/WeatherForecastConfig.svelte index ea6c7ec8..4c7b3402 100644 --- a/src/lib/Modal/WeatherForecastConfig.svelte +++ b/src/lib/Modal/WeatherForecastConfig.svelte @@ -5,13 +5,11 @@ import Select from '$lib/Components/Select.svelte'; import ConfigButtons from '$lib/Modal/ConfigButtons.svelte'; import Modal from '$lib/Modal/Index.svelte'; - import { updateObj } from '$lib/Utils'; - import type { HassEntity } from 'home-assistant-js-websocket'; - import type { WeatherForecastItem } from '$lib/Types'; + import { getSupport, updateObj } from '$lib/Utils'; import Ripple from 'svelte-ripple'; export let isOpen: boolean; - export let sel: WeatherForecastItem; + export let sel: any; export let demo: string | undefined = undefined; if (demo) { @@ -20,30 +18,28 @@ set('entity_id', demo); } + $: entity = $states[sel?.entity_id]; + $: attributes = entity?.attributes; + $: supported_features = attributes?.supported_features; + + $: supports = getSupport(supported_features, { + FORECAST_DAILY: 1, + FORECAST_HOURLY: 2, + FORECAST_TWICE_DAILY: 4 + }); + let days_to_show = sel?.days_to_show ?? 7; let numberElement: HTMLInputElement; - let entity: HassEntity; - $: if (sel?.entity_id) { - if ($states?.[sel?.entity_id]?.last_updated !== entity?.last_updated) { - entity = $states?.[sel?.entity_id]; - } - } - const iconOptions = [ { id: 'meteocons', label: 'meteocons' }, { id: 'weathericons', label: 'weather icons' }, { id: 'materialsymbolslight', label: 'materialsymbolslight' } ]; - $: weatherStates = Object.keys( - Object.fromEntries( - Object.entries($states).filter( - ([key, value]) => key.startsWith('weather.') && value?.attributes?.forecast - ) - ) - ) + $: options = Object.keys($states) + .filter((key) => key.startsWith('weather.')) .sort() .map((key) => ({ id: key, label: key })); @@ -82,14 +78,18 @@

{$lang('entity')}

- {#if weatherStates} + {#if options} {/if} + {#if Object.keys(supports).filter((key) => supports[key]).length > 1} +

{$lang('forecast_type')}

+ +
+ {#if supports?.FORECAST_DAILY} + + {/if} + + {#if supports?.FORECAST_HOURLY} + + {/if} + + {#if supports?.FORECAST_TWICE_DAILY} + + {/if} +
+ {/if} +

{$lang('mobile')}

diff --git a/src/lib/Sidebar/WeatherForecast.svelte b/src/lib/Sidebar/WeatherForecast.svelte index dd549ea9..b0742f86 100644 --- a/src/lib/Sidebar/WeatherForecast.svelte +++ b/src/lib/Sidebar/WeatherForecast.svelte @@ -1,23 +1,53 @@