mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add HassGetCurrentDate and HassGetCurrentTime intents (#121707)
This commit is contained in:
parent
0462582da3
commit
417abda649
@ -6,5 +6,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/conversation",
|
"documentation": "https://www.home-assistant.io/integrations/conversation",
|
||||||
"integration_type": "system",
|
"integration_type": "system",
|
||||||
"quality_scale": "internal",
|
"quality_scale": "internal",
|
||||||
"requirements": ["hassil==1.7.3", "home-assistant-intents==2024.7.3"]
|
"requirements": ["hassil==1.7.4", "home-assistant-intents==2024.7.10"]
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Protocol
|
from typing import Any, Protocol
|
||||||
|
|
||||||
@ -120,6 +121,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
intent.async_register(hass, PauseTimerIntentHandler())
|
intent.async_register(hass, PauseTimerIntentHandler())
|
||||||
intent.async_register(hass, UnpauseTimerIntentHandler())
|
intent.async_register(hass, UnpauseTimerIntentHandler())
|
||||||
intent.async_register(hass, TimerStatusIntentHandler())
|
intent.async_register(hass, TimerStatusIntentHandler())
|
||||||
|
intent.async_register(hass, GetCurrentDateIntentHandler())
|
||||||
|
intent.async_register(hass, GetCurrentTimeIntentHandler())
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -370,6 +373,30 @@ class SetPositionIntentHandler(intent.DynamicServiceIntentHandler):
|
|||||||
raise intent.IntentHandleError(f"Domain not supported: {state.domain}")
|
raise intent.IntentHandleError(f"Domain not supported: {state.domain}")
|
||||||
|
|
||||||
|
|
||||||
|
class GetCurrentDateIntentHandler(intent.IntentHandler):
|
||||||
|
"""Gets the current date."""
|
||||||
|
|
||||||
|
intent_type = intent.INTENT_GET_CURRENT_DATE
|
||||||
|
description = "Gets the current date"
|
||||||
|
|
||||||
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
||||||
|
response = intent_obj.create_response()
|
||||||
|
response.async_set_speech_slots({"date": datetime.now().date()})
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class GetCurrentTimeIntentHandler(intent.IntentHandler):
|
||||||
|
"""Gets the current time."""
|
||||||
|
|
||||||
|
intent_type = intent.INTENT_GET_CURRENT_TIME
|
||||||
|
description = "Gets the current time"
|
||||||
|
|
||||||
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
||||||
|
response = intent_obj.create_response()
|
||||||
|
response.async_set_speech_slots({"time": datetime.now().time()})
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
async def _async_process_intent(
|
async def _async_process_intent(
|
||||||
hass: HomeAssistant, domain: str, platform: IntentPlatformProtocol
|
hass: HomeAssistant, domain: str, platform: IntentPlatformProtocol
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -54,6 +54,8 @@ INTENT_DECREASE_TIMER = "HassDecreaseTimer"
|
|||||||
INTENT_PAUSE_TIMER = "HassPauseTimer"
|
INTENT_PAUSE_TIMER = "HassPauseTimer"
|
||||||
INTENT_UNPAUSE_TIMER = "HassUnpauseTimer"
|
INTENT_UNPAUSE_TIMER = "HassUnpauseTimer"
|
||||||
INTENT_TIMER_STATUS = "HassTimerStatus"
|
INTENT_TIMER_STATUS = "HassTimerStatus"
|
||||||
|
INTENT_GET_CURRENT_DATE = "HassGetCurrentDate"
|
||||||
|
INTENT_GET_CURRENT_TIME = "HassGetCurrentTime"
|
||||||
|
|
||||||
SLOT_SCHEMA = vol.Schema({}, extra=vol.ALLOW_EXTRA)
|
SLOT_SCHEMA = vol.Schema({}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
@ -277,6 +277,8 @@ class AssistAPI(API):
|
|||||||
intent.INTENT_GET_STATE,
|
intent.INTENT_GET_STATE,
|
||||||
intent.INTENT_NEVERMIND,
|
intent.INTENT_NEVERMIND,
|
||||||
intent.INTENT_TOGGLE,
|
intent.INTENT_TOGGLE,
|
||||||
|
intent.INTENT_GET_CURRENT_DATE,
|
||||||
|
intent.INTENT_GET_CURRENT_TIME,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant) -> None:
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
|
@ -30,10 +30,10 @@ ha-av==10.1.1
|
|||||||
ha-ffmpeg==3.2.0
|
ha-ffmpeg==3.2.0
|
||||||
habluetooth==3.1.3
|
habluetooth==3.1.3
|
||||||
hass-nabucasa==0.81.1
|
hass-nabucasa==0.81.1
|
||||||
hassil==1.7.3
|
hassil==1.7.4
|
||||||
home-assistant-bluetooth==1.12.2
|
home-assistant-bluetooth==1.12.2
|
||||||
home-assistant-frontend==20240710.0
|
home-assistant-frontend==20240710.0
|
||||||
home-assistant-intents==2024.7.3
|
home-assistant-intents==2024.7.10
|
||||||
httpx==0.27.0
|
httpx==0.27.0
|
||||||
ifaddr==0.2.0
|
ifaddr==0.2.0
|
||||||
Jinja2==3.1.4
|
Jinja2==3.1.4
|
||||||
|
@ -1062,7 +1062,7 @@ hass-nabucasa==0.81.1
|
|||||||
hass-splunk==0.1.1
|
hass-splunk==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
hassil==1.7.3
|
hassil==1.7.4
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.10.9
|
hdate==0.10.9
|
||||||
@ -1099,7 +1099,7 @@ holidays==0.52
|
|||||||
home-assistant-frontend==20240710.0
|
home-assistant-frontend==20240710.0
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
home-assistant-intents==2024.7.3
|
home-assistant-intents==2024.7.10
|
||||||
|
|
||||||
# homeassistant.components.home_connect
|
# homeassistant.components.home_connect
|
||||||
homeconnect==0.7.2
|
homeconnect==0.7.2
|
||||||
|
@ -876,7 +876,7 @@ habluetooth==3.1.3
|
|||||||
hass-nabucasa==0.81.1
|
hass-nabucasa==0.81.1
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
hassil==1.7.3
|
hassil==1.7.4
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.10.9
|
hdate==0.10.9
|
||||||
@ -904,7 +904,7 @@ holidays==0.52
|
|||||||
home-assistant-frontend==20240710.0
|
home-assistant-frontend==20240710.0
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
home-assistant-intents==2024.7.3
|
home-assistant-intents==2024.7.10
|
||||||
|
|
||||||
# homeassistant.components.home_connect
|
# homeassistant.components.home_connect
|
||||||
homeconnect==0.7.2
|
homeconnect==0.7.2
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
"""Test intents for the default agent."""
|
"""Test intents for the default agent."""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
@ -413,3 +415,28 @@ async def test_todo_add_item_fr(
|
|||||||
assert mock_handle.call_args.args
|
assert mock_handle.call_args.args
|
||||||
intent_obj = mock_handle.call_args.args[0]
|
intent_obj = mock_handle.call_args.args[0]
|
||||||
assert intent_obj.slots.get("item", {}).get("value", "").strip() == "farine"
|
assert intent_obj.slots.get("item", {}).get("value", "").strip() == "farine"
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time(datetime(year=2013, month=9, day=17, hour=1, minute=2))
|
||||||
|
async def test_date_time(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
init_components,
|
||||||
|
) -> None:
|
||||||
|
"""Test the date and time intents."""
|
||||||
|
result = await conversation.async_converse(
|
||||||
|
hass, "what is the date", None, Context(), None
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
response = result.response
|
||||||
|
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
||||||
|
assert response.speech["plain"]["speech"] == "September 17th, 2013"
|
||||||
|
|
||||||
|
result = await conversation.async_converse(
|
||||||
|
hass, "what time is it", None, Context(), None
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
response = result.response
|
||||||
|
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
||||||
|
assert response.speech["plain"]["speech"] == "1:02 AM"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user