Files
advanced-camera-card/src/types.ts
T

105 lines
2.7 KiB
TypeScript

import { HomeAssistant, LovelaceCardConfig, Themes } from '@dermotduffy/custom-card-helpers';
import { StyleInfo } from 'lit/directives/style-map.js';
import { z } from 'zod';
export type ClipsOrSnapshots = 'clips' | 'snapshots';
export type ClipsOrSnapshotsOrAll = 'clips' | 'snapshots' | 'all';
export type EventsOrRecordings = 'events' | 'recordings';
export class FrigateCardError extends Error {
context?: unknown;
constructor(message: string, context?: unknown) {
super(message);
this.context = context;
}
}
export interface ExtendedHomeAssistant extends HomeAssistant {
hassUrl(path?): string;
themes: Themes & {
darkMode?: boolean;
};
}
export interface MediaLoadedCapabilities {
supports2WayAudio?: boolean;
supportsPause?: boolean;
hasAudio?: boolean;
}
export interface MediaLoadedInfo {
width: number;
height: number;
player?: FrigateCardMediaPlayer;
capabilities?: MediaLoadedCapabilities;
}
export type MessageType = 'info' | 'error' | 'connection' | 'diagnostics';
type MessagePriority = {
[type in MessageType]: number;
};
export const MESSAGE_TYPE_PRIORITIES: MessagePriority = {
info: 10,
error: 20,
connection: 30,
diagnostics: 40,
};
export interface Message {
message: string;
type: MessageType;
icon?: string;
context?: unknown;
dotdotdot?: boolean;
}
export interface StateParameters {
entity?: string;
icon?: string;
title?: string | null;
state_color?: boolean;
style?: StyleInfo;
data_domain?: string;
data_state?: string;
}
export interface FrigateCardMediaPlayer {
play(): Promise<void>;
pause(): Promise<void>;
mute(): Promise<void>;
unmute(): Promise<void>;
isMuted(): boolean;
seek(seconds: number): Promise<void>;
getScreenshotURL(): Promise<string | null>;
// If no value for controls if specified, the player should use the default.
setControls(controls?: boolean): Promise<void>;
isPaused(): boolean;
}
export interface CardHelpers {
createCardElement(config: LovelaceCardConfig): Promise<{
constructor: {
getConfigElement(): HTMLElement;
};
}>;
}
// *************************************************************************
// Home Assistant API types.
// *************************************************************************
// Server side data-type defined here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/media_source/models.py
export const resolvedMediaSchema = z.object({
url: z.string(),
mime_type: z.string(),
});
export type ResolvedMedia = z.infer<typeof resolvedMediaSchema>;
export const signedPathSchema = z.object({
path: z.string(),
});
export type SignedPath = z.infer<typeof signedPathSchema>;