Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
zeehio committed Sep 26, 2024
1 parent 76b4212 commit 3fe1b6b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions homeassistant/components/local_calendar/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ async def async_setup_entry(
) -> None:
"""Set up the local calendar platform."""
store = hass.data[DOMAIN][config_entry.entry_id]
ics = await store.async_load()
calendar: Calendar = await hass.async_add_executor_job(
IcsCalendarStream.calendar_from_ics, ics
)
calendar.prodid = PRODID
name = config_entry.data[CONF_CALENDAR_NAME]
url = config_entry.data.get(CONF_CALENDAR_URL)
if url:
Expand All @@ -56,26 +61,22 @@ async def async_setup_entry(
else:
update_interval = DEFAULT_SYNC_INTERVAL
update_interval = max(update_interval, MIN_SYNC_INTERVAL)
entity = RemoteCalendarEntity(
entity: LocalCalendarEntityBase = RemoteCalendarEntity(

Check warning on line 64 in homeassistant/components/local_calendar/calendar.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/local_calendar/calendar.py#L62-L64

Added lines #L62 - L64 were not covered by tests
store,
calendar,
name,
unique_id=config_entry.entry_id,
url=url,
update_interval=update_interval,
)
else:
ics = await store.async_load()
calendar: Calendar = await hass.async_add_executor_job(
IcsCalendarStream.calendar_from_ics, ics
)
calendar.prodid = PRODID
entity = LocalCalendarEntity(
store, calendar, name, unique_id=config_entry.entry_id
)
async_add_entities([entity], True)


class ReadOnlyLocalCalendarEntity(CalendarEntity):
class LocalCalendarEntityBase(CalendarEntity):
"""Class for a read-only calendar entity backed by a local iCalendar file."""

_attr_has_entity_name = True
Expand All @@ -87,7 +88,7 @@ def __init__(
name: str,
unique_id: str,
) -> None:
"""Initialize LocalCalendarEntity."""
"""Initialize LocalCalendarEntityBase."""
self._store = store
self._calendar = calendar
self._event: CalendarEvent | None = None
Expand Down Expand Up @@ -124,19 +125,20 @@ async def _async_store(self) -> None:
await self._store.async_store(content)


class RemoteCalendarEntity(ReadOnlyLocalCalendarEntity):
class RemoteCalendarEntity(LocalCalendarEntityBase):
"""A read-only calendar that we get and refresh from a url."""

def __init__(
self,
store: LocalCalendarStore,
calendar: Calendar,
name: str,
unique_id: str,
url: str,
update_interval: timedelta,
) -> None:
"""Initialize a remote read-only calendar."""
super().__init__(store, None, name, unique_id)
super().__init__(store, calendar, name, unique_id)
self._url = url
self._client = None
self._track_fetch = None
Expand Down Expand Up @@ -177,14 +179,8 @@ async def async_will_remove_from_hass(self):
if self._track_fetch is not None:
self._track_fetch()

Check warning on line 180 in homeassistant/components/local_calendar/calendar.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/local_calendar/calendar.py#L179-L180

Added lines #L179 - L180 were not covered by tests

async def async_update(self) -> None:
"""Update once the calendar has been fetched."""
if self._calendar is None:
return
await super().async_update()


class LocalCalendarEntity(ReadOnlyLocalCalendarEntity):
class LocalCalendarEntity(LocalCalendarEntityBase):
"""A calendar entity backed by a local iCalendar file."""

_attr_supported_features = (
Expand Down

0 comments on commit 3fe1b6b

Please sign in to comment.