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>pull/74734/head
parent
b2a3071658
commit
08d8304a52
|
@ -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:
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue