mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-27 17:44:01 +08:00
Update files
This commit is contained in:
@@ -56,3 +56,4 @@ class HATextAISensor(CoordinatorEntity, SensorEntity):
|
|||||||
ATTR_RESPONSE: last_response,
|
ATTR_RESPONSE: last_response,
|
||||||
ATTR_LAST_UPDATED: self.coordinator.last_update_success_time,
|
ATTR_LAST_UPDATED: self.coordinator.last_update_success_time,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
|||||||
|
ha_text_ai/
|
||||||
|
├── custom_components/
|
||||||
|
│ └── ha_text_ai/
|
||||||
|
│ ├── __init__.py
|
||||||
|
│ ├── manifest.json
|
||||||
|
│ ├── config_flow.py
|
||||||
|
│ ├── const.py
|
||||||
|
│ ├── coordinator.py
|
||||||
|
│ ├── sensor.py
|
||||||
|
│ ├── services.yaml
|
||||||
|
│ └── translations/
|
||||||
|
│ ├── en.json
|
||||||
|
│ └── ru.json
|
||||||
|
├── .github/
|
||||||
|
│ ├── ISSUE_TEMPLATE/
|
||||||
|
│ │ ├── bug_report.md
|
||||||
|
│ │ └── feature_request.md
|
||||||
|
│ └── workflows/
|
||||||
|
│ ├── hassfest.yaml
|
||||||
|
│ └── validate.yaml
|
||||||
|
├── tests/
|
||||||
|
│ └── test_init.py
|
||||||
|
├── .gitignore
|
||||||
|
├── LICENSE
|
||||||
|
├── README.md
|
||||||
|
├── hacs.json
|
||||||
|
└── info.md
|
||||||
+60
-18
@@ -1,23 +1,65 @@
|
|||||||
"""Tests for the HA text AI integration."""
|
"""Tests for the HA text AI integration."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from custom_components.ha_text_ai.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from custom_components.ha_text_ai.const import DOMAIN
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.fixture
|
||||||
async def test_setup(hass: HomeAssistant):
|
def mock_setup_entry() -> AsyncMock:
|
||||||
"""Test the setup."""
|
"""Override async_setup_entry."""
|
||||||
with patch('custom_components.ha_text_ai.coordinator.HATextAICoordinator'):
|
with patch(
|
||||||
assert await async_setup_component(hass, DOMAIN, {
|
"custom_components.ha_text_ai.async_setup_entry",
|
||||||
DOMAIN: {
|
return_value=True,
|
||||||
"api_key": "test_key",
|
) as mock_setup_entry:
|
||||||
"model": "gpt-3.5-turbo",
|
yield mock_setup_entry
|
||||||
"temperature": 0.7,
|
|
||||||
"max_tokens": 1000,
|
@pytest.fixture
|
||||||
"api_endpoint": "https://api.openai.com/v1",
|
def mock_coordinator() -> AsyncMock:
|
||||||
"request_interval": 1.0
|
"""Override coordinator."""
|
||||||
}
|
with patch(
|
||||||
})
|
"custom_components.ha_text_ai.coordinator.HATextAICoordinator",
|
||||||
await hass.async_block_till_done()
|
return_value=AsyncMock(),
|
||||||
assert DOMAIN in hass.data
|
) as mock_coordinator:
|
||||||
|
yield mock_coordinator
|
||||||
|
|
||||||
|
async def test_async_setup(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||||
|
"""Test the initial setup."""
|
||||||
|
assert await async_setup_component(hass, DOMAIN, {
|
||||||
|
DOMAIN: {
|
||||||
|
"api_key": "test_key",
|
||||||
|
"model": "gpt-3.5-turbo",
|
||||||
|
"temperature": 0.7,
|
||||||
|
"max_tokens": 1000,
|
||||||
|
"api_endpoint": "https://api.openai.com/v1",
|
||||||
|
"request_interval": 1.0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert DOMAIN in hass.data
|
||||||
|
|
||||||
|
async def test_async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_coordinator: AsyncMock
|
||||||
|
) -> None:
|
||||||
|
"""Test setup entry."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={
|
||||||
|
"api_key": "test_key",
|
||||||
|
"model": "gpt-3.5-turbo",
|
||||||
|
"temperature": 0.7,
|
||||||
|
"max_tokens": 1000,
|
||||||
|
"api_endpoint": "https://api.openai.com/v1",
|
||||||
|
"request_interval": 1.0
|
||||||
|
},
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_coordinator.mock_calls) == 1
|
||||||
|
assert DOMAIN in hass.data
|
||||||
|
assert entry.entry_id in hass.data[DOMAIN]
|
||||||
|
|||||||
Reference in New Issue
Block a user