Clean up some types (#7801)

Co-authored-by: Zack Barett <arnett.zackary@gmail.com>
This commit is contained in:
Paulus Schoutsen 2020-11-25 12:31:51 +01:00 committed by GitHub
parent 51332bc7e7
commit fc48c59eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 217 additions and 158 deletions

View File

@ -1,5 +1,6 @@
import { Theme } from "../../data/ws-themes";
import { darkStyles, derivedStyles } from "../../resources/styles"; import { darkStyles, derivedStyles } from "../../resources/styles";
import { HomeAssistant, Theme } from "../../types"; import type { HomeAssistant } from "../../types";
import { import {
hex2rgb, hex2rgb,
lab2hex, lab2hex,

View File

@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket"; import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types"; import type { GroupEntity } from "../../data/group";
import { DEFAULT_VIEW_ENTITY_ID } from "../const"; import { DEFAULT_VIEW_ENTITY_ID } from "../const";
// Return an ordered array of available views // Return an ordered array of available views

View File

@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket"; import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types"; import { GroupEntity } from "../../data/group";
export const getGroupEntities = ( export const getGroupEntities = (
entities: HassEntities, entities: HassEntities,

View File

@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket"; import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types"; import { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain"; import { computeDomain } from "./compute_domain";
import { getGroupEntities } from "./get_group_entities"; import { getGroupEntities } from "./get_group_entities";

View File

@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket"; import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types"; import { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain"; import { computeDomain } from "./compute_domain";
// Split a collection into a list of groups and a 'rest' list of ungrouped // Split a collection into a list of groups and a 'rest' list of ungrouped

View File

@ -13,11 +13,12 @@ import { fireEvent } from "../common/dom/fire_event";
import { computeStateName } from "../common/entity/compute_state_name"; import { computeStateName } from "../common/entity/compute_state_name";
import { supportsFeature } from "../common/entity/supports-feature"; import { supportsFeature } from "../common/entity/supports-feature";
import { import {
CameraEntity,
CAMERA_SUPPORT_STREAM, CAMERA_SUPPORT_STREAM,
computeMJPEGStreamUrl, computeMJPEGStreamUrl,
fetchStreamUrl, fetchStreamUrl,
} from "../data/camera"; } from "../data/camera";
import { CameraEntity, HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import "./ha-hls-player"; import "./ha-hls-player";
@customElement("ha-camera-stream") @customElement("ha-camera-stream")

View File

@ -1,8 +1,14 @@
import type { HomeAssistant, Calendar, CalendarEvent } from "../types"; import type { HomeAssistant, CalendarEvent } from "../types";
import { computeDomain } from "../common/entity/compute_domain"; import { computeDomain } from "../common/entity/compute_domain";
import { HA_COLOR_PALETTE } from "../common/const"; import { HA_COLOR_PALETTE } from "../common/const";
import { computeStateName } from "../common/entity/compute_state_name"; import { computeStateName } from "../common/entity/compute_state_name";
export interface Calendar {
entity_id: string;
name?: string;
backgroundColor?: string;
}
export const fetchCalendarEvents = async ( export const fetchCalendarEvents = async (
hass: HomeAssistant, hass: HomeAssistant,
start: Date, start: Date,

View File

@ -1,10 +1,25 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise"; import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise";
import { CameraEntity, HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { getSignedPath } from "./auth"; import { getSignedPath } from "./auth";
export const CAMERA_SUPPORT_ON_OFF = 1; export const CAMERA_SUPPORT_ON_OFF = 1;
export const CAMERA_SUPPORT_STREAM = 2; export const CAMERA_SUPPORT_STREAM = 2;
interface CameraEntityAttributes extends HassEntityAttributeBase {
model_name: string;
access_token: string;
brand: string;
motion_detection: boolean;
}
export interface CameraEntity extends HassEntityBase {
attributes: CameraEntityAttributes;
}
export interface CameraPreferences { export interface CameraPreferences {
preload_stream: boolean; preload_stream: boolean;
} }

15
src/data/group.ts Normal file
View File

@ -0,0 +1,15 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
interface GroupEntityAttributes extends HassEntityAttributeBase {
entity_id: string[];
order: number;
auto?: boolean;
view?: boolean;
control?: "hidden";
}
export interface GroupEntity extends HassEntityBase {
attributes: GroupEntityAttributes;
}

View File

@ -1,5 +1,17 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
interface InputSelectEntityAttributes extends HassEntityAttributeBase {
options: string[];
}
export interface InputSelectEntity extends HassEntityBase {
attributes: InputSelectEntityAttributes;
}
export interface InputSelect { export interface InputSelect {
id: string; id: string;
name: string; name: string;

View File

@ -1,3 +1,24 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
interface LightEntityAttributes extends HassEntityAttributeBase {
min_mireds: number;
max_mireds: number;
friendly_name: string;
brightness: number;
hs_color: number[];
color_temp: number;
white_value: number;
effect?: string;
effect_list: string[] | null;
}
export interface LightEntity extends HassEntityBase {
attributes: LightEntityAttributes;
}
export const SUPPORT_BRIGHTNESS = 1; export const SUPPORT_BRIGHTNESS = 1;
export const SUPPORT_COLOR_TEMP = 2; export const SUPPORT_COLOR_TEMP = 2;
export const SUPPORT_EFFECT = 4; export const SUPPORT_EFFECT = 4;

View File

@ -16,11 +16,48 @@ import {
mdiVideo, mdiVideo,
mdiWeb, mdiWeb,
} from "@mdi/js"; } from "@mdi/js";
import type { HassEntity } from "home-assistant-js-websocket"; import type {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
import { UNAVAILABLE_STATES } from "./entity"; import { UNAVAILABLE_STATES } from "./entity";
import { supportsFeature } from "../common/entity/supports-feature"; import { supportsFeature } from "../common/entity/supports-feature";
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
media_content_type?: any;
media_artist?: string;
media_playlist?: string;
media_series_title?: string;
media_season?: any;
media_episode?: any;
app_name?: string;
media_position_updated_at?: string | number | Date;
media_duration?: number;
media_position?: number;
media_title?: string;
icon?: string;
entity_picture_local?: string;
is_volume_muted?: boolean;
volume_level?: number;
source?: string;
source_list?: string[];
sound_mode?: string;
sound_mode_list?: string[];
}
export interface MediaPlayerEntity extends HassEntityBase {
attributes: MediaPlayerEntityAttributes;
state:
| "playing"
| "paused"
| "idle"
| "off"
| "on"
| "unavailable"
| "unknown";
}
export const SUPPORT_PAUSE = 1; export const SUPPORT_PAUSE = 1;
export const SUPPORT_SEEK = 2; export const SUPPORT_SEEK = 2;
export const SUPPORT_VOLUME_SET = 4; export const SUPPORT_VOLUME_SET = 4;
@ -149,32 +186,34 @@ export const browseLocalMediaPlayer = (
media_content_id: mediaContentId, media_content_id: mediaContentId,
}); });
export const getCurrentProgress = (stateObj: HassEntity): number => { export const getCurrentProgress = (stateObj: MediaPlayerEntity): number => {
let progress = stateObj.attributes.media_position; let progress = stateObj.attributes.media_position!;
if (stateObj.state !== "playing") { if (stateObj.state !== "playing") {
return progress; return progress;
} }
progress += progress +=
(Date.now() - (Date.now() -
new Date(stateObj.attributes.media_position_updated_at).getTime()) / new Date(stateObj.attributes.media_position_updated_at!).getTime()) /
1000.0; 1000.0;
return progress; return progress;
}; };
export const computeMediaDescription = (stateObj: HassEntity): string => { export const computeMediaDescription = (
stateObj: MediaPlayerEntity
): string => {
let secondaryTitle: string; let secondaryTitle: string;
switch (stateObj.attributes.media_content_type) { switch (stateObj.attributes.media_content_type) {
case "music": case "music":
case "image": case "image":
secondaryTitle = stateObj.attributes.media_artist; secondaryTitle = stateObj.attributes.media_artist!;
break; break;
case "playlist": case "playlist":
secondaryTitle = stateObj.attributes.media_playlist; secondaryTitle = stateObj.attributes.media_playlist!;
break; break;
case "tvshow": case "tvshow":
secondaryTitle = stateObj.attributes.media_series_title; secondaryTitle = stateObj.attributes.media_series_title!;
if (stateObj.attributes.media_season) { if (stateObj.attributes.media_season) {
secondaryTitle += " S" + stateObj.attributes.media_season; secondaryTitle += " S" + stateObj.attributes.media_season;
@ -191,7 +230,7 @@ export const computeMediaDescription = (stateObj: HassEntity): string => {
}; };
export const computeMediaControls = ( export const computeMediaControls = (
stateObj: HassEntity stateObj: MediaPlayerEntity
): ControlButton[] | undefined => { ): ControlButton[] | undefined => {
if (!stateObj) { if (!stateObj) {
return undefined; return undefined;

View File

@ -5,12 +5,39 @@ import {
mdiWeatherRainy, mdiWeatherRainy,
mdiWeatherWindy, mdiWeatherWindy,
} from "@mdi/js"; } from "@mdi/js";
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { css, html, svg, SVGTemplateResult, TemplateResult } from "lit-element"; import { css, html, svg, SVGTemplateResult, TemplateResult } from "lit-element";
import { styleMap } from "lit-html/directives/style-map"; import { styleMap } from "lit-html/directives/style-map";
import { formatNumber } from "../common/string/format_number"; import { formatNumber } from "../common/string/format_number";
import "../components/ha-icon"; import "../components/ha-icon";
import "../components/ha-svg-icon"; import "../components/ha-svg-icon";
import type { HomeAssistant, WeatherEntity } from "../types"; import type { HomeAssistant } from "../types";
interface ForecastAttribute {
temperature: number;
datetime: string;
templow?: number;
precipitation?: number;
precipitation_probability?: number;
humidity?: number;
condition?: string;
daytime?: boolean;
}
interface WeatherEntityAttributes extends HassEntityAttributeBase {
temperature: number;
humidity?: number;
forecast?: ForecastAttribute[];
wind_speed: string;
wind_bearing: string;
}
export interface WeatherEntity extends HassEntityBase {
attributes: WeatherEntityAttributes;
}
export const weatherSVGs = new Set<string>([ export const weatherSVGs = new Set<string>([
"clear-night", "clear-night",

View File

@ -5,6 +5,10 @@ export interface Webhook {
domain: string; domain: string;
name: string; name: string;
} }
export interface WebhookError {
code: number;
message: string;
}
export const fetchWebhooks = (hass: HomeAssistant): Promise<Webhook[]> => export const fetchWebhooks = (hass: HomeAssistant): Promise<Webhook[]> =>
hass.callWS({ hass.callWS({

View File

@ -1,5 +1,19 @@
import { Connection, createCollection } from "home-assistant-js-websocket"; import { Connection, createCollection } from "home-assistant-js-websocket";
import { Themes } from "../types";
export interface Theme {
// Incomplete
"primary-color": string;
"text-primary-color": string;
"accent-color": string;
[key: string]: string;
}
export interface Themes {
default_theme: string;
default_dark_theme: string | null;
themes: Record<string, Theme>;
darkMode: boolean;
}
const fetchThemes = (conn) => const fetchThemes = (conn) =>
conn.sendMessagePromise({ conn.sendMessagePromise({

View File

@ -17,8 +17,9 @@ import {
CAMERA_SUPPORT_STREAM, CAMERA_SUPPORT_STREAM,
fetchCameraPrefs, fetchCameraPrefs,
updateCameraPrefs, updateCameraPrefs,
CameraEntity,
} from "../../../data/camera"; } from "../../../data/camera";
import type { CameraEntity, HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
class MoreInfoCamera extends LitElement { class MoreInfoCamera extends LitElement {
@property({ attribute: false }) public hass?: HomeAssistant; @property({ attribute: false }) public hass?: HomeAssistant;

View File

@ -10,8 +10,9 @@ import {
import { html, TemplateResult } from "lit-html"; import { html, TemplateResult } from "lit-html";
import { dynamicElement } from "../../../common/dom/dynamic-element-directive"; import { dynamicElement } from "../../../common/dom/dynamic-element-directive";
import { computeStateDomain } from "../../../common/entity/compute_state_domain"; import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { GroupEntity } from "../../../data/group";
import "../../../state-summary/state-card-content"; import "../../../state-summary/state-card-content";
import { GroupEntity, HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { import {
importMoreInfoControl, importMoreInfoControl,
domainMoreInfoType, domainMoreInfoType,

View File

@ -24,8 +24,9 @@ import {
SUPPORT_COLOR_TEMP, SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT, SUPPORT_EFFECT,
SUPPORT_WHITE_VALUE, SUPPORT_WHITE_VALUE,
LightEntity,
} from "../../../data/light"; } from "../../../data/light";
import type { HomeAssistant, LightEntity } from "../../../types"; import type { HomeAssistant } from "../../../types";
interface HueSatColor { interface HueSatColor {
h: number; h: number;

View File

@ -34,14 +34,15 @@ import {
SUPPORT_VOLUME_BUTTONS, SUPPORT_VOLUME_BUTTONS,
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_SET,
MediaPlayerEntity,
} from "../../../data/media-player"; } from "../../../data/media-player";
import { HomeAssistant, MediaEntity } from "../../../types"; import { HomeAssistant } from "../../../types";
@customElement("more-info-media_player") @customElement("more-info-media_player")
class MoreInfoMediaPlayer extends LitElement { class MoreInfoMediaPlayer extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public stateObj?: MediaEntity; @property({ attribute: false }) public stateObj?: MediaPlayerEntity;
@query("#ttsInput") private _ttsInput?: HTMLInputElement; @query("#ttsInput") private _ttsInput?: HTMLInputElement;

View File

@ -18,11 +18,14 @@ import { LocalStorage } from "../../common/decorators/local-storage";
import { HASSDomEvent } from "../../common/dom/fire_event"; import { HASSDomEvent } from "../../common/dom/fire_event";
import "../../components/ha-card"; import "../../components/ha-card";
import "../../components/ha-menu-button"; import "../../components/ha-menu-button";
import { fetchCalendarEvents, getCalendars } from "../../data/calendar"; import {
Calendar,
fetchCalendarEvents,
getCalendars,
} from "../../data/calendar";
import "../../layouts/ha-app-layout"; import "../../layouts/ha-app-layout";
import { haStyle } from "../../resources/styles"; import { haStyle } from "../../resources/styles";
import type { import type {
Calendar,
CalendarEvent, CalendarEvent,
CalendarViewChanged, CalendarViewChanged,
HomeAssistant, HomeAssistant,

View File

@ -20,9 +20,9 @@ import {
createCloudhook, createCloudhook,
deleteCloudhook, deleteCloudhook,
} from "../../../../data/cloud"; } from "../../../../data/cloud";
import { fetchWebhooks, Webhook } from "../../../../data/webhook"; import { fetchWebhooks, Webhook, WebhookError } from "../../../../data/webhook";
import { haStyle } from "../../../../resources/styles"; import { haStyle } from "../../../../resources/styles";
import { HomeAssistant, WebhookError } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { showManageCloudhookDialog } from "../dialog-manage-cloudhook/show-dialog-manage-cloudhook"; import { showManageCloudhookDialog } from "../dialog-manage-cloudhook/show-dialog-manage-cloudhook";
@customElement("cloud-webhooks") @customElement("cloud-webhooks")

View File

@ -29,7 +29,8 @@ import { isValidEntityId } from "../../../common/entity/valid_entity_id";
import { iconColorCSS } from "../../../common/style/icon_color_css"; import { iconColorCSS } from "../../../common/style/icon_color_css";
import "../../../components/ha-card"; import "../../../components/ha-card";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant, LightEntity } from "../../../types"; import { LightEntity } from "../../../data/light";
import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive"; import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entites"; import { findEntities } from "../common/find-entites";
import { handleAction } from "../common/handle-action"; import { handleAction } from "../common/handle-action";

View File

@ -16,9 +16,8 @@ import { HASSDomEvent } from "../../../common/dom/fire_event";
import { debounce } from "../../../common/util/debounce"; import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-icon"; import "../../../components/ha-icon";
import { fetchCalendarEvents } from "../../../data/calendar"; import { Calendar, fetchCalendarEvents } from "../../../data/calendar";
import type { import type {
Calendar,
CalendarEvent, CalendarEvent,
CalendarViewChanged, CalendarViewChanged,
FullCalendarView, FullCalendarView,

View File

@ -22,9 +22,9 @@ import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import { UNAVAILABLE, UNAVAILABLE_STATES } from "../../../data/entity"; import { UNAVAILABLE, UNAVAILABLE_STATES } from "../../../data/entity";
import { SUPPORT_BRIGHTNESS } from "../../../data/light"; import { LightEntity, SUPPORT_BRIGHTNESS } from "../../../data/light";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant, LightEntity } from "../../../types"; import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive"; import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entites"; import { findEntities } from "../common/find-entites";
import { handleAction } from "../common/handle-action"; import { handleAction } from "../common/handle-action";

View File

@ -37,8 +37,9 @@ import {
SUPPORT_BROWSE_MEDIA, SUPPORT_BROWSE_MEDIA,
SUPPORT_SEEK, SUPPORT_SEEK,
SUPPORT_TURN_ON, SUPPORT_TURN_ON,
MediaPlayerEntity,
} from "../../../data/media-player"; } from "../../../data/media-player";
import type { HomeAssistant, MediaEntity } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { findEntities } from "../common/find-entites"; import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { installResizeObserver } from "../common/install-resize-observer"; import { installResizeObserver } from "../common/install-resize-observer";
@ -499,8 +500,8 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
} }
} }
private get _stateObj(): MediaEntity | undefined { private get _stateObj(): MediaPlayerEntity | undefined {
return this.hass!.states[this._config!.entity] as MediaEntity; return this.hass!.states[this._config!.entity] as MediaPlayerEntity;
} }
private _handleSeek(e: MouseEvent): void { private _handleSeek(e: MouseEvent): void {

View File

@ -27,8 +27,9 @@ import {
getWind, getWind,
weatherAttrIcons, weatherAttrIcons,
weatherSVGStyles, weatherSVGStyles,
WeatherEntity,
} from "../../../data/weather"; } from "../../../data/weather";
import type { HomeAssistant, WeatherEntity } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive"; import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entites"; import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";

View File

@ -26,6 +26,7 @@ import {
EntityRegistryEntry, EntityRegistryEntry,
subscribeEntityRegistry, subscribeEntityRegistry,
} from "../../../data/entity_registry"; } from "../../../data/entity_registry";
import { GroupEntity } from "../../../data/group";
import { domainToName } from "../../../data/integration"; import { domainToName } from "../../../data/integration";
import { import {
LovelaceCardConfig, LovelaceCardConfig,
@ -33,7 +34,7 @@ import {
LovelaceViewConfig, LovelaceViewConfig,
} from "../../../data/lovelace"; } from "../../../data/lovelace";
import { SENSOR_DEVICE_CLASS_BATTERY } from "../../../data/sensor"; import { SENSOR_DEVICE_CLASS_BATTERY } from "../../../data/sensor";
import { GroupEntity, HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { import {
AlarmPanelCardConfig, AlarmPanelCardConfig,
EntitiesCardConfig, EntitiesCardConfig,

View File

@ -15,9 +15,9 @@ import { styleMap } from "lit-html/directives/style-map";
import { STATES_OFF } from "../../../common/const"; import { STATES_OFF } from "../../../common/const";
import parseAspectRatio from "../../../common/util/parse-aspect-ratio"; import parseAspectRatio from "../../../common/util/parse-aspect-ratio";
import "../../../components/ha-camera-stream"; import "../../../components/ha-camera-stream";
import { fetchThumbnailUrlWithCache } from "../../../data/camera"; import { CameraEntity, fetchThumbnailUrlWithCache } from "../../../data/camera";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
import { CameraEntity, HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
const UPDATE_INTERVAL = 10000; const UPDATE_INTERVAL = 10000;
const DEFAULT_FILTER = "grayscale(100%)"; const DEFAULT_FILTER = "grayscale(100%)";

View File

@ -21,9 +21,12 @@ import "../../../components/entity/state-badge";
import "../../../components/ha-paper-dropdown-menu"; import "../../../components/ha-paper-dropdown-menu";
import { UNAVAILABLE_STATES } from "../../../data/entity"; import { UNAVAILABLE_STATES } from "../../../data/entity";
import { forwardHaptic } from "../../../data/haptics"; import { forwardHaptic } from "../../../data/haptics";
import { setInputSelectOption } from "../../../data/input_select"; import {
InputSelectEntity,
setInputSelectOption,
} from "../../../data/input_select";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant, InputSelectEntity } from "../../../types"; import { HomeAssistant } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types"; import { EntitiesCardEntityConfig } from "../cards/types";
import { actionHandler } from "../common/directives/action-handler-directive"; import { actionHandler } from "../common/directives/action-handler-directive";
import { handleAction } from "../common/handle-action"; import { handleAction } from "../common/handle-action";

View File

@ -28,6 +28,7 @@ import {
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_SET,
computeMediaDescription, computeMediaDescription,
MediaPlayerEntity,
} from "../../../data/media-player"; } from "../../../data/media-player";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
@ -80,7 +81,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
return html``; return html``;
} }
const stateObj = this.hass.states[this._config.entity]; const stateObj = this.hass.states[this._config.entity] as MediaPlayerEntity;
const state = stateObj.state; const state = stateObj.state;
if (!stateObj) { if (!stateObj) {

View File

@ -20,8 +20,9 @@ import {
getWeatherUnit, getWeatherUnit,
getWeatherStateIcon, getWeatherStateIcon,
weatherSVGStyles, weatherSVGStyles,
WeatherEntity,
} from "../../../data/weather"; } from "../../../data/weather";
import type { HomeAssistant, WeatherEntity } from "../../../types"; import type { HomeAssistant } from "../../../types";
import type { EntitiesCardEntityConfig } from "../cards/types"; import type { EntitiesCardEntityConfig } from "../cards/types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row"; import "../components/hui-generic-entity-row";

View File

@ -15,9 +15,9 @@ import {
import { stopPropagation } from "../common/dom/stop_propagation"; import { stopPropagation } from "../common/dom/stop_propagation";
import { computeStateName } from "../common/entity/compute_state_name"; import { computeStateName } from "../common/entity/compute_state_name";
import "../components/entity/state-badge"; import "../components/entity/state-badge";
import { setInputSelectOption } from "../data/input_select"; import { InputSelectEntity, setInputSelectOption } from "../data/input_select";
import type { PolymerIronSelectEvent } from "../polymer-types"; import type { PolymerIronSelectEvent } from "../polymer-types";
import type { HomeAssistant, InputSelectEntity } from "../types"; import type { HomeAssistant } from "../types";
@customElement("state-card-input_select") @customElement("state-card-input_select")
class StateCardInputSelect extends LitElement { class StateCardInputSelect extends LitElement {

View File

@ -3,14 +3,13 @@ import {
Connection, Connection,
HassConfig, HassConfig,
HassEntities, HassEntities,
HassEntityAttributeBase,
HassEntityBase,
HassServices, HassServices,
MessageBase, MessageBase,
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { LocalizeFunc } from "./common/translations/localize"; import { LocalizeFunc } from "./common/translations/localize";
import { CoreFrontendUserData } from "./data/frontend"; import { CoreFrontendUserData } from "./data/frontend";
import { getHassTranslations } from "./data/translation"; import { getHassTranslations } from "./data/translation";
import { Themes } from "./data/ws-themes";
import { ExternalMessaging } from "./external_app/external_messaging"; import { ExternalMessaging } from "./external_app/external_messaging";
declare global { declare global {
@ -62,11 +61,6 @@ export interface ClassElement {
descriptor?: PropertyDescriptor; descriptor?: PropertyDescriptor;
} }
export interface WebhookError {
code: number;
message: string;
}
export interface Credential { export interface Credential {
auth_provider_type: string; auth_provider_type: string;
auth_provider_id: string; auth_provider_id: string;
@ -87,21 +81,6 @@ export interface CurrentUser {
mfa_modules: MFAModule[]; mfa_modules: MFAModule[];
} }
export interface Theme {
// Incomplete
"primary-color": string;
"text-primary-color": string;
"accent-color": string;
[key: string]: string;
}
export interface Themes {
default_theme: string;
default_dark_theme: string | null;
themes: Record<string, Theme>;
darkMode: boolean;
}
export interface ThemeSettings { export interface ThemeSettings {
theme: string; theme: string;
dark?: boolean; dark?: boolean;
@ -121,12 +100,6 @@ export interface Panels {
[name: string]: PanelInfo; [name: string]: PanelInfo;
} }
export interface Calendar {
entity_id: string;
name?: string;
backgroundColor?: string;
}
export interface CalendarEvent { export interface CalendarEvent {
summary: string; summary: string;
title: string; title: string;
@ -261,69 +234,6 @@ export interface HomeAssistant {
): Promise<LocalizeFunc>; ): Promise<LocalizeFunc>;
} }
export type LightEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
min_mireds: number;
max_mireds: number;
friendly_name: string;
brightness: number;
hs_color: number[];
color_temp: number;
white_value: number;
effect?: string;
effect_list: string[] | null;
};
};
export type GroupEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
entity_id: string[];
order: number;
auto?: boolean;
view?: boolean;
control?: "hidden";
};
};
export type CameraEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
model_name: string;
access_token: string;
brand: string;
motion_detection: boolean;
};
};
export type MediaEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
media_duration: number;
media_position: number;
media_title: string;
icon?: string;
entity_picture_local?: string;
is_volume_muted?: boolean;
volume_level?: number;
source?: string;
source_list?: string[];
sound_mode?: string;
sound_mode_list?: string[];
};
state:
| "playing"
| "paused"
| "idle"
| "off"
| "on"
| "unavailable"
| "unknown";
};
export type InputSelectEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
options: string[];
};
};
export interface Route { export interface Route {
prefix: string; prefix: string;
path: string; path: string;
@ -340,24 +250,3 @@ export interface LocalizeMixin {
hass?: HomeAssistant; hass?: HomeAssistant;
localize: LocalizeFunc; localize: LocalizeFunc;
} }
interface ForecastAttribute {
temperature: number;
datetime: string;
templow?: number;
precipitation?: number;
precipitation_probability?: number;
humidity?: number;
condition?: string;
daytime?: boolean;
}
export type WeatherEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
temperature: number;
humidity?: number;
forecast?: ForecastAttribute[];
wind_speed: string;
wind_bearing: string;
};
};