feat: Add card picker suggestion for camera entities (#2517)
Selecting a camera entity in the dashboard card picker now suggests Advanced Camera Card under the Community section, so you can add it in one click without searching for it manually. Requires Home Assistant 2026.6 or later. Docs: https://developers.home-assistant.io/docs/frontend/custom-ui/custom-card#suggesting-your-card-for-an-entity --------- Co-authored-by: dermotduffy <dermot.duffy@gmail.com>
This commit is contained in:
committed by
dermotduffy
co-authored by
dermotduffy
parent
7dc29865b8
commit
b33c034810
@@ -7,7 +7,12 @@ import {
|
||||
type AdvancedCameraCardConfig,
|
||||
type CardWideConfig,
|
||||
} from '../../config/schema/types.js';
|
||||
import type { RawAdvancedCameraCardConfig } from '../../config/types.js';
|
||||
import type {
|
||||
PartialAdvancedCameraCardConfig,
|
||||
RawAdvancedCameraCardConfig,
|
||||
} from '../../config/types.js';
|
||||
import { computeDomain } from '../../ha/compute-domain.js';
|
||||
import type { HomeAssistant } from '../../ha/types.js';
|
||||
import { localize } from '../../localize/localize.js';
|
||||
import { getParseError } from '../../utils/zod/parse-errors.js';
|
||||
import { InitializationAspect } from '../initialization-manager.js';
|
||||
@@ -36,6 +41,32 @@ export class ConfigManager {
|
||||
this._api = api;
|
||||
}
|
||||
|
||||
public static getEntitySuggestion(
|
||||
hass: HomeAssistant,
|
||||
entityId: string,
|
||||
): { config: PartialAdvancedCameraCardConfig } | null {
|
||||
if (computeDomain(entityId) !== 'camera' || !hass.states[entityId]) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
config: {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: entityId }],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public static getStubConfig(entities: string[]): PartialAdvancedCameraCardConfig {
|
||||
const cameraEntity = entities.find((entity) => computeDomain(entity) === 'camera');
|
||||
return {
|
||||
cameras: [
|
||||
{
|
||||
camera_entity: cameraEntity ?? 'camera.demo',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
public hasConfig(): boolean {
|
||||
return !!this.getConfig();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { ReactiveController } from 'lit';
|
||||
|
||||
import { CameraManager } from '../camera-manager/manager';
|
||||
import { ConditionStateManager } from '../condition-trigger/conditions/state-manager';
|
||||
import type { AdvancedCameraCardConfig } from '../config/schema/types';
|
||||
import { DeviceRegistryManager } from '../ha/registry/device';
|
||||
import { DeviceCache } from '../ha/registry/device/types';
|
||||
import { EntityRegistryManagerLive } from '../ha/registry/entity';
|
||||
@@ -303,20 +302,6 @@ export class CardController
|
||||
return this._statusBarItemManager;
|
||||
}
|
||||
|
||||
public static getStubConfig(entities: string[]): AdvancedCameraCardConfig {
|
||||
const cameraEntity = entities.find((element) => element.startsWith('camera.'));
|
||||
return {
|
||||
cameras: [
|
||||
{
|
||||
camera_entity: cameraEntity ?? 'camera.demo',
|
||||
},
|
||||
],
|
||||
// Need to use 'as unknown' to convince Typescript that this really isn't a
|
||||
// mistake, despite the miniscule size of the configuration vs the full type
|
||||
// description.
|
||||
} as unknown as AdvancedCameraCardConfig;
|
||||
}
|
||||
|
||||
public getStyleManager(): StyleManager {
|
||||
return this._styleManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user