Skip to content

Added configurable CO2 API backend: Nowtricity (default) or Wattnet. - #12

Merged
pailozka merged 2 commits into
releasefrom
wattnet
Aug 17, 2026
Merged

Added configurable CO2 API backend: Nowtricity (default) or Wattnet.#12
pailozka merged 2 commits into
releasefrom
wattnet

Conversation

@pailozka

Copy link
Copy Markdown
Collaborator
  • Introduced [CO2_API] section with TYPE selector (nowtricity|wattnet).
  • Nowtricity settings: BASE_URL, ZONE, USER_AGENT, API_KEY (unified prefix).
  • Wattnet settings: URL, API_KEY, ZONE, FOOTPRINT_TYPE, SCOPE.
  • Removed hardcoded Nowtricity API URLs — configurable via config.ini.

- Introduced [CO2_API] section with TYPE selector (nowtricity|wattnet).
- Nowtricity settings: BASE_URL, ZONE, USER_AGENT, API_KEY (unified prefix).
- Wattnet settings: URL, API_KEY, ZONE, FOOTPRINT_TYPE, SCOPE.
- Removed hardcoded Nowtricity API URLs — configurable via config.ini.
# Reverse to newest first (to match Nowtricity order) and take last 24
result = hourly_values[::-1][:24]

if len(result) < 24:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questionable if feeding padded data into decisions is the right approach. rather fail loudly:
if len(result) < 24: raise ValueError(f"Wattnet API returned only {len(result)}/24 hourly values")

it is consistent with the fallback logic here:

try:
historical_values, current_value, median_value, grade = co2_value({
'User-Agent': config['API']['USER_AGENT'],
'X-Api-Key': config['API']['API_KEY']
})
debug_log(f"Last 24 hours CO2 values (g CO2eq/kWh): {historical_values}")
debug_log(f"Current CO2 value (g CO2eq/kWh): {current_value}")
debug_log(f"Median value from 24 hours values (g CO2eq/kWh): {median_value}")
debug_log(f"Current CO2 value grade from 1 (low) to 10 (high): {grade}")
except Exception as e:
historical_values, current_value, median_value, grade = None, None, None, "unknown"
debug_log(f"Error fetching co2 values and rating: {e}")

@pailozka
pailozka merged commit 0e14c7b into release Aug 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants