From 8e49241e7c5ad5ae73362ea9d329bb45e6b05e53 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 16 Oct 2018 09:04:10 +0200 Subject: [PATCH] Add types to hass object (#1776) --- src/types.ts | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index 98d2d1940a..055dab505d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,13 +1,87 @@ -import { HassEntities, HassConfig } from "home-assistant-js-websocket"; +import { + HassEntities, + HassConfig, + Auth, + Connection, + MessageBase, +} from "home-assistant-js-websocket"; + +export interface Credential { + auth_provider_type: string; + auth_provider_id: string; +} + +export interface MFAModule { + id: string; + name: string; + enabled: boolean; +} + +export interface User { + id: string; + is_owner: boolean; + name: string; + credentials: Credential[]; + mfa_modules: MFAModule[]; +} + +export interface Theme { + // Incomplete + "primary-color": string; + "text-primary-color": string; + "accent-color": string; +} + +export interface Panel { + component_name: string; + config?: { [key: string]: any }; + icon: string; + title: string; + url_path: string; +} + +export interface Translation { + nativeName: string; + fingerprints: { [fragment: string]: string }; +} export interface HomeAssistant { + auth: Auth; + conn: Connection; + connected: boolean; states: HassEntities; config: HassConfig; + themes: { + default_theme: string; + themes: { [key: string]: Theme }; + }; + panels: { [key: string]: Panel }; + panelUrl: string; language: string; resources: { [key: string]: any }; + translationMetadata: { + fragments: string[]; + translations: { + [lang: string]: Translation; + }; + }; + dockedSidebar: boolean; + moreInfoEntityId: string; + user: User; callService: ( domain: string, service: string, - serviceData: { [key: string]: any } + serviceData?: { [key: string]: any } ) => Promise; + callApi: ( + method: "GET" | "POST" | "PUT" | "DELETE", + path: string, + parameters?: { [key: string]: any } + ) => Promise; + fetchWithAuth: ( + path: string, + init?: { [key: string]: any } + ) => Promise; + sendWS: (msg: MessageBase) => Promise; + callWS: (msg: MessageBase) => Promise; }