Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/common/dom/apply_themes_on_element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Theme } from "../../data/ws-themes";
import { darkStyles, derivedStyles } from "../../resources/styles";
import { HomeAssistant, Theme } from "../../types";
import type { HomeAssistant } from "../../types";
import {
hex2rgb,
lab2hex,
Expand Down
2 changes: 1 addition & 1 deletion src/common/entity/extract_views.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types";
import type { GroupEntity } from "../../data/group";
import { DEFAULT_VIEW_ENTITY_ID } from "../const";

// Return an ordered array of available views
Expand Down
2 changes: 1 addition & 1 deletion src/common/entity/get_group_entities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types";
import { GroupEntity } from "../../data/group";

export const getGroupEntities = (
entities: HassEntities,
Expand Down
2 changes: 1 addition & 1 deletion src/common/entity/get_view_entities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types";
import { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain";
import { getGroupEntities } from "./get_group_entities";

Expand Down
2 changes: 1 addition & 1 deletion src/common/entity/split_by_groups.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HassEntities } from "home-assistant-js-websocket";
import { GroupEntity } from "../../types";
import { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain";

// Split a collection into a list of groups and a 'rest' list of ungrouped
Expand Down
3 changes: 2 additions & 1 deletion src/components/ha-camera-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { fireEvent } from "../common/dom/fire_event";
import { computeStateName } from "../common/entity/compute_state_name";
import { supportsFeature } from "../common/entity/supports-feature";
import {
CameraEntity,
CAMERA_SUPPORT_STREAM,
computeMJPEGStreamUrl,
fetchStreamUrl,
} from "../data/camera";
import { CameraEntity, HomeAssistant } from "../types";
import { HomeAssistant } from "../types";
import "./ha-hls-player";

@customElement("ha-camera-stream")
Expand Down
8 changes: 7 additions & 1 deletion src/data/calendar.ts
Original file line number Diff line number Diff line change
@@ -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 { HA_COLOR_PALETTE } from "../common/const";
import { computeStateName } from "../common/entity/compute_state_name";

export interface Calendar {
entity_id: string;
name?: string;
backgroundColor?: string;
}

export const fetchCalendarEvents = async (
hass: HomeAssistant,
start: Date,
Expand Down
17 changes: 16 additions & 1 deletion src/data/camera.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise";
import { CameraEntity, HomeAssistant } from "../types";
import { HomeAssistant } from "../types";
import { getSignedPath } from "./auth";

export const CAMERA_SUPPORT_ON_OFF = 1;
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 {
preload_stream: boolean;
}
Expand Down
15 changes: 15 additions & 0 deletions src/data/group.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions src/data/input_select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { HomeAssistant } from "../types";

interface InputSelectEntityAttributes extends HassEntityAttributeBase {
options: string[];
}

export interface InputSelectEntity extends HassEntityBase {
attributes: InputSelectEntityAttributes;
}

export interface InputSelect {
id: string;
name: string;
Expand Down
21 changes: 21 additions & 0 deletions src/data/light.ts
Original file line number Diff line number Diff line change
@@ -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_COLOR_TEMP = 2;
export const SUPPORT_EFFECT = 4;
Expand Down
57 changes: 48 additions & 9 deletions src/data/media-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,48 @@ import {
mdiVideo,
mdiWeb,
} 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 { UNAVAILABLE_STATES } from "./entity";
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_SEEK = 2;
export const SUPPORT_VOLUME_SET = 4;
Expand Down Expand Up @@ -149,32 +186,34 @@ export const browseLocalMediaPlayer = (
media_content_id: mediaContentId,
});

export const getCurrentProgress = (stateObj: HassEntity): number => {
let progress = stateObj.attributes.media_position;
export const getCurrentProgress = (stateObj: MediaPlayerEntity): number => {
let progress = stateObj.attributes.media_position!;

if (stateObj.state !== "playing") {
return progress;
}
progress +=
(Date.now() -
new Date(stateObj.attributes.media_position_updated_at).getTime()) /
new Date(stateObj.attributes.media_position_updated_at!).getTime()) /
1000.0;
return progress;
};

export const computeMediaDescription = (stateObj: HassEntity): string => {
export const computeMediaDescription = (
stateObj: MediaPlayerEntity
): string => {
let secondaryTitle: string;

switch (stateObj.attributes.media_content_type) {
case "music":
case "image":
secondaryTitle = stateObj.attributes.media_artist;
secondaryTitle = stateObj.attributes.media_artist!;
break;
case "playlist":
secondaryTitle = stateObj.attributes.media_playlist;
secondaryTitle = stateObj.attributes.media_playlist!;
break;
case "tvshow":
secondaryTitle = stateObj.attributes.media_series_title;
secondaryTitle = stateObj.attributes.media_series_title!;
if (stateObj.attributes.media_season) {
secondaryTitle += " S" + stateObj.attributes.media_season;

Expand All @@ -191,7 +230,7 @@ export const computeMediaDescription = (stateObj: HassEntity): string => {
};

export const computeMediaControls = (
stateObj: HassEntity
stateObj: MediaPlayerEntity
): ControlButton[] | undefined => {
if (!stateObj) {
return undefined;
Expand Down
29 changes: 28 additions & 1 deletion src/data/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,39 @@ import {
mdiWeatherRainy,
mdiWeatherWindy,
} from "@mdi/js";
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { css, html, svg, SVGTemplateResult, TemplateResult } from "lit-element";
import { styleMap } from "lit-html/directives/style-map";
import { formatNumber } from "../common/string/format_number";
import "../components/ha-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>([
"clear-night",
Expand Down
4 changes: 4 additions & 0 deletions src/data/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface Webhook {
domain: string;
name: string;
}
export interface WebhookError {
code: number;
message: string;
}

export const fetchWebhooks = (hass: HomeAssistant): Promise<Webhook[]> =>
hass.callWS({
Expand Down
16 changes: 15 additions & 1 deletion src/data/ws-themes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
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) =>
conn.sendMessagePromise({
Expand Down
3 changes: 2 additions & 1 deletion src/dialogs/more-info/controls/more-info-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
CAMERA_SUPPORT_STREAM,
fetchCameraPrefs,
updateCameraPrefs,
CameraEntity,
} from "../../../data/camera";
import type { CameraEntity, HomeAssistant } from "../../../types";
import type { HomeAssistant } from "../../../types";

class MoreInfoCamera extends LitElement {
@property({ attribute: false }) public hass?: HomeAssistant;
Expand Down
3 changes: 2 additions & 1 deletion src/dialogs/more-info/controls/more-info-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
import { html, TemplateResult } from "lit-html";
import { dynamicElement } from "../../../common/dom/dynamic-element-directive";
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { GroupEntity } from "../../../data/group";
import "../../../state-summary/state-card-content";
import { GroupEntity, HomeAssistant } from "../../../types";
import { HomeAssistant } from "../../../types";
import {
importMoreInfoControl,
domainMoreInfoType,
Expand Down
3 changes: 2 additions & 1 deletion src/dialogs/more-info/controls/more-info-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT,
SUPPORT_WHITE_VALUE,
LightEntity,
} from "../../../data/light";
import type { HomeAssistant, LightEntity } from "../../../types";
import type { HomeAssistant } from "../../../types";

interface HueSatColor {
h: number;
Expand Down
5 changes: 3 additions & 2 deletions src/dialogs/more-info/controls/more-info-media_player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ import {
SUPPORT_VOLUME_BUTTONS,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
MediaPlayerEntity,
} from "../../../data/media-player";
import { HomeAssistant, MediaEntity } from "../../../types";
import { HomeAssistant } from "../../../types";

@customElement("more-info-media_player")
class MoreInfoMediaPlayer extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property({ attribute: false }) public stateObj?: MediaEntity;
@property({ attribute: false }) public stateObj?: MediaPlayerEntity;

@query("#ttsInput") private _ttsInput?: HTMLInputElement;

Expand Down
7 changes: 5 additions & 2 deletions src/panels/calendar/ha-panel-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import { LocalStorage } from "../../common/decorators/local-storage";
import { HASSDomEvent } from "../../common/dom/fire_event";
import "../../components/ha-card";
import "../../components/ha-menu-button";
import { fetchCalendarEvents, getCalendars } from "../../data/calendar";
import {
Calendar,
fetchCalendarEvents,
getCalendars,
} from "../../data/calendar";
import "../../layouts/ha-app-layout";
import { haStyle } from "../../resources/styles";
import type {
Calendar,
CalendarEvent,
CalendarViewChanged,
HomeAssistant,
Expand Down
Loading