Fix google calendar working location event filtering (#141222)

This commit is contained in:
Allen Porter 2025-03-23 09:07:42 -07:00 committed by GitHub
parent f14b76c54b
commit c451518959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -383,9 +383,9 @@ class GoogleCalendarEntity(
for attendee in event.attendees for attendee in event.attendees
): ):
return False return False
is_working_location_event = event.event_type == EventTypeEnum.WORKING_LOCATION
if event.event_type == EventTypeEnum.WORKING_LOCATION: if self.entity_description.working_location != is_working_location_event:
return self.entity_description.working_location return False
if self._ignore_availability: if self._ignore_availability:
return True return True
return event.transparency == OPAQUE return event.transparency == OPAQUE

View File

@ -1451,6 +1451,13 @@ async def test_working_location_ignored(
assert state.attributes.get("message") == expected_event_message assert state.attributes.get("message") == expected_event_message
@pytest.mark.parametrize(
("event_type", "expected_event_message"),
[
("workingLocation", "Test All Day Event"),
("default", None),
],
)
@pytest.mark.parametrize("calendar_is_primary", [True]) @pytest.mark.parametrize("calendar_is_primary", [True])
async def test_working_location_entity( async def test_working_location_entity(
hass: HomeAssistant, hass: HomeAssistant,
@ -1458,12 +1465,14 @@ async def test_working_location_entity(
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mock_events_list_items: Callable[[list[dict[str, Any]]], None], mock_events_list_items: Callable[[list[dict[str, Any]]], None],
component_setup: ComponentSetup, component_setup: ComponentSetup,
event_type: str,
expected_event_message: str | None,
) -> None: ) -> None:
"""Test that working location events are registered under a disabled by default entity.""" """Test that working location events are registered under a disabled by default entity."""
event = { event = {
**TEST_EVENT, **TEST_EVENT,
**upcoming(), **upcoming(),
"eventType": "workingLocation", "eventType": event_type,
} }
mock_events_list_items([event]) mock_events_list_items([event])
assert await component_setup() assert await component_setup()
@ -1484,7 +1493,7 @@ async def test_working_location_entity(
state = hass.states.get("calendar.working_location") state = hass.states.get("calendar.working_location")
assert state assert state
assert state.name == "Working location" assert state.name == "Working location"
assert state.attributes.get("message") == "Test All Day Event" assert state.attributes.get("message") == expected_event_message
@pytest.mark.parametrize("calendar_is_primary", [False]) @pytest.mark.parametrize("calendar_is_primary", [False])