Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_sum parameter to query parameters #105

Open
RikiSot opened this issue Oct 22, 2024 · 0 comments
Open

Add no_sum parameter to query parameters #105

RikiSot opened this issue Oct 22, 2024 · 0 comments
Labels
new-feature New features or request.

Comments

@RikiSot
Copy link

RikiSot commented Oct 22, 2024

Hi, it would be nice to add the option to control this query parameter. From the documentation:

no_sun
Type: integer flag (0|1)

By default the forecast is filled up to show the time from sunrise to sunset.

This will result in irregular timestamp offsets at the beginning and the end of the day but you have a full daylight forecast cycle.
https://api.forecast.solar/...?no_sun=1

This will suppress this logic and starts/ends with the first/last available dataset.

I cloned the repo and added this solution:

@dataclass
class ForecastSolar:
    """Main class for handling connections with the Forecast.Solar API."""

    azimuth: float
    declination: float
    kwp: float
    latitude: float
    longitude: float

    api_key: str | None = None
    damping: float = 0
    damping_morning: float | None = None
    damping_evening: float | None = None
    horizon: str | None = None
    no_sun: bool = True
...

    async def estimate(self, actual: float = 0) -> Estimate:
        """Get solar production estimations from the Forecast.Solar API.

        Args:
        ----
            actual: The production for the day in kWh so far. Used to improve
                the estimation for the current day if an API key is provided.

        Returns:
        -------
            A Estimate object, with a estimated production forecast.

        """
        params = {"time": "iso8601", "damping": str(self.damping), "no_sun": int(self.no_sun)}
        if self.inverter is not None:
            params["inverter"] = str(self.inverter)
        if self.horizon is not None:
            params["horizon"] = str(self.horizon)
        if self.damping_morning is not None and self.damping_evening is not None:
            params["damping_morning"] = str(self.damping_morning)
            params["damping_evening"] = str(self.damping_evening)
        if self.api_key is not None:
            params["actual"] = str(actual)

        data = await self._request(
            f"estimate/{self.latitude}/{self.longitude}"
            f"/{self.declination}/{self.azimuth}/{self.kwp}",
            params=params,
        )

        return Estimate.from_dict(data)
@klaasnicolaas klaasnicolaas added the new-feature New features or request. label Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New features or request.
Projects
None yet
Development

No branches or pull requests

2 participants