mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 03:03:17 +01:00
Add support for initial color in Google Calendar (#161671)
This commit is contained in:
@@ -101,6 +101,7 @@ class GoogleCalendarEntityDescription(CalendarEntityDescription):
|
||||
search: str | None
|
||||
local_sync: bool
|
||||
device_id: str
|
||||
initial_color: str | None = None
|
||||
event_type: EventTypeEnum | None = None
|
||||
|
||||
|
||||
@@ -161,6 +162,7 @@ def _get_entity_descriptions(
|
||||
local_sync=local_sync,
|
||||
entity_registry_enabled_default=entity_enabled,
|
||||
device_id=data[CONF_DEVICE_ID],
|
||||
initial_color=calendar_item.background_color,
|
||||
)
|
||||
entity_descriptions.append(entity_description)
|
||||
_LOGGER.debug(
|
||||
@@ -359,6 +361,7 @@ class GoogleCalendarEntity(
|
||||
if entity_description.entity_id:
|
||||
self.entity_id = entity_description.entity_id
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_initial_color = entity_description.initial_color
|
||||
if not entity_description.read_only:
|
||||
self._attr_supported_features = (
|
||||
CalendarEntityFeature.CREATE_EVENT | CalendarEntityFeature.DELETE_EVENT
|
||||
|
||||
@@ -1562,3 +1562,43 @@ async def test_birthday_entity(
|
||||
assert state
|
||||
assert state.name == "Birthdays"
|
||||
assert state.attributes.get("message") == expected_event_message
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("background_color", "expected_color"),
|
||||
[
|
||||
("#16a765", "#16a765"), # Valid color
|
||||
("not-a-color", None), # Invalid color
|
||||
(None, None), # Missing color
|
||||
],
|
||||
)
|
||||
async def test_calendar_background_color(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_calendars_list: ApiResult,
|
||||
mock_events_list_items: Callable[[list[dict[str, Any]]], None],
|
||||
component_setup: ComponentSetup,
|
||||
entity_registry: er.EntityRegistry,
|
||||
background_color: str | None,
|
||||
expected_color: str | None,
|
||||
) -> None:
|
||||
"""Test backgroundColor from API is stored in entity options only if valid."""
|
||||
aioclient_mock.clear_requests()
|
||||
calendar_item: dict[str, Any] = {
|
||||
"id": CALENDAR_ID,
|
||||
"etag": '"3584134138943410"',
|
||||
"timeZone": "UTC",
|
||||
"accessRole": "owner",
|
||||
"summary": "Test Calendar",
|
||||
}
|
||||
if background_color is not None:
|
||||
calendar_item["backgroundColor"] = background_color
|
||||
mock_calendars_list({"items": [calendar_item]})
|
||||
mock_events_list_items([])
|
||||
|
||||
assert await component_setup()
|
||||
|
||||
# Verify the main calendar entity has the color set
|
||||
entity = entity_registry.async_get("calendar.test_calendar")
|
||||
assert entity is not None
|
||||
assert entity.options.get("calendar", {}).get("color") == expected_color
|
||||
|
||||
Reference in New Issue
Block a user