mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-07 16:37:48 +00:00
Use hass areas and devices
This commit is contained in:
parent
f41330a29b
commit
da51ddac8a
@ -1,4 +1,4 @@
|
|||||||
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -9,15 +9,9 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import {
|
import { AreaRegistryEntry } from "../data/area_registry";
|
||||||
AreaRegistryEntry,
|
|
||||||
subscribeAreaRegistry,
|
|
||||||
} from "../data/area_registry";
|
|
||||||
import { ConfigEntry, getConfigEntries } from "../data/config_entries";
|
import { ConfigEntry, getConfigEntries } from "../data/config_entries";
|
||||||
import {
|
import { DeviceRegistryEntry } from "../data/device_registry";
|
||||||
DeviceRegistryEntry,
|
|
||||||
subscribeDeviceRegistry,
|
|
||||||
} from "../data/device_registry";
|
|
||||||
import { SceneEntity } from "../data/scene";
|
import { SceneEntity } from "../data/scene";
|
||||||
import { findRelated, ItemType, RelatedResult } from "../data/search";
|
import { findRelated, ItemType, RelatedResult } from "../data/search";
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
@ -34,23 +28,8 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _entries?: ConfigEntry[];
|
@state() private _entries?: ConfigEntry[];
|
||||||
|
|
||||||
@state() private _devices?: DeviceRegistryEntry[];
|
|
||||||
|
|
||||||
@state() private _areas?: AreaRegistryEntry[];
|
|
||||||
|
|
||||||
@state() private _related?: RelatedResult;
|
@state() private _related?: RelatedResult;
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
|
||||||
return [
|
|
||||||
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
|
|
||||||
this._devices = devices;
|
|
||||||
}),
|
|
||||||
subscribeAreaRegistry(this.hass.connection!, (areas) => {
|
|
||||||
this._areas = areas;
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
getConfigEntries(this.hass).then((configEntries) => {
|
getConfigEntries(this.hass).then((configEntries) => {
|
||||||
@ -104,11 +83,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
})
|
})
|
||||||
: ""}
|
: ""}
|
||||||
${this._related.device && this._devices
|
${this._related.device
|
||||||
? this._related.device.map((relatedDeviceId) => {
|
? this._related.device.map((relatedDeviceId) => {
|
||||||
const device: DeviceRegistryEntry | undefined = this._devices!.find(
|
const device: DeviceRegistryEntry | undefined =
|
||||||
(dev) => dev.id === relatedDeviceId
|
this.hass.devices[relatedDeviceId];
|
||||||
);
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -125,11 +103,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
})
|
})
|
||||||
: ""}
|
: ""}
|
||||||
${this._related.area && this._areas
|
${this._related.area
|
||||||
? this._related.area.map((relatedAreaId) => {
|
? this._related.area.map((relatedAreaId) => {
|
||||||
const area: AreaRegistryEntry | undefined = this._areas!.find(
|
const area: AreaRegistryEntry | undefined =
|
||||||
(ar) => ar.area_id === relatedAreaId
|
this.hass.areas[relatedAreaId];
|
||||||
);
|
|
||||||
if (!area) {
|
if (!area) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user