Skip to content

Commit

Permalink
Don't import google calendar user pref for disabling new entities (ho…
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter authored May 28, 2022
1 parent e061495 commit a598cdf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 69 deletions.
29 changes: 13 additions & 16 deletions homeassistant/components/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,18 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
_LOGGER.warning(
"Configuration of Google Calendar in YAML in configuration.yaml is "
"is deprecated and will be removed in a future release; Your existing "
"OAuth Application Credentials and other settings have been imported "
"OAuth Application Credentials and access settings have been imported "
"into the UI automatically and can be safely removed from your "
"configuration.yaml file"
)

if conf.get(CONF_TRACK_NEW) is False:
# The track_new as False would previously result in new entries
# in google_calendars.yaml with track set to Fasle which is
# handled at calendar entity creation time.
_LOGGER.warning(
"You must manually set the integration System Options in the "
"UI to disable newly discovered entities going forward"
)
return True


Expand Down Expand Up @@ -260,23 +267,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

def async_upgrade_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Upgrade the config entry if needed."""
if DATA_CONFIG not in hass.data[DOMAIN] and entry.options:
if entry.options:
return

options = (
entry.options
if entry.options
else {
CONF_CALENDAR_ACCESS: get_feature_access(hass).name,
}
)
disable_new_entities = (
not hass.data[DOMAIN].get(DATA_CONFIG, {}).get(CONF_TRACK_NEW, True)
)
hass.config_entries.async_update_entry(
entry,
options=options,
pref_disable_new_entities=disable_new_entities,
options={
CONF_CALENDAR_ACCESS: get_feature_access(hass).name,
},
)


Expand Down
82 changes: 29 additions & 53 deletions tests/components/google/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,57 +154,6 @@ async def test_calendar_yaml_error(
assert hass.states.get(TEST_API_ENTITY)


@pytest.mark.parametrize(
"google_config_track_new,calendars_config,expected_state",
[
(
None,
[],
State(
TEST_API_ENTITY,
STATE_OFF,
attributes={
"offset_reached": False,
"friendly_name": TEST_API_ENTITY_NAME,
},
),
),
(
True,
[],
State(
TEST_API_ENTITY,
STATE_OFF,
attributes={
"offset_reached": False,
"friendly_name": TEST_API_ENTITY_NAME,
},
),
),
(False, [], None),
],
ids=["default", "True", "False"],
)
async def test_track_new(
hass: HomeAssistant,
component_setup: ComponentSetup,
mock_calendars_list: ApiResult,
test_api_calendar: dict[str, Any],
mock_events_list: ApiResult,
mock_calendars_yaml: None,
expected_state: State,
setup_config_entry: MockConfigEntry,
) -> None:
"""Test behavior of configuration.yaml settings for tracking new calendars not in the config."""

mock_calendars_list({"items": [test_api_calendar]})
mock_events_list({})
assert await component_setup()

state = hass.states.get(TEST_API_ENTITY)
assert_state(state, expected_state)


@pytest.mark.parametrize("calendars_config", [[]])
async def test_found_calendar_from_api(
hass: HomeAssistant,
Expand Down Expand Up @@ -263,7 +212,7 @@ async def test_load_application_credentials(


@pytest.mark.parametrize(
"calendars_config_track,expected_state",
"calendars_config_track,expected_state,google_config_track_new",
[
(
True,
Expand All @@ -275,8 +224,35 @@ async def test_load_application_credentials(
"friendly_name": TEST_YAML_ENTITY_NAME,
},
),
None,
),
(
True,
State(
TEST_YAML_ENTITY,
STATE_OFF,
attributes={
"offset_reached": False,
"friendly_name": TEST_YAML_ENTITY_NAME,
},
),
True,
),
(
True,
State(
TEST_YAML_ENTITY,
STATE_OFF,
attributes={
"offset_reached": False,
"friendly_name": TEST_YAML_ENTITY_NAME,
},
),
False, # Has no effect
),
(False, None),
(False, None, None),
(False, None, True),
(False, None, False),
],
)
async def test_calendar_config_track_new(
Expand Down

0 comments on commit a598cdf

Please sign in to comment.