Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #548 from Thomas55555/remove-reverse-geocode
Browse files Browse the repository at this point in the history
remove reverse geocode
  • Loading branch information
Thomas55555 committed Oct 10, 2023
2 parents 3ceb4ba + cd1b0e4 commit 8c72c1a
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 144 deletions.
1 change: 0 additions & 1 deletion core
Submodule core deleted from f0abea
22 changes: 0 additions & 22 deletions custom_components/husqvarna_automower/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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}",
Expand Down
1 change: 0 additions & 1 deletion custom_components/husqvarna_automower/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
120 changes: 0 additions & 120 deletions custom_components/husqvarna_automower/tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8c72c1a

Please sign in to comment.