Skip to content

Commit 2802d6f

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into ukraine-alarm-forbid-to-choose-state
2 parents 8d3e551 + a7edfb0 commit 2802d6f

File tree

245 files changed

+9696
-5291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+9696
-5291
lines changed

homeassistant/auth/mfa_modules/notify.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from __future__ import annotations
77

88
import asyncio
9-
from collections import OrderedDict
109
import logging
1110
from typing import Any, cast
1211

@@ -304,14 +303,15 @@ async def async_step_init(
304303
if not self._available_notify_services:
305304
return self.async_abort(reason="no_available_service")
306305

307-
schema: dict[str, Any] = OrderedDict()
308-
schema["notify_service"] = vol.In(self._available_notify_services)
309-
schema["target"] = vol.Optional(str)
310-
311-
return self.async_show_form(
312-
step_id="init", data_schema=vol.Schema(schema), errors=errors
306+
schema = vol.Schema(
307+
{
308+
vol.Required("notify_service"): vol.In(self._available_notify_services),
309+
vol.Optional("target"): str,
310+
}
313311
)
314312

313+
return self.async_show_form(step_id="init", data_schema=schema, errors=errors)
314+
315315
async def async_step_setup(
316316
self, user_input: dict[str, str] | None = None
317317
) -> FlowResult:

homeassistant/components/adax/config_flow.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
CONF_UNIQUE_ID,
1818
)
1919
from homeassistant.helpers.aiohttp_client import async_get_clientsession
20+
from homeassistant.helpers.selector import (
21+
TextSelector,
22+
TextSelectorConfig,
23+
TextSelectorType,
24+
)
2025

2126
from .const import (
2227
ACCOUNT_ID,
@@ -66,7 +71,15 @@ async def async_step_local(
6671
) -> ConfigFlowResult:
6772
"""Handle the local step."""
6873
data_schema = vol.Schema(
69-
{vol.Required(WIFI_SSID): str, vol.Required(WIFI_PSWD): str}
74+
{
75+
vol.Required(WIFI_SSID): str,
76+
vol.Required(WIFI_PSWD): TextSelector(
77+
TextSelectorConfig(
78+
type=TextSelectorType.PASSWORD,
79+
autocomplete="current-password",
80+
),
81+
),
82+
}
7083
)
7184
if user_input is None:
7285
return self.async_show_form(

homeassistant/components/anthropic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
RECOMMENDED_CHAT_MODEL,
2626
)
2727

28-
PLATFORMS = (Platform.CONVERSATION,)
28+
PLATFORMS = (Platform.AI_TASK, Platform.CONVERSATION)
2929
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
3030

3131
type AnthropicConfigEntry = ConfigEntry[anthropic.AsyncClient]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""AI Task integration for Anthropic."""
2+
3+
from __future__ import annotations
4+
5+
from json import JSONDecodeError
6+
import logging
7+
8+
from homeassistant.components import ai_task, conversation
9+
from homeassistant.config_entries import ConfigEntry
10+
from homeassistant.core import HomeAssistant
11+
from homeassistant.exceptions import HomeAssistantError
12+
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
13+
from homeassistant.util.json import json_loads
14+
15+
from .entity import AnthropicBaseLLMEntity
16+
17+
_LOGGER = logging.getLogger(__name__)
18+
19+
20+
async def async_setup_entry(
21+
hass: HomeAssistant,
22+
config_entry: ConfigEntry,
23+
async_add_entities: AddConfigEntryEntitiesCallback,
24+
) -> None:
25+
"""Set up AI Task entities."""
26+
for subentry in config_entry.subentries.values():
27+
if subentry.subentry_type != "ai_task_data":
28+
continue
29+
30+
async_add_entities(
31+
[AnthropicTaskEntity(config_entry, subentry)],
32+
config_subentry_id=subentry.subentry_id,
33+
)
34+
35+
36+
class AnthropicTaskEntity(
37+
ai_task.AITaskEntity,
38+
AnthropicBaseLLMEntity,
39+
):
40+
"""Anthropic AI Task entity."""
41+
42+
_attr_supported_features = (
43+
ai_task.AITaskEntityFeature.GENERATE_DATA
44+
| ai_task.AITaskEntityFeature.SUPPORT_ATTACHMENTS
45+
)
46+
47+
async def _async_generate_data(
48+
self,
49+
task: ai_task.GenDataTask,
50+
chat_log: conversation.ChatLog,
51+
) -> ai_task.GenDataTaskResult:
52+
"""Handle a generate data task."""
53+
await self._async_handle_chat_log(chat_log, task.name, task.structure)
54+
55+
if not isinstance(chat_log.content[-1], conversation.AssistantContent):
56+
raise HomeAssistantError(
57+
"Last content in chat log is not an AssistantContent"
58+
)
59+
60+
text = chat_log.content[-1].content or ""
61+
62+
if not task.structure:
63+
return ai_task.GenDataTaskResult(
64+
conversation_id=chat_log.conversation_id,
65+
data=text,
66+
)
67+
try:
68+
data = json_loads(text)
69+
except JSONDecodeError as err:
70+
_LOGGER.error(
71+
"Failed to parse JSON response: %s. Response: %s",
72+
err,
73+
text,
74+
)
75+
raise HomeAssistantError("Error with Claude structured response") from err
76+
77+
return ai_task.GenDataTaskResult(
78+
conversation_id=chat_log.conversation_id,
79+
data=data,
80+
)

0 commit comments

Comments
 (0)