Skip to content

Commit 942d264

Browse files
authored
Allow storing AI Task generate image preferred entity (#26959)
1 parent b10fdf8 commit 942d264

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/data/ai_task.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import type { HomeAssistant } from "../types";
22
import type { Selector } from "./selector";
33

4+
export const enum AITaskEntityFeature {
5+
GENERATE_DATA = 1,
6+
SUPPORT_ATTACHMENTS = 2,
7+
GENERATE_IMAGE = 4,
8+
}
49
export interface AITaskPreferences {
510
gen_data_entity_id: string | null;
11+
gen_image_entity_id: string | null;
612
}
713

814
export interface GenDataTask {

src/panels/config/core/ai-task-pref.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mdiHelpCircle, mdiStarFourPoints } from "@mdi/js";
22
import { css, html, LitElement } from "lit";
3+
import type { HassEntity } from "home-assistant-js-websocket";
34
import { customElement, property, state } from "lit/decorators";
45
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
56
import type { HaProgressButton } from "../../../components/buttons/ha-progress-button";
@@ -8,13 +9,23 @@ import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker
89
import "../../../components/ha-card";
910
import "../../../components/ha-settings-row";
1011
import {
12+
AITaskEntityFeature,
1113
fetchAITaskPreferences,
1214
saveAITaskPreferences,
1315
type AITaskPreferences,
1416
} from "../../../data/ai_task";
1517
import type { HomeAssistant } from "../../../types";
1618
import { brandsUrl } from "../../../util/brands-url";
1719
import { documentationUrl } from "../../../util/documentation-url";
20+
import { computeDomain } from "../../../common/entity/compute_domain";
21+
import { supportsFeature } from "../../../common/entity/supports-feature";
22+
23+
const filterGenData = (entity: HassEntity) =>
24+
computeDomain(entity.entity_id) === "ai_task" &&
25+
supportsFeature(entity, AITaskEntityFeature.GENERATE_DATA);
26+
const filterGenImage = (entity: HassEntity) =>
27+
computeDomain(entity.entity_id) === "ai_task" &&
28+
supportsFeature(entity, AITaskEntityFeature.GENERATE_IMAGE);
1829

1930
@customElement("ai-task-pref")
2031
export class AITaskPref extends LitElement {
@@ -26,6 +37,8 @@ export class AITaskPref extends LitElement {
2637

2738
private _gen_data_entity_id?: string | null;
2839

40+
private _gen_image_entity_id?: string | null;
41+
2942
protected firstUpdated(changedProps) {
3043
super.firstUpdated(changedProps);
3144
if (!this.hass || !isComponentLoaded(this.hass, "ai_task")) {
@@ -90,7 +103,27 @@ export class AITaskPref extends LitElement {
90103
isComponentLoaded(this.hass, "ai_task")}
91104
.value=${this._gen_data_entity_id ||
92105
this._prefs?.gen_data_entity_id}
93-
.includeDomains=${["ai_task"]}
106+
.entityFilter=${filterGenData}
107+
@value-changed=${this._handlePrefChange}
108+
></ha-entity-picker>
109+
</ha-settings-row>
110+
<ha-settings-row .narrow=${this.narrow}>
111+
<span slot="heading">
112+
${this.hass!.localize("ui.panel.config.ai_task.gen_image_header")}
113+
</span>
114+
<span slot="description">
115+
${this.hass!.localize(
116+
"ui.panel.config.ai_task.gen_image_description"
117+
)}
118+
</span>
119+
<ha-entity-picker
120+
data-name="gen_image_entity_id"
121+
.hass=${this.hass}
122+
.disabled=${this._prefs === undefined &&
123+
isComponentLoaded(this.hass, "ai_task")}
124+
.value=${this._gen_image_entity_id ||
125+
this._prefs?.gen_image_entity_id}
126+
.entityFilter=${filterGenImage}
94127
@value-changed=${this._handlePrefChange}
95128
></ha-entity-picker>
96129
</ha-settings-row>
@@ -121,6 +154,7 @@ export class AITaskPref extends LitElement {
121154
const oldPrefs = this._prefs;
122155
const update: Partial<AITaskPreferences> = {
123156
gen_data_entity_id: this._gen_data_entity_id,
157+
gen_image_entity_id: this._gen_image_entity_id,
124158
};
125159
this._prefs = { ...this._prefs!, ...update };
126160
try {

src/translations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,9 @@
23122312
"header": "AI suggestions",
23132313
"description": "Home Assistant can use generative AI to help you with tasks. Look for the button with the {button} icon throughout Home Assistant to get suggestions. Select an AI task entity to use this feature.",
23142314
"gen_data_header": "Data generation tasks",
2315-
"gen_data_description": "Suggest automation names."
2315+
"gen_data_description": "Suggest automation names.",
2316+
"gen_image_header": "Image generation tasks",
2317+
"gen_image_description": "Generate images."
23162318
},
23172319
"category": {
23182320
"caption": "Categories",

0 commit comments

Comments
 (0)