Skip to content

Commit a49dce2

Browse files
authored
Merge pull request #20 from loryanstrant/feature/v2.0.0-image-generation
🎨 Release v2.0.0: Add DALL-E image generation support
2 parents 46cc6df + 4352686 commit a49dce2

File tree

7 files changed

+496
-64
lines changed

7 files changed

+496
-64
lines changed

README.md

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ A Home Assistant custom integration that facilitates AI tasks using Azure AI ser
1414
- Easy configuration through Home Assistant UI
1515
- Secure API key management
1616
- **User-configurable AI models for chat responses** (GPT-3.5, GPT-4, GPT-4o, etc.) - type in any model name
17+
- **🎨 Image generation with DALL-E support** - generate images from text prompts using DALL-E 2/3
1718
- **Image and video analysis with attachment support** - analyze camera streams and uploaded images
19+
- **Flexible entity configuration** - create chat-only, image-only, or combined entities
1820
- **Reconfiguration support** - change models without re-entering credentials
1921
- **Multiple entry support** - use different API endpoints and keys for different purposes
2022
- Compatible with Azure OpenAI and other Azure AI services
@@ -52,9 +54,10 @@ Or replace steps 1-6 with this:
5254
2. Search for "Azure AI Tasks"
5355
3. Enter your Azure AI endpoint URL (make sure you use the Azure OpenAI URL - i.e. https://USE-YOUR-RESOURCE-URL.openai.azure.com)
5456
4. Enter your API key
55-
5. **Enter your preferred chat model** (gpt-35-turbo, gpt-4, gpt-4o, etc.)
56-
6. Give your integration a name
57-
7. Click Submit
57+
5. **Enter your preferred chat model** (gpt-35-turbo, gpt-4, gpt-4o, etc.) - leave empty for image-only entities
58+
6. **Enter your preferred image model** (dall-e-2, dall-e-3, etc.) - leave empty for chat-only entities
59+
7. Give your integration a name
60+
8. Click Submit
5861

5962
<img width="383" height="478" alt="image" src="https://github.com/user-attachments/assets/8932c51a-8fcb-42bc-9e22-ead143c610d7" />
6063

@@ -68,9 +71,14 @@ Or replace steps 1-6 with this:
6871
To change AI models without re-entering credentials:
6972
1. Go to your Azure AI Tasks integration
7073
2. Click "Configure"
71-
3. Enter a different model as needed
74+
3. Enter different chat/image models as needed (use placeholder text `[None - leave empty to disable chat]` or `[None - leave empty to disable images]` to clear fields)
7275
4. Save changes
7376

77+
**Note**: You can create specialized entities by leaving one model type empty:
78+
- **Chat-only entities**: Configure chat model, leave image model empty
79+
- **Image-only entities**: Configure image model, leave chat model empty
80+
- **Combined entities**: Configure both models
81+
7482
<img width="1072" height="700" alt="image" src="https://github.com/user-attachments/assets/598b8c28-7663-4507-be63-22413cac4b9d" />
7583

7684

@@ -92,6 +100,34 @@ data:
92100
```
93101
![HA Azure AI Task example](https://github.com/user-attachments/assets/592ec039-20ea-436f-a6f0-caf88bef9b56)
94102
103+
### 🎨 Image Generation
104+
Example service calls for generating images with DALL-E:
105+
106+
**Basic Image Generation:**
107+
```yaml
108+
action: ai_image.generate_image
109+
data:
110+
prompt: "A futuristic smart home with holographic displays and AI assistants"
111+
entity_id: ai_image.azure_ai_tasks_dall_e_3
112+
```
113+
114+
**Advanced Image Generation with Parameters:**
115+
```yaml
116+
action: ai_image.generate_image
117+
data:
118+
prompt: "A cozy living room during sunset with warm lighting"
119+
entity_id: ai_image.azure_ai_tasks_dall_e_3
120+
size: "1024x1024"
121+
quality: "hd"
122+
style: "vivid"
123+
```
124+
125+
**Supported DALL-E Parameters:**
126+
- **size**: Image dimensions (DALL-E 2: 256x256, 512x512, 1024x1024; DALL-E 3: 1024x1024, 1024x1792, 1792x1024)
127+
- **quality**: Image quality for DALL-E 3 (standard, hd)
128+
- **style**: Image style for DALL-E 3 (natural, vivid)
129+
- **n**: Number of images to generate (1-10 for DALL-E 2, 1 for DALL-E 3)
130+
95131
96132
97133
### Image/Video Analysis with Attachments
@@ -135,11 +171,16 @@ data:
135171
136172
### Available Models
137173
138-
You can enter any model name that your Azure AI deployment supports.
174+
**Chat Models**: You can enter any chat model name that your Azure AI deployment supports:
175+
- gpt-35-turbo, gpt-4, gpt-4o, gpt-4-turbo, etc.
176+
177+
**Image Models**: Supported image generation models:
178+
- **dall-e-2**: Classic DALL-E model with multiple size options
179+
- **dall-e-3**: Latest DALL-E model with enhanced quality and style controls
139180
140181
## Requirements
141182
142-
- Home Assistant 2024.1 or later
183+
- **Home Assistant 2025.10.0 or later** (required for AI Task and AI Image services)
143184
- Azure AI service with API access
144185
- Valid Azure AI endpoint and API key
145186

custom_components/azure_ai_tasks/__init__.py

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,99 @@
11
"""The Azure AI Tasks integration."""
22
from __future__ import annotations
33

4+
import logging
5+
46
from homeassistant.config_entries import ConfigEntry
5-
from homeassistant.const import Platform
7+
from homeassistant.const import Platform, __version__ as ha_version
68
from homeassistant.core import HomeAssistant
9+
from homeassistant.exceptions import ConfigEntryNotReady
710

811
from .const import DOMAIN
912

1013
PLATFORMS: list[Platform] = [Platform.AI_TASK]
1114

15+
_LOGGER = logging.getLogger(__name__)
16+
17+
# Minimum Home Assistant version required
18+
MIN_HA_VERSION = "2025.10.0"
19+
20+
21+
def _check_ha_version() -> None:
22+
"""Check if Home Assistant version meets minimum requirements."""
23+
from packaging import version
24+
25+
try:
26+
current_version = version.parse(ha_version.split(".dev")[0]) # Remove .dev suffix if present
27+
min_version = version.parse(MIN_HA_VERSION)
28+
29+
if current_version < min_version:
30+
raise ConfigEntryNotReady(
31+
f"Home Assistant {MIN_HA_VERSION} or newer is required. "
32+
f"Current version: {ha_version}"
33+
)
34+
except Exception as err:
35+
_LOGGER.warning(
36+
"Unable to verify Home Assistant version compatibility: %s. "
37+
"Integration may not work correctly if running on older versions.",
38+
err
39+
)
40+
41+
42+
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
43+
"""Migrate old entry to new version."""
44+
_LOGGER.info(f"Migrating Azure AI Tasks config entry {config_entry.entry_id} from version {config_entry.version} to version 2")
45+
46+
if config_entry.version == 1:
47+
new_data = dict(config_entry.data)
48+
new_options = dict(config_entry.options)
49+
migrated = False
50+
51+
# Remove deprecated gpt-35-turbo from both data and options
52+
if new_data.get("chat_model") == "gpt-35-turbo":
53+
new_data["chat_model"] = ""
54+
migrated = True
55+
_LOGGER.info("Removed deprecated gpt-35-turbo from data.chat_model")
56+
57+
if new_options.get("chat_model") == "gpt-35-turbo":
58+
new_options["chat_model"] = ""
59+
migrated = True
60+
_LOGGER.info("Removed deprecated gpt-35-turbo from options.chat_model")
61+
62+
# Update the config entry
63+
hass.config_entries.async_update_entry(
64+
config_entry,
65+
data=new_data,
66+
options=new_options,
67+
version=2
68+
)
69+
70+
if migrated:
71+
_LOGGER.info(f"Successfully migrated config entry {config_entry.entry_id}, cleaned deprecated model")
72+
else:
73+
_LOGGER.info(f"Migrated config entry {config_entry.entry_id} to version 2, no deprecated models found")
74+
75+
return True
76+
1277

1378
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
1479
"""Set up Azure AI Tasks from a config entry."""
80+
# Check Home Assistant version compatibility
81+
_check_ha_version()
82+
83+
# Set up the integration
1584
hass.data.setdefault(DOMAIN, {})
1685
hass.data[DOMAIN][entry.entry_id] = entry.data
17-
18-
# Set up update listener for options changes
19-
entry.async_on_unload(entry.add_update_listener(async_update_options))
20-
21-
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
22-
86+
87+
# Forward entry setup to AI task platform
88+
await hass.config_entries.async_forward_entry_setups(entry, ["ai_task"])
89+
2390
return True
2491

2592

2693
async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
2794
"""Update options."""
95+
_LOGGER.info("Azure AI Tasks options updated for entry %s", entry.entry_id)
96+
_LOGGER.info("New options: %s", entry.options)
2897
# Reload the integration when options change
2998
await hass.config_entries.async_reload(entry.entry_id)
3099

0 commit comments

Comments
 (0)