Add unique id for todoist calendar entity (#75674)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
1eb0983fba
commit
91384e07d0
2 changed files with 67 additions and 1 deletions
|
@ -296,6 +296,7 @@ class TodoistProjectEntity(CalendarEntity):
|
|||
)
|
||||
self._cal_data = {}
|
||||
self._name = data[CONF_NAME]
|
||||
self._attr_unique_id = data.get(CONF_ID)
|
||||
|
||||
@property
|
||||
def event(self) -> CalendarEvent:
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
"""Unit tests for the Todoist calendar platform."""
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant.components.todoist.calendar import _parse_due_date
|
||||
import pytest
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant.components.todoist.calendar import DOMAIN, _parse_due_date
|
||||
from homeassistant.components.todoist.types import DueDate
|
||||
from homeassistant.const import CONF_TOKEN
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.util import dt
|
||||
|
||||
|
||||
|
@ -42,3 +49,61 @@ def test_parse_due_date_without_timezone_uses_offset():
|
|||
}
|
||||
actual = _parse_due_date(data, timezone_offset=-8)
|
||||
assert datetime(2022, 2, 2, 22, 0, 0, tzinfo=dt.UTC) == actual
|
||||
|
||||
|
||||
@pytest.fixture(name="state")
|
||||
def mock_state() -> dict[str, Any]:
|
||||
"""Mock the api state."""
|
||||
return {
|
||||
"collaborators": [],
|
||||
"labels": [{"name": "label1", "id": 1}],
|
||||
"projects": [{"id": 12345, "name": "Name"}],
|
||||
}
|
||||
|
||||
|
||||
@patch("homeassistant.components.todoist.calendar.TodoistAPI")
|
||||
async def test_calendar_entity_unique_id(todoist_api, hass, state):
|
||||
"""Test unique id is set to project id."""
|
||||
api = Mock(state=state)
|
||||
todoist_api.return_value = api
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"calendar",
|
||||
{
|
||||
"calendar": {
|
||||
"platform": DOMAIN,
|
||||
CONF_TOKEN: "token",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
registry = entity_registry.async_get(hass)
|
||||
entity = registry.async_get("calendar.name")
|
||||
assert 12345 == entity.unique_id
|
||||
|
||||
|
||||
@patch("homeassistant.components.todoist.calendar.TodoistAPI")
|
||||
async def test_calendar_custom_project_unique_id(todoist_api, hass, state):
|
||||
"""Test unique id is None for any custom projects."""
|
||||
api = Mock(state=state)
|
||||
todoist_api.return_value = api
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"calendar",
|
||||
{
|
||||
"calendar": {
|
||||
"platform": DOMAIN,
|
||||
CONF_TOKEN: "token",
|
||||
"custom_projects": [{"name": "All projects"}],
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
registry = entity_registry.async_get(hass)
|
||||
entity = registry.async_get("calendar.all_projects")
|
||||
assert entity is None
|
||||
|
||||
state = hass.states.get("calendar.all_projects")
|
||||
assert state.state == "off"
|
||||
|
|
Loading…
Add table
Reference in a new issue