Whilst the Frigate support in this card is the best among camera engines, the name incorrectly suggests that Frigate is a requirement. Instead, to broaden the appeal, change to more camera agnostic name. This does not suggest any change in priority, role or support for Frigate. This change is likely to be bug prone, due to the size of the rename -- the code contains 1500+ references to "Frigate" most of which make sense to rename, some which do not, all of which needed human assessment. - Closes #1298 BREAKING CHANGE: References to `frigate-card` in all kinds of configuration need to be updated to `advanced-camera-card`. An automated config upgrade should take care of the majority of usecases (click `Edit -> Upgrade -> Save`), though may not be perfect.
126 lines
3.5 KiB
TypeScript
126 lines
3.5 KiB
TypeScript
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
|
|
import pkg from '../../package.json';
|
|
import { RawAdvancedCameraCardConfig } from '../config/types';
|
|
import { getLanguage } from '../localize/localize';
|
|
import { getIntegrationManifest } from './ha/integration';
|
|
import { IntegrationManifest } from './ha/integration/types';
|
|
import { DeviceRegistryManager } from './ha/registry/device';
|
|
import { HASS_WEB_PROXY_DOMAIN } from './ha/web-proxy';
|
|
|
|
type FrigateDevices = Record<string, string>;
|
|
|
|
interface GitDiagnostics {
|
|
build_version?: string;
|
|
build_date?: string;
|
|
commit_date?: string;
|
|
}
|
|
|
|
interface IntegrationDiagnostics {
|
|
detected: boolean;
|
|
version?: string;
|
|
}
|
|
|
|
export const getReleaseVersion = (): string => {
|
|
const releaseVersion: string = '__ADVANCED_CAMERA_CARD_RELEASE_VERSION__';
|
|
|
|
/* istanbul ignore if: depends on rollup substitution -- @preserve */
|
|
if (releaseVersion === 'pkg') {
|
|
return pkg.version;
|
|
}
|
|
|
|
/* istanbul ignore if: depends on rollup substitution -- @preserve */
|
|
if (releaseVersion === 'dev') {
|
|
return `dev+${pkg['gitAbbrevHash']}`;
|
|
}
|
|
|
|
return releaseVersion;
|
|
};
|
|
|
|
interface Diagnostics {
|
|
card_version: string;
|
|
browser: string;
|
|
date: Date;
|
|
lang: string;
|
|
timezone: string;
|
|
git: GitDiagnostics;
|
|
|
|
ha_version?: string;
|
|
config?: RawAdvancedCameraCardConfig;
|
|
|
|
custom_integrations: {
|
|
frigate: IntegrationDiagnostics & {
|
|
devices?: FrigateDevices;
|
|
};
|
|
hass_web_proxy: IntegrationDiagnostics;
|
|
};
|
|
}
|
|
|
|
const getIntegrationDiagnostics = async (
|
|
integration: string,
|
|
hass?: HomeAssistant,
|
|
): Promise<IntegrationDiagnostics> => {
|
|
let manifest: IntegrationManifest | null = null;
|
|
|
|
if (hass) {
|
|
try {
|
|
manifest = await getIntegrationManifest(hass, integration);
|
|
} catch (e) {
|
|
// Silently ignore integrations not being found.
|
|
}
|
|
}
|
|
|
|
return {
|
|
detected: !!manifest,
|
|
...(manifest?.version && { version: manifest.version }),
|
|
};
|
|
};
|
|
|
|
export const getDiagnostics = async (
|
|
hass?: HomeAssistant,
|
|
deviceRegistryManager?: DeviceRegistryManager,
|
|
rawConfig?: RawAdvancedCameraCardConfig,
|
|
): Promise<Diagnostics> => {
|
|
// Get the Frigate devices in order to extract the Frigate integration and
|
|
// server version numbers.
|
|
const frigateDevices =
|
|
hass && deviceRegistryManager
|
|
? await deviceRegistryManager.getMatchingDevices(
|
|
hass,
|
|
(device) => device.manufacturer === 'Frigate',
|
|
)
|
|
: [];
|
|
|
|
const frigateVersionMap: Map<string, string> = new Map();
|
|
frigateDevices?.forEach((device) => {
|
|
device.config_entries.forEach((configEntry) => {
|
|
if (device.model) {
|
|
frigateVersionMap.set(configEntry, device.model);
|
|
}
|
|
});
|
|
});
|
|
|
|
return {
|
|
card_version: getReleaseVersion(),
|
|
browser: navigator.userAgent,
|
|
date: new Date(),
|
|
lang: getLanguage(),
|
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
git: {
|
|
...(pkg['gitAbbrevHash'] && { hash: pkg['gitAbbrevHash'] }),
|
|
...(pkg['buildDate'] && { build_date: pkg['buildDate'] }),
|
|
...(pkg['gitDate'] && { commit_date: pkg['gitDate'] }),
|
|
},
|
|
...(hass && { ha_version: hass.config.version }),
|
|
custom_integrations: {
|
|
frigate: {
|
|
...(await getIntegrationDiagnostics('frigate', hass)),
|
|
...(frigateVersionMap.size && {
|
|
devices: Object.fromEntries(frigateVersionMap),
|
|
}),
|
|
},
|
|
hass_web_proxy: await getIntegrationDiagnostics(HASS_WEB_PROXY_DOMAIN, hass),
|
|
},
|
|
...(rawConfig && { config: rawConfig }),
|
|
};
|
|
};
|