mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
GoogleSolarApiClient fetches building insights from the Solar API 🟩
This commit is contained in:
parent
629fc34a0f
commit
b0106fa93d
1 changed files with 14 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Any, Literal
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class BuildingInsightsNotFoundError(Exception):
|
||||
pass
|
||||
|
|
@ -11,7 +13,7 @@ class GoogleSolarApiClient:
|
|||
ENTITY_NOT_FOUND_ERROR: str = "Requested entity was not found."
|
||||
|
||||
def __init__(self, api_key: str) -> None:
|
||||
raise NotImplementedError
|
||||
self._api_key = api_key
|
||||
|
||||
def get_building_insights(
|
||||
self,
|
||||
|
|
@ -19,4 +21,14 @@ class GoogleSolarApiClient:
|
|||
latitude: float,
|
||||
required_quality: Literal["HIGH", "MEDIUM", "LOW"] = "MEDIUM",
|
||||
) -> dict[str, Any]:
|
||||
raise NotImplementedError
|
||||
insights_url = f"{self.base_url}/buildingInsights:findClosest"
|
||||
params: dict[str, str] = {
|
||||
"location.latitude": f"{latitude:.5f}",
|
||||
"location.longitude": f"{longitude:.5f}",
|
||||
"requiredQuality": required_quality,
|
||||
"key": self._api_key,
|
||||
}
|
||||
response = requests.get(insights_url, params=params)
|
||||
response.raise_for_status()
|
||||
result: dict[str, Any] = response.json()
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue