Skip to content

Conversation

petschni
Copy link

@petschni petschni commented Aug 4, 2025

Breaking change

Proposed change

🌱 Add Green Planet Energy Integration

This PR introduces a new integration for Green Planet Energy, a German renewable energy provider, offering real-time electricity pricing data to help Home Assistant users optimize their power consumption based on hourly electricity rates.

  • 29 Sensors Total:
  • 24 Hourly Price Sensors: sensor.gpe_price_00 through sensor.gpe_price_23 showing electricity prices for each hour
  • 5 Statistical Sensors: For energy optimization and monitoring:
    • sensor.gpe_current_price - Current hour's electricity price
    • sensor.gpe_highest_price_today - Peak price of the day
    • sensor.gpe_lowest_price_day - Cheapest price during day hours (06:00-18:00)
    • sensor.gpe_lowest_price_night - Cheapest price during night hours (18:00-06:00)
    • sensor.gpe_price_chart_24h - 24-hour chart data for visualization

The integration uses the following dependency: https://github.com/petschni/greenplanet-energy-api

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

- Add hourly electricity price sensors for business hours (9-18)
- Implement JSON-RPC API client with proper error handling
- Include comprehensive test suite with >95% coverage
- Meet Home Assistant Core Bronze quality standards
- Support config flow with unique entry validation
- Add runtime data for quality scale compliance
- Removed config flow, coordinator, and sensor files as part of the integration cleanup.
- Deleted constants and manifest files to streamline the integration structure.
- Updated the sensor implementation to support 24-hour pricing and added special sensors for highest, lowest, and current prices.
- Enhanced error handling and response processing in the API communication.
- Added installation script for easier setup of the integration.
- Updated tests to reflect changes in sensor setup and values, ensuring coverage for new features.
- Translated strings to English and improved naming conventions for clarity.
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @petschni

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@petschni petschni closed this Aug 4, 2025
@petschni petschni reopened this Aug 4, 2025
@petschni petschni marked this pull request as ready for review August 4, 2025 22:31
@home-assistant
Copy link

home-assistant bot commented Aug 8, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft August 8, 2025 20:26
@petschni
Copy link
Author

@joostlek thanks for the review! I applied your change requests. Got a bit bigger due to the changes to a service but I guess it makes more sense with the service. Let me know if there is more.

@petschni petschni marked this pull request as ready for review August 10, 2025 11:46
@home-assistant home-assistant bot requested a review from joostlek August 10, 2025 11:46
@home-assistant home-assistant bot marked this pull request as draft August 11, 2025 11:13
@petschni petschni marked this pull request as ready for review August 11, 2025 18:23
@home-assistant home-assistant bot requested a review from joostlek August 11, 2025 18:23
return True


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Let's extend the ConfigEntry type as described in the runtime-data rule

Copy link
Author

Choose a reason for hiding this comment

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

added a greenplanetconfigentry type

Comment on lines 33 to 34
if user_input is not None:
return self.async_create_entry(title="Green Planet Energy", data=user_input)
Copy link
Member

Choose a reason for hiding this comment

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

Let's still try to fetch some data. Mostly because the config flow is the best way to tell the user something is wrong. Maybe they have DNS set up incorrectly, or they have a pi-hole running which blocks it. This way we can guarantee that it works.

Copy link
Author

Choose a reason for hiding this comment

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

added a test

Comment on lines 189 to 260
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return additional state attributes."""
if self.entity_description.key == "gpe_highest_price_today":
# Find the hour with the highest price
highest_price = get_highest_price_today(self.coordinator.data)
highest_hour = None
if highest_price is not None and self.coordinator.data:
for hour in range(24):
price_key = f"gpe_price_{hour:02d}"
if self.coordinator.data.get(price_key) == highest_price:
highest_hour = hour
break
return {
"highest_price_hour": highest_hour,
"time_slot": f"{highest_hour:02d}:00-{highest_hour + 1:02d}:00"
if highest_hour is not None
else None,
}

if self.entity_description.key == "gpe_lowest_price_day":
# Find the hour with the lowest price during day (6-18)
lowest_price = get_lowest_price_day(self.coordinator.data)
lowest_hour = None
if lowest_price is not None and self.coordinator.data:
for hour in range(6, 18):
price_key = f"gpe_price_{hour:02d}"
if self.coordinator.data.get(price_key) == lowest_price:
lowest_hour = hour
break
return {
"lowest_price_hour": lowest_hour,
"time_slot": f"{lowest_hour:02d}:00-{lowest_hour + 1:02d}:00"
if lowest_hour is not None
else None,
"period": "day (06:00-18:00)",
}

if self.entity_description.key == "gpe_lowest_price_night":
# Find the hour with the lowest price during night (18-6)
lowest_price = get_lowest_price_night(self.coordinator.data)
lowest_hour = None
if lowest_price is not None and self.coordinator.data:
# Check evening hours (18-23)
for hour in range(18, 24):
price_key = f"gpe_price_{hour:02d}"
if self.coordinator.data.get(price_key) == lowest_price:
lowest_hour = hour
break
# Check early morning hours (0-5) if not found
if lowest_hour is None:
for hour in range(6):
price_key = f"gpe_price_{hour:02d}"
if self.coordinator.data.get(price_key) == lowest_price:
lowest_hour = hour
break
return {
"lowest_price_hour": lowest_hour,
"time_slot": f"{lowest_hour:02d}:00-{lowest_hour + 1:02d}:00"
if lowest_hour is not None
else None,
"period": "night (18:00-06:00)",
}

if self.entity_description.key == "gpe_current_price":
current_hour = dt_util.now().hour
return {
"current_hour": current_hour,
"time_slot": f"{current_hour:02d}:00-{current_hour + 1:02d}:00",
}

return None
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the extra state attributes for now?

Copy link
Author

Choose a reason for hiding this comment

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

I removed all but time_slot b/c that one is important for the usecase - otherwise I cannot show to the user when the price is actually cheap.

Comment on lines 179 to 182
if not self.coordinator.data:
return None

# Use value_fn to get calculated values
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if not self.coordinator.data:
return None
# Use value_fn to get calculated values

coordinator data is never None

Copy link
Member

Choose a reason for hiding this comment

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

Or, if it could be an empty dict, it should raise UpdateFailed

Copy link
Author

Choose a reason for hiding this comment

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

I removed the "none" case. I guess the updatefailed expection should be raised in the coordinator

Comment on lines 183 to 187
if self.entity_description.value_fn:
return self.entity_description.value_fn(self.coordinator.data)

# Fallback to coordinator data
return self.coordinator.data.get(self.entity_description.key)
Copy link
Member

Choose a reason for hiding this comment

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

They all have value_fns

Copy link
Author

Choose a reason for hiding this comment

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

removed the fallback - but still need the return or ?

@home-assistant home-assistant bot marked this pull request as draft August 11, 2025 21:12
@petschni petschni marked this pull request as ready for review August 12, 2025 20:57
@home-assistant home-assistant bot requested a review from joostlek August 12, 2025 20:57
@petschni
Copy link
Author

@joostlek I addressed the comments and finally also got the connected branding PR updated with the official files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants