Convert camera configuration to YAML dictionary.

This commit is contained in:
Dermot Duffy
2022-01-14 21:31:16 -08:00
parent af3b9092fd
commit 85ba8f3a93
5 changed files with 68 additions and 57 deletions
+23 -11
View File
@@ -287,7 +287,8 @@ export function convertActionToFrigateCardCustomAction(
*/
export function createFrigateCardCustomAction(
action: FrigateCardAction,
camera?: string): FrigateCardCustomAction | undefined {
camera?: string,
): FrigateCardCustomAction | undefined {
if (action == 'camera_select') {
if (!camera) {
return undefined;
@@ -296,12 +297,12 @@ export function createFrigateCardCustomAction(
action: 'fire-dom-event',
frigate_card_action: action,
camera: camera,
}
};
}
return {
action: 'fire-dom-event',
frigate_card_action: action,
}
};
}
/**
@@ -397,13 +398,24 @@ export function refreshDynamicStateParameters(
return params;
}
function prettifyCameraName(input: string): string {
const words = input.split(/[_\s]+/);
return words
.map((word) => {
return word[0].toUpperCase() + word.substring(1);
})
.join(' ');
}
export function refreshCameraConfigDynamicParameters(
hass: HomeAssistant,
config: CameraConfig): CameraConfig {
if (hass && config.camera_entity) {
const state = hass.states[config.camera_entity];
config.title = config.title ?? (state?.attributes?.friendly_name || config.camera_entity);
config.icon = config.icon ?? stateIcon(state);
}
config: CameraConfig,
hass?: HomeAssistant,
): CameraConfig {
const state =
hass && config.camera_entity ? hass.states[config.camera_entity] : undefined;
config.title =
config.title ??
(state?.attributes?.friendly_name || prettifyCameraName(config.camera_name || ''));
config.icon = config.icon ?? (state ? stateIcon(state) : 'mdi:video');
return config;
}
}