-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a working location google calendar entity (#127016)
- Loading branch information
1 parent
963b9d9
commit c5ebd53
Showing
4 changed files
with
156 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,5 +123,12 @@ | |
} | ||
} | ||
} | ||
}, | ||
"entity": { | ||
"calendar": { | ||
"working_location": { | ||
"name": "Working location" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,11 @@ | |
import pytest | ||
|
||
from homeassistant.components.google.const import CONF_CALENDAR_ACCESS, DOMAIN | ||
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY | ||
from homeassistant.const import STATE_OFF, STATE_ON, Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
from homeassistant.helpers.entity_registry import RegistryEntryDisabler | ||
from homeassistant.helpers.template import DATE_STR_FORMAT | ||
import homeassistant.util.dt as dt_util | ||
|
||
|
@@ -1359,3 +1361,90 @@ async def test_invalid_rrule_fix( | |
assert event["uid"] == "[email protected]" | ||
assert event["recurrence_id"] == "_c8rinwq863h45qnucyoi43ny8_20230915" | ||
assert event["rrule"] is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("event_type", "expected_event_message"), | ||
[ | ||
("default", "Test All Day Event"), | ||
("workingLocation", None), | ||
], | ||
) | ||
async def test_working_location_ignored( | ||
hass: HomeAssistant, | ||
hass_client: ClientSessionGenerator, | ||
mock_events_list_items: Callable[[list[dict[str, Any]]], None], | ||
component_setup: ComponentSetup, | ||
event_type: str, | ||
expected_event_message: str | None, | ||
) -> None: | ||
"""Test working location events are skipped.""" | ||
event = { | ||
**TEST_EVENT, | ||
**upcoming(), | ||
"eventType": event_type, | ||
} | ||
mock_events_list_items([event]) | ||
assert await component_setup() | ||
|
||
state = hass.states.get(TEST_ENTITY) | ||
assert state | ||
assert state.name == TEST_ENTITY_NAME | ||
assert state.attributes.get("message") == expected_event_message | ||
|
||
|
||
@pytest.mark.parametrize("calendar_is_primary", [True]) | ||
async def test_working_location_entity( | ||
hass: HomeAssistant, | ||
hass_client: ClientSessionGenerator, | ||
entity_registry: er.EntityRegistry, | ||
mock_events_list_items: Callable[[list[dict[str, Any]]], None], | ||
component_setup: ComponentSetup, | ||
) -> None: | ||
"""Test that working location events are registered under a disabled by default entity.""" | ||
event = { | ||
**TEST_EVENT, | ||
**upcoming(), | ||
"eventType": "workingLocation", | ||
} | ||
mock_events_list_items([event]) | ||
assert await component_setup() | ||
|
||
entity_entry = entity_registry.async_get("calendar.working_location") | ||
assert entity_entry | ||
assert entity_entry.disabled_by == RegistryEntryDisabler.INTEGRATION | ||
|
||
entity_registry.async_update_entity( | ||
entity_id="calendar.working_location", disabled_by=None | ||
) | ||
async_fire_time_changed( | ||
hass, | ||
dt_util.utcnow() + datetime.timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1), | ||
) | ||
await hass.async_block_till_done() | ||
|
||
state = hass.states.get("calendar.working_location") | ||
assert state | ||
assert state.name == "Working location" | ||
assert state.attributes.get("message") == "Test All Day Event" | ||
|
||
|
||
@pytest.mark.parametrize("calendar_is_primary", [False]) | ||
async def test_no_working_location_entity( | ||
hass: HomeAssistant, | ||
hass_client: ClientSessionGenerator, | ||
entity_registry: er.EntityRegistry, | ||
mock_events_list_items: Callable[[list[dict[str, Any]]], None], | ||
component_setup: ComponentSetup, | ||
) -> None: | ||
"""Test that working location events are not registered for a secondary calendar.""" | ||
event = { | ||
**TEST_EVENT, | ||
**upcoming(), | ||
"eventType": "workingLocation", | ||
} | ||
mock_events_list_items([event]) | ||
assert await component_setup() | ||
|
||
entity_entry = entity_registry.async_get("calendar.working_location") | ||
assert not entity_entry |