mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-11 19:36:35 +00:00
Add entities, devices and areas to hass
(#13530)
This commit is contained in:
parent
e976f9c119
commit
3fc94106b8
@ -18,13 +18,16 @@ import { serviceCallWillDisconnect } from "../data/service";
|
|||||||
import { NumberFormat, TimeFormat } from "../data/translation";
|
import { NumberFormat, TimeFormat } from "../data/translation";
|
||||||
import { subscribePanels } from "../data/ws-panels";
|
import { subscribePanels } from "../data/ws-panels";
|
||||||
import { translationMetadata } from "../resources/translations-metadata";
|
import { translationMetadata } from "../resources/translations-metadata";
|
||||||
import { Constructor, ServiceCallResponse } from "../types";
|
import { Constructor, HomeAssistant, ServiceCallResponse } from "../types";
|
||||||
import { fetchWithAuth } from "../util/fetch-with-auth";
|
import { fetchWithAuth } from "../util/fetch-with-auth";
|
||||||
import { getState } from "../util/ha-pref-storage";
|
import { getState } from "../util/ha-pref-storage";
|
||||||
import hassCallApi from "../util/hass-call-api";
|
import hassCallApi from "../util/hass-call-api";
|
||||||
import { getLocalLanguage } from "../util/common-translation";
|
import { getLocalLanguage } from "../util/common-translation";
|
||||||
import { HassBaseEl } from "./hass-base-mixin";
|
import { HassBaseEl } from "./hass-base-mixin";
|
||||||
import { polyfillsLoaded } from "../common/translations/localize";
|
import { polyfillsLoaded } from "../common/translations/localize";
|
||||||
|
import { subscribeAreaRegistry } from "../data/area_registry";
|
||||||
|
import { subscribeDeviceRegistry } from "../data/device_registry";
|
||||||
|
import { subscribeEntityRegistry } from "../data/entity_registry";
|
||||||
|
|
||||||
export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
||||||
superClass: T
|
superClass: T
|
||||||
@ -38,6 +41,9 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
|||||||
connection: conn,
|
connection: conn,
|
||||||
connected: true,
|
connected: true,
|
||||||
states: null as any,
|
states: null as any,
|
||||||
|
entities: null as any,
|
||||||
|
devices: null as any,
|
||||||
|
areas: null as any,
|
||||||
config: null as any,
|
config: null as any,
|
||||||
themes: null as any,
|
themes: null as any,
|
||||||
selectedTheme: null,
|
selectedTheme: null,
|
||||||
@ -180,6 +186,27 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
subscribeEntities(conn, (states) => this._updateHass({ states }));
|
subscribeEntities(conn, (states) => this._updateHass({ states }));
|
||||||
|
subscribeEntityRegistry(conn, (entityReg) => {
|
||||||
|
const entities: HomeAssistant["entities"] = {};
|
||||||
|
for (const entity of entityReg) {
|
||||||
|
entities[entity.entity_id] = entity;
|
||||||
|
}
|
||||||
|
this._updateHass({ entities });
|
||||||
|
});
|
||||||
|
subscribeDeviceRegistry(conn, (deviceReg) => {
|
||||||
|
const devices: HomeAssistant["devices"] = {};
|
||||||
|
for (const device of deviceReg) {
|
||||||
|
devices[device.id] = device;
|
||||||
|
}
|
||||||
|
this._updateHass({ devices });
|
||||||
|
});
|
||||||
|
subscribeAreaRegistry(conn, (areaReg) => {
|
||||||
|
const areas: HomeAssistant["areas"] = {};
|
||||||
|
for (const area of areaReg) {
|
||||||
|
areas[area.area_id] = area;
|
||||||
|
}
|
||||||
|
this._updateHass({ areas });
|
||||||
|
});
|
||||||
subscribeConfig(conn, (config) => {
|
subscribeConfig(conn, (config) => {
|
||||||
if (this.hass?.config?.time_zone !== config.time_zone) {
|
if (this.hass?.config?.time_zone !== config.time_zone) {
|
||||||
if (__BUILD__ === "latest" && polyfillsLoaded) {
|
if (__BUILD__ === "latest" && polyfillsLoaded) {
|
||||||
|
@ -8,6 +8,9 @@ import {
|
|||||||
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 { AreaRegistryEntry } from "./data/area_registry";
|
||||||
|
import { DeviceRegistryEntry } from "./data/device_registry";
|
||||||
|
import { EntityRegistryEntry } from "./data/entity_registry";
|
||||||
import { CoreFrontendUserData } from "./data/frontend";
|
import { CoreFrontendUserData } from "./data/frontend";
|
||||||
import { FrontendLocaleData, getHassTranslations } from "./data/translation";
|
import { FrontendLocaleData, getHassTranslations } from "./data/translation";
|
||||||
import { Themes } from "./data/ws-themes";
|
import { Themes } from "./data/ws-themes";
|
||||||
@ -197,6 +200,9 @@ export interface HomeAssistant {
|
|||||||
connection: Connection;
|
connection: Connection;
|
||||||
connected: boolean;
|
connected: boolean;
|
||||||
states: HassEntities;
|
states: HassEntities;
|
||||||
|
entities: { [id: string]: EntityRegistryEntry };
|
||||||
|
devices: { [id: string]: DeviceRegistryEntry };
|
||||||
|
areas: { [id: string]: AreaRegistryEntry };
|
||||||
services: HassServices;
|
services: HassServices;
|
||||||
config: HassConfig;
|
config: HassConfig;
|
||||||
themes: Themes;
|
themes: Themes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user