Skip to content

Commit 84789e6

Browse files
Add account type (#14)
1 parent a07debe commit 84789e6

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ With this python library you can request data from [forecast.solar](https://fore
2424

2525
This library returns a lot of different data, based on the API:
2626

27-
- Estimated Energy Production - Today
28-
- Estimated Energy Production - Tomorrow
29-
- Estimated Energy Production - This Hour
30-
- Estimated Energy Production - Next Hour
31-
- Highest Power Peak Time - Today
32-
- Highest Power Peak Time - Tomorrow
33-
- Estimated Power Production - Now
34-
- Estimated Power Production - Next Hour
35-
- Estimated Power Production - Next +6 Hours
36-
- Estimated Power Production - Next +12 Hours
37-
- Estimated Power Production - Next +24 Hours
27+
### Energy
28+
29+
- Total Estimated Energy Production - today/tomorrow (kWh)
30+
- Estimated Energy Production - This Hour (kWh)
31+
- Estimated Energy Production - Next Hour (kWh)
32+
33+
### Power
34+
35+
- Highest Power Peak Time - Today (datetime)
36+
- Highest Power Peak Time - Tomorrow (datetime)
37+
- Estimated Power Production - Now (W)
38+
- Estimated Power Production - Next Hour (W)
39+
- Estimated Power Production - In +6 Hours (W)
40+
- Estimated Power Production - In +12 Hours (W)
41+
- Estimated Power Production - In +24 Hours (W)
42+
43+
### API Info
44+
3845
- Timezone
46+
- Rate limit
47+
- Account type
48+
- Rate remaining
3949

4050
## Contributing
4151

example.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ async def main():
4848
)
4949
print()
5050
print(f"energy_current_hour: {estimate.energy_current_hour}")
51-
print(f"energy_production_next_hour: {estimate.sum_energy_production(1)}")
52-
print(f"energy_production_next_6hours: {estimate.sum_energy_production(6)}")
53-
print(f"energy_production_next_12hours: {estimate.sum_energy_production(12)}")
54-
print(f"energy_production_next_24hours: {estimate.sum_energy_production(24)}")
51+
print(f"energy_production next hour: {estimate.sum_energy_production(1)}")
52+
print(f"energy_production next 6 hours: {estimate.sum_energy_production(6)}")
53+
print(f"energy_production next 12 hours: {estimate.sum_energy_production(12)}")
54+
print(f"energy_production next 24 hours: {estimate.sum_energy_production(24)}")
5555
print(f"timezone: {estimate.timezone}")
56+
print(f"account_type: {estimate.account_type}")
5657
print(forecast.ratelimit)
5758

5859

forecast_solar/models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from dataclasses import dataclass
55
from datetime import datetime, timedelta, date
6+
from enum import Enum
67
from typing import Any
78
import sys
89

@@ -25,6 +26,14 @@ def _timed_value(at: datetime, data: dict[datetime, int]) -> int | None:
2526
return None
2627

2728

29+
class AccountType(str, Enum):
30+
"""Enumeration representing the Forecast.Solar account type."""
31+
32+
PUBLIC = "public"
33+
PERSONAL = "personal"
34+
PROFESSIONAL = "professional"
35+
36+
2837
@dataclass
2938
class Estimate:
3039
"""Object holding estimate forecast results from Forecast.Solar.
@@ -38,13 +47,23 @@ class Estimate:
3847
wh_days: dict[datetime, int]
3948
wh_hours: dict[datetime, int]
4049
watts: dict[datetime, int]
50+
api_rate_limit: int
4151
api_timezone: str
4252

4353
@property
4454
def timezone(self) -> str:
4555
"""Return API timezone information."""
4656
return self.api_timezone
4757

58+
@property
59+
def account_type(self) -> AccountType:
60+
"""Return API account_type information."""
61+
if self.api_rate_limit == 60:
62+
return AccountType.PERSONAL
63+
if self.api_rate_limit == 5:
64+
return AccountType.PROFESSIONAL
65+
return AccountType.PUBLIC
66+
4867
@property
4968
def energy_production_today(self) -> int:
5069
"""Return estimated energy produced today."""
@@ -158,6 +177,7 @@ def from_dict(cls, data: dict[str, Any]) -> Estimate:
158177
watts={
159178
datetime.fromisoformat(d): w for d, w in data["result"]["watts"].items()
160179
},
180+
api_rate_limit=data["message"]["ratelimit"]["limit"],
161181
api_timezone=data["message"]["info"]["timezone"],
162182
)
163183

0 commit comments

Comments
 (0)