Skip to content

Commit

Permalink
Waze Exception TypeError: WazeRouteCalculator.init() got an unexpecte…
Browse files Browse the repository at this point in the history
…d keyword argument avoid_toll_roads #12
  • Loading branch information
rodpayne committed Dec 10, 2023
1 parent 9b7ddc7 commit 6c54ed0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion custom_components/person_location/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
API_STATE_OBJECT = DOMAIN + "." + DOMAIN + "_integration"
INTEGRATION_NAME = "Person Location"
ISSUE_URL = "https://github.com/rodpayne/home-assistant/issues"
VERSION = "2023.09.26"
VERSION = "2023.12.09"

# Fixed parameters:
MIN_DISTANCE_TRAVELLED_TO_GEOCODE = 5
Expand Down
2 changes: 1 addition & 1 deletion custom_components/person_location/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/rodpayne/home-assistant_person_location/issues",
"requirements": [],
"version": "2023.09.26"
"version": "2023.12.09"
}
40 changes: 30 additions & 10 deletions custom_components/person_location/reverse_geocode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" The person_location integration reverse_geocode service."""

import asyncio
import json
import logging
import math
Expand All @@ -17,9 +18,11 @@
CONF_FRIENDLY_NAME_TEMPLATE,
STATE_ON,
)
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.util.location import distance
from requests import get
from pywaze.route_calculator import WazeRouteCalculator
# from requests import get
import httpx
from pywaze.route_calculator import WazeRouteCalculator,WRCError

from .const import (
ATTR_BREAD_CRUMBS,
Expand Down Expand Up @@ -430,7 +433,7 @@ def handle_reverse_geocode(call):
)

osm_decoded = {}
osm_response = get(osm_url)
osm_response = httpx.get(osm_url)
osm_json_input = osm_response.text
osm_decoded = json.loads(osm_json_input)

Expand Down Expand Up @@ -515,7 +518,7 @@ def handle_reverse_geocode(call):
+ pli.configuration[CONF_GOOGLE_API_KEY]
)
google_decoded = {}
google_response = get(google_url)
google_response = httpx.get(google_url)
google_json_input = google_response.text
google_decoded = json.loads(google_json_input)

Expand Down Expand Up @@ -614,7 +617,7 @@ def handle_reverse_geocode(call):
+ pli.configuration[CONF_MAPQUEST_API_KEY]
)
mapquest_decoded = {}
mapquest_response = get(mapquest_url)
mapquest_response = httpx.get(mapquest_url)
mapquest_json_input = mapquest_response.text
_LOGGER.debug(
"("
Expand Down Expand Up @@ -785,6 +788,22 @@ def handle_reverse_geocode(call):
"(" + entity_id + ") Waze calculation"
)

async def async_get_waze_route (
from_location,
to_location,
waze_region,
):
client = WazeRouteCalculator(
region=waze_region,
client=get_async_client(pli.hass),
)
route = await client.calc_route_info(
from_location,
to_location,
avoid_toll_roads=True,
)
return route

from_location = (
str(new_latitude) + "," + str(new_longitude)
)
Expand All @@ -793,13 +812,14 @@ def handle_reverse_geocode(call):
+ ","
+ str(pli.attributes["home_longitude"])
)
route = WazeRouteCalculator(
routeTime, routeDistance = asyncio.run_coroutine_threadsafe(
async_get_waze_route(
from_location,
to_location,
pli.configuration["waze_region"],
avoid_toll_roads=True,
)
routeTime, routeDistance = route.calc_route_info()
pli.configuration["waze_region"].upper(),
# "US",
),pli.hass.loop
).result()
_LOGGER.debug(
"("
+ entity_id
Expand Down

0 comments on commit 6c54ed0

Please sign in to comment.