diff --git a/core b/core deleted file mode 160000 index f0abea4..0000000 --- a/core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f0abea48a6aef5c8f35770f36df5a47488ed3df6 diff --git a/custom_components/husqvarna_automower/calendar.py b/custom_components/husqvarna_automower/calendar.py index 6b5327d..0f01730 100644 --- a/custom_components/husqvarna_automower/calendar.py +++ b/custom_components/husqvarna_automower/calendar.py @@ -6,7 +6,6 @@ import homeassistant.util.dt as dt_util import voluptuous as vol from aiohttp import ClientResponseError -from geopy.geocoders import Nominatim from homeassistant.components.calendar import ( CalendarEntity, CalendarEntityFeature, @@ -52,7 +51,6 @@ def __init__(self, session, idx) -> None: self._event = None self._next_event = None self.loc = None - self.geolocator = Nominatim(user_agent=self.mower_id) self._attr_unique_id = f"{self.mower_id}_calendar" @property @@ -67,24 +65,6 @@ async def async_get_events_data( ) -> list[CalendarEvent]: """Get all events in a specific time frame.""" mower_attributes = AutomowerEntity.get_mower_attributes(self) - try: - lat = mower_attributes["positions"][0]["latitude"] - long = mower_attributes["positions"][0]["longitude"] - position = f"{lat}, {long}" - result = await hass.async_add_executor_job( - self.geolocator.reverse, position - ) - try: - self.loc = ( - f"{result.raw['address']['road']} " - f"{result.raw['address']['house_number']}, " - f"{result.raw['address']['town']}" - ) - except Exception: # TODO: What exception are we trying to catch here? - self.loc = None - except IndexError: - self.loc = None - # pylint: disable=unused-variable even_list, next_event = self.get_next_event() return even_list @@ -95,7 +75,6 @@ def get_next_event(self) -> tuple[list[CalendarEvent], CalendarEvent]: summary="", start=dt_util.start_of_local_day() + dt_util.dt.timedelta(days=7), end=dt_util.start_of_local_day() + dt_util.dt.timedelta(days=7, hours=2), - location="", ) event_list = [] # pylint: disable=unused-variable @@ -128,7 +107,6 @@ def get_next_event(self) -> tuple[list[CalendarEvent], CalendarEvent]: start=start_mowing + dt_util.dt.timedelta(days=days), end=end_mowing + dt_util.dt.timedelta(days=days), description="Description can't be changed", - location=self.loc, rrule=f"FREQ=WEEKLY;BYDAY={day_list}", uid=task, recurrence_id=f"Recure{task}", diff --git a/custom_components/husqvarna_automower/manifest.json b/custom_components/husqvarna_automower/manifest.json index ba37a74..33691f8 100644 --- a/custom_components/husqvarna_automower/manifest.json +++ b/custom_components/husqvarna_automower/manifest.json @@ -22,7 +22,6 @@ ], "requirements": [ "aioautomower==2023.8.1", - "geopy>=2.1.0", "numpy>=1.21.6", "Pillow>=9.1.1", "Shapely>=1.8.2" diff --git a/custom_components/husqvarna_automower/tests/test_calendar.py b/custom_components/husqvarna_automower/tests/test_calendar.py index 1025a98..393e65d 100644 --- a/custom_components/husqvarna_automower/tests/test_calendar.py +++ b/custom_components/husqvarna_automower/tests/test_calendar.py @@ -7,7 +7,6 @@ import voluptuous as vol from aioautomower import AutomowerSession from aiohttp import ClientResponseError -from geopy import Location from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from pytest_homeassistant_custom_component.common import MockConfigEntry @@ -89,125 +88,6 @@ async def test_calendar(hass: HomeAssistant): assert calendar.available == True - # Get calendar events - location_result = Location( - "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - (35.5399226, -82.55193188763246, 0.0), - { - "place_id": 266519807, - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", - "osm_type": "way", - "osm_id": 830192286, - "lat": "35.5399226", - "lon": "-82.55193188763246", - "display_name": "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - "address": { - "leisure": "Italian Garden", - "road": "Biltmore Estate Path", - "county": "Buncombe County", - "state": "North Carolina", - "ISO3166-2-lvl4": "US-NC", - "postcode": "28803", - "country": "United States", - "country_code": "us", - "house_number": "1", - "town": "Asheville", - }, - "boundingbox": ["35.5395166", "35.5403093", "-82.5530644", "-82.550742"], - }, - ) - with patch.object( - calendar, - "geolocator", - MagicMock(reverse=MagicMock(return_value=location_result)), - ) as mock_geo: - result = await calendar.async_get_events_data( - hass, datetime(2023, 6, 9, 7), datetime(2023, 6, 9, 16) - ) - mock_geo.reverse.assert_called_once() - assert len(result) == 6 - - # No house number in return address - location_result = Location( - "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - (35.5399226, -82.55193188763246, 0.0), - { - "place_id": 266519807, - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", - "osm_type": "way", - "osm_id": 830192286, - "lat": "35.5399226", - "lon": "-82.55193188763246", - "display_name": "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - "address": { - "leisure": "Italian Garden", - "road": "Biltmore Estate Path", - "county": "Buncombe County", - "state": "North Carolina", - "ISO3166-2-lvl4": "US-NC", - "postcode": "28803", - "country": "United States", - "country_code": "us", - "town": "Asheville", - }, - "boundingbox": [ - "35.5395166", - "35.5403093", - "-82.5530644", - "-82.550742", - ], - }, - ) - mock_geo.reverse.reset_mock() - mock_geo.reverse.return_value = location_result - result = await calendar.async_get_events_data( - hass, datetime(2023, 6, 9, 7), datetime(2023, 6, 9, 16) - ) - mock_geo.reverse.assert_called_once() - assert len(result) == 6 - - # No postions, Index error - location_result = Location( - "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - (35.5399226, -82.55193188763246, 0.0), - { - "place_id": 266519807, - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", - "osm_type": "way", - "osm_id": 830192286, - "lat": "35.5399226", - "lon": "-82.55193188763246", - "display_name": "Italian Garden, Biltmore Estate Path, Buncombe County, North Carolina, 28803, United States", - "address": { - "leisure": "Italian Garden", - "road": "Biltmore Estate Path", - "county": "Buncombe County", - "state": "North Carolina", - "ISO3166-2-lvl4": "US-NC", - "postcode": "28803", - "country": "United States", - "country_code": "us", - "house_number": "1", - "town": "Asheville", - }, - "boundingbox": [ - "35.5395166", - "35.5403093", - "-82.5530644", - "-82.550742", - ], - }, - ) - mock_geo.reverse.reset_mock() - mock_geo.reverse.return_value = location_result - coordinator.session.data["data"][MWR_ONE_IDX]["attributes"]["positions"] = [] - - result = await calendar.async_get_events_data( - hass, datetime(2023, 6, 9, 7), datetime(2023, 6, 9, 16) - ) - mock_geo.reverse.assert_not_called() - assert len(result) == 6 - # Get next event assert len(calendar.get_next_event()) == 2