Fix "Area not found" error

If the card type for the undisclosed area is set to `HaAreaCard`, a card
is shown with the message "Area not found".
This is because it's not a real area and the type must be enforced to
`default`.

Closes #206
This commit is contained in:
DigiLive
2025-05-14 08:36:37 +02:00
parent 2fc0df9db0
commit 4cbb1274f6
3 changed files with 4 additions and 7 deletions

View File

@@ -179,8 +179,9 @@ class Registry {
return { ...area, ...Registry.strategyOptions.areas['_'], ...Registry.strategyOptions.areas?.[area.area_id] }; return { ...area, ...Registry.strategyOptions.areas['_'], ...Registry.strategyOptions.areas?.[area.area_id] };
}); });
// Ensure the custom configuration of the undisclosed area doesn't overwrite the area_id. // Ensure the custom configuration of the undisclosed area doesn't overwrite the required property values.
Registry.strategyOptions.areas.undisclosed.area_id = 'undisclosed'; Registry.strategyOptions.areas.undisclosed.area_id = 'undisclosed';
Registry.strategyOptions.areas.undisclosed.type = 'default';
// Remove hidden areas if configured as so and sort them by name. // Remove hidden areas if configured as so and sort them by name.

View File

@@ -40,8 +40,8 @@ class AreaCard extends AbstractCard {
configuration.tap_action.navigation_path = area.area_id; configuration.tap_action.navigation_path = area.area_id;
} }
// Don't override the default card type if default is set in the strategy options. // Don't override the card type if set differently in the strategy options.
if (customConfig && customConfig.type === 'default') { if (customConfig) {
customConfig = { ...customConfig, type: configuration.type }; customConfig = { ...customConfig, type: configuration.type };
} }

View File

@@ -229,16 +229,12 @@ class HomeView extends AbstractView {
const cardConfigurations: (TemplateCardConfig | AreaCardConfig)[] = []; const cardConfigurations: (TemplateCardConfig | AreaCardConfig)[] = [];
let onlyDefaultCards = true;
for (const area of Registry.areas) { for (const area of Registry.areas) {
const moduleName = const moduleName =
Registry.strategyOptions.areas[area.area_id]?.type ?? Registry.strategyOptions.areas['_']?.type ?? 'default'; Registry.strategyOptions.areas[area.area_id]?.type ?? Registry.strategyOptions.areas['_']?.type ?? 'default';
let AreaCard; let AreaCard;
onlyDefaultCards = onlyDefaultCards && moduleName === 'default';
try { try {
AreaCard = (await import(`../cards/${moduleName}`)).default; AreaCard = (await import(`../cards/${moduleName}`)).default;
} catch (e) { } catch (e) {