GoogleSolarApiClient fetches building insights from the Solar API 🟩

This commit is contained in:
Daniel Roth 2026-05-21 15:48:45 +00:00
parent 629fc34a0f
commit b0106fa93d

View file

@ -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