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 get tariff from cache action/service to enphase_envoy #134820

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

catsmanac
Copy link
Contributor

@catsmanac catsmanac commented Jan 5, 2025

Proposed change

The enphase envoy integration collects data from the envoy device to populate various entity data. The set of available entities is based on actual envoy model, firmware version and configuration. Overall a most applicable set is provided for these mentioned drivers. When data is collected for the entities from various endpoints on the Envoy, all returned data is locally cached as 'raw' data. The raw cache contains more data as used for the entities.

This PR adds a service enphase_envoy.get_raw_tariff, to view 1 specific dataset from the raw cache: /admin/lib/tariff. This is data related to envoy battery operation. Recent firmware changes seem to have broken operation of some existing selector and switches. With this service the developers tools / actions tool can be used to view the full tariff data details and evaluate effect of changes on the battery operation. This data comes from the local cache maintained by the regular updates, no additional envoy communication is performed.

The documentation for below actions can be viewed here: https://deploy-preview-36740--home-assistant-docs.netlify.app/integrations/enphase_envoy/#action-enphase_envoyget_firmware

EDIT: This PR has been reworked after review. The original firmware retrieval will be made part of the coordinator itself. This service scope is limited to a single endpoint in the local cache.

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:

  • Documentation added/updated for www.home-assistant.io
    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:

@home-assistant
Copy link

home-assistant bot commented Jan 5, 2025

Hey there @bdraco, @cgarwood, @joostlek, mind taking a look at this pull request as it has been labeled with an integration (enphase_envoy) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of enphase_envoy can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign enphase_envoy Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@catsmanac catsmanac changed the title Add get firmware, raw data, current data, and post data services to enphase_envoy Add get firmware action/service to enphase_envoy Jan 8, 2025
@catsmanac catsmanac marked this pull request as ready for review January 8, 2025 17:46
Comment on lines 71 to 72
# setup the nephase_envoy action services
await setup_hass_services(hass, entry)
Copy link
Member

Choose a reason for hiding this comment

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

typo

We should set these up in async_setup not in async_setup_entry. Please check the iqs on that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I've moved it to async_setup and applied related changes for it.

@home-assistant
Copy link

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 January 17, 2025 16:22
@catsmanac catsmanac marked this pull request as ready for review January 18, 2025 12:34
@home-assistant home-assistant bot requested a review from joostlek January 18, 2025 12:34


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Enphase Envoy integration."""
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
"""Set up Enphase Envoy integration."""
"""Set up Enphase Envoy integration."""

SERVICE_GET_FIRMWARE = "get_firmware"
SERVICE_GET_FIRMWARE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENVOY): cv.entity_id,
Copy link
Member

Choose a reason for hiding this comment

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

I think we can also do a ConfigEntrySelector and select the config entry. (If I assume correctly that this is on a per enphase basis and not on a (sub) device basis). This way we don't give the user 100s of entities to pick from, but just every system they have, which is clearer I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked to use ConfigEntrySelector ,

Comment on lines 142 to 145
return {
"firmware": envoy_to_use.firmware,
"previous_firmware": previous_firmware,
}
Copy link
Member

Choose a reason for hiding this comment

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

So what do we use this for?

return None


def _find_envoy_coordinator(
Copy link
Member

Choose a reason for hiding this comment

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

I probably should have pointed you to this before, sorry for that. But have a check at Mealies services

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used the Mealies format.

Comment on lines 140 to 145
# if there's difference between coordinator fw
# and envoy one, user should reload the entry
return {
"firmware": envoy_to_use.firmware,
"previous_firmware": previous_firmware,
}
Copy link
Member

Choose a reason for hiding this comment

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

But why would this happen? If the user should do that, why don't we build that in for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Firmware refresh will move to coordinator. Replaced get)firmware service by get_raw_tariff services that returns a single endpoint only from raw cache. See updated description.

@home-assistant home-assistant bot marked this pull request as draft January 18, 2025 12:39
@catsmanac catsmanac changed the title Add get firmware action/service to enphase_envoy Add get tariff from cache action/service to enphase_envoy Jan 19, 2025
@catsmanac catsmanac marked this pull request as ready for review January 20, 2025 18:02
@home-assistant home-assistant bot requested a review from joostlek January 20, 2025 18:02
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.

4 participants