From 08d8304a529074a0b39b6ca83355ba799bf21afc Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Fri, 8 Jul 2022 07:59:50 -0700 Subject: [PATCH] Migrate google calendar to new entity naming (#74727) * Migrate google calendar to new entity naming * Update homeassistant/components/google/calendar.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/google/calendar.py | 9 +++------ tests/components/google/conftest.py | 4 ++-- tests/components/google/test_init.py | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index a86cdf55e3a..534b1cbdef3 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -216,6 +216,8 @@ async def async_setup_entry( class GoogleCalendarEntity(CalendarEntity): """A calendar event device.""" + _attr_has_entity_name = True + def __init__( self, calendar_service: GoogleCalendarService, @@ -231,7 +233,7 @@ class GoogleCalendarEntity(CalendarEntity): self._search: str | None = data.get(CONF_SEARCH) self._ignore_availability: bool = data.get(CONF_IGNORE_AVAILABILITY, False) self._event: CalendarEvent | None = None - self._name: str = data[CONF_NAME] + self._attr_name = data[CONF_NAME].capitalize() self._offset = data.get(CONF_OFFSET, DEFAULT_CONF_OFFSET) self._offset_value: timedelta | None = None self.entity_id = entity_id @@ -257,11 +259,6 @@ class GoogleCalendarEntity(CalendarEntity): """Return the next upcoming event.""" return self._event - @property - def name(self) -> str: - """Return the name of the entity.""" - return self._name - def _event_filter(self, event: Event) -> bool: """Return True if the event is visible.""" if self._ignore_availability: diff --git a/tests/components/google/conftest.py b/tests/components/google/conftest.py index a871722c2e9..f47d1232582 100644 --- a/tests/components/google/conftest.py +++ b/tests/components/google/conftest.py @@ -34,10 +34,10 @@ EMAIL_ADDRESS = "user@gmail.com" # the yaml config that overrides the entity name and other settings. A test # can use a fixture to exercise either case. TEST_API_ENTITY = "calendar.we_are_we_are_a_test_calendar" -TEST_API_ENTITY_NAME = "We are, we are, a... Test Calendar" +TEST_API_ENTITY_NAME = "We are, we are, a... test calendar" # Name of the entity when using yaml configuration overrides TEST_YAML_ENTITY = "calendar.backyard_light" -TEST_YAML_ENTITY_NAME = "Backyard Light" +TEST_YAML_ENTITY_NAME = "Backyard light" # A calendar object returned from the API TEST_API_CALENDAR = { diff --git a/tests/components/google/test_init.py b/tests/components/google/test_init.py index a40b499f769..f6c1f8c611f 100644 --- a/tests/components/google/test_init.py +++ b/tests/components/google/test_init.py @@ -20,7 +20,7 @@ from homeassistant.components.google import DOMAIN, SERVICE_ADD_EVENT from homeassistant.components.google.calendar import SERVICE_CREATE_EVENT from homeassistant.components.google.const import CONF_CALENDAR_ACCESS from homeassistant.config_entries import ConfigEntryState -from homeassistant.const import STATE_OFF +from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF from homeassistant.core import HomeAssistant, State from homeassistant.exceptions import HomeAssistantError from homeassistant.setup import async_setup_component @@ -307,8 +307,8 @@ async def test_multiple_config_entries( state = hass.states.get("calendar.example_calendar_1") assert state - assert state.name == "Example Calendar 1" assert state.state == STATE_OFF + assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Example calendar 1" config_entry2 = MockConfigEntry( domain=DOMAIN, data=config_entry.data, unique_id="other-address@example.com" @@ -327,7 +327,7 @@ async def test_multiple_config_entries( state = hass.states.get("calendar.example_calendar_2") assert state - assert state.name == "Example Calendar 2" + assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Example calendar 2" @pytest.mark.parametrize(