mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Make entities and devices independent in the scene editor (#11046)
Co-authored-by: Zack Barett <zackbarett@hey.com> Co-authored-by: Erik <erik@montnemery.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
e1fd7244a5
commit
b71b230bfd
@ -47,12 +47,17 @@ export interface SceneConfig {
|
|||||||
name: string;
|
name: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
entities: SceneEntities;
|
entities: SceneEntities;
|
||||||
|
metadata?: SceneMetaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SceneEntities {
|
export interface SceneEntities {
|
||||||
[entityId: string]: string | { state: string; [key: string]: any };
|
[entityId: string]: string | { state: string; [key: string]: any };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SceneMetaData {
|
||||||
|
[entityId: string]: { entity_only?: boolean | undefined };
|
||||||
|
}
|
||||||
|
|
||||||
export const activateScene = (
|
export const activateScene = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entityId: string
|
entityId: string
|
||||||
|
@ -55,6 +55,7 @@ import {
|
|||||||
SceneConfig,
|
SceneConfig,
|
||||||
SceneEntities,
|
SceneEntities,
|
||||||
SceneEntity,
|
SceneEntity,
|
||||||
|
SceneMetaData,
|
||||||
SCENE_IGNORED_DOMAINS,
|
SCENE_IGNORED_DOMAINS,
|
||||||
showSceneEditor,
|
showSceneEditor,
|
||||||
} from "../../../data/scene";
|
} from "../../../data/scene";
|
||||||
@ -628,16 +629,22 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
const filteredEntityReg = this._entityRegistryEntries.filter((entityReg) =>
|
const filteredEntityReg = this._entityRegistryEntries.filter((entityReg) =>
|
||||||
this._entities.includes(entityReg.entity_id)
|
this._entities.includes(entityReg.entity_id)
|
||||||
);
|
);
|
||||||
this._devices = [];
|
const newDevices: string[] = [];
|
||||||
|
|
||||||
for (const entityReg of filteredEntityReg) {
|
for (const entityReg of filteredEntityReg) {
|
||||||
if (!entityReg.device_id) {
|
if (!entityReg.device_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!this._devices.includes(entityReg.device_id)) {
|
const entityMetaData = config.metadata?.[entityReg.entity_id];
|
||||||
this._devices = [...this._devices, entityReg.device_id];
|
if (
|
||||||
|
!newDevices.includes(entityReg.device_id) &&
|
||||||
|
!entityMetaData?.entity_only
|
||||||
|
) {
|
||||||
|
newDevices.push(entityReg.device_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._devices = newDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _entityPicked(ev: CustomEvent) {
|
private _entityPicked(ev: CustomEvent) {
|
||||||
@ -646,18 +653,8 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
if (this._entities.includes(entityId)) {
|
if (this._entities.includes(entityId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const entityRegistry = this._entityRegistryEntries.find(
|
|
||||||
(entityReg) => entityReg.entity_id === entityId
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
entityRegistry?.device_id &&
|
|
||||||
!this._devices.includes(entityRegistry.device_id)
|
|
||||||
) {
|
|
||||||
this._pickDevice(entityRegistry.device_id);
|
|
||||||
} else {
|
|
||||||
this._entities = [...this._entities, entityId];
|
this._entities = [...this._entities, entityId];
|
||||||
this._storeState(entityId);
|
this._storeState(entityId);
|
||||||
}
|
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,6 +812,28 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _calculateMetaData(): SceneMetaData {
|
||||||
|
const output: SceneMetaData = {};
|
||||||
|
|
||||||
|
for (const entityReg of this._entityRegistryEntries) {
|
||||||
|
if (!this._entities.includes(entityReg.entity_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityState = this._getCurrentState(entityReg.entity_id);
|
||||||
|
|
||||||
|
if (!entityState) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
output[entityReg.entity_id] = {
|
||||||
|
entity_only: !this._devices.includes(entityReg.device_id!),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
private _calculateStates(): SceneEntities {
|
private _calculateStates(): SceneEntities {
|
||||||
const output: SceneEntities = {};
|
const output: SceneEntities = {};
|
||||||
this._entities.forEach((entityId) => {
|
this._entities.forEach((entityId) => {
|
||||||
@ -847,7 +866,11 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
|
|
||||||
private async _saveScene(): Promise<void> {
|
private async _saveScene(): Promise<void> {
|
||||||
const id = !this.sceneId ? "" + Date.now() : this.sceneId!;
|
const id = !this.sceneId ? "" + Date.now() : this.sceneId!;
|
||||||
this._config = { ...this._config!, entities: this._calculateStates() };
|
this._config = {
|
||||||
|
...this._config!,
|
||||||
|
entities: this._calculateStates(),
|
||||||
|
metadata: this._calculateMetaData(),
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
this._saving = true;
|
this._saving = true;
|
||||||
await saveScene(this.hass, id, this._config);
|
await saveScene(this.hass, id, this._config);
|
||||||
|
@ -2257,15 +2257,14 @@
|
|||||||
"area": "Area",
|
"area": "Area",
|
||||||
"devices": {
|
"devices": {
|
||||||
"header": "Devices",
|
"header": "Devices",
|
||||||
"introduction": "Add the devices that you want to be included in your scene. Set all the devices to the state you want for this scene.",
|
"introduction": "Add the devices that you want to be included in your scene. Set all entities in each device to the state you want for this scene.",
|
||||||
"add": "Add a device",
|
"add": "Add a device",
|
||||||
"delete": "Delete device"
|
"delete": "Delete device"
|
||||||
},
|
},
|
||||||
"entities": {
|
"entities": {
|
||||||
"header": "Entities",
|
"header": "Entities",
|
||||||
"introduction": "Entities that do not belong to a device can be set here.",
|
"introduction": "Individual entities can be added here.",
|
||||||
"without_device": "Entities without device",
|
"without_device": "Entities",
|
||||||
"device_entities": "If you add an entity that belongs to a device, the device will be added.",
|
|
||||||
"add": "Add an entity",
|
"add": "Add an entity",
|
||||||
"delete": "Delete entity"
|
"delete": "Delete entity"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user