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 energy management for efergy #56511

Closed
wants to merge 8 commits into from
Closed

Conversation

tkdrob
Copy link
Contributor

@tkdrob tkdrob commented Sep 21, 2021

Breaking change

Unit of measurement now uses an ISO standard currency code. Periods are now separate from the currency specified by the user, in the entity unit of measurement. Users are advised to adjust the currency configuration item, if set, to be a valid ISO standard currency code and also any automations, scripts, or templates that handle the entity unit of measurement.

Proposed change

Follow-up to: #54210
Should be merged after: #56890

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)
  • 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant probot-home-assistant bot added new-feature small-pr PRs with less than 30 lines. labels Sep 21, 2021
@project-bot project-bot bot added this to Needs review in Dev Sep 21, 2021
Dev automation moved this from Needs review to Review in progress Sep 22, 2021
@@ -146,7 +153,7 @@ def __init__(
if sid:
self._attr_name = f"efergy_{sid}"
if description.key == CONF_COST:
self._attr_native_unit_of_measurement = f"{currency}/{period}"
self._attr_native_unit_of_measurement = currency
Copy link
Member

Choose a reason for hiding this comment

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

This will be a breaking change. Is just the currency accurate as unit of measurement for this measurement?

If we're going to keep the device class as monetary for this sensor we need to validate that the currency config is an ISO-standard currency code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user can specify the period in the yaml and it defaults to yearly.

homeassistant/components/efergy/sensor.py Outdated Show resolved Hide resolved
@tkdrob tkdrob marked this pull request as draft September 25, 2021 09:04
@tkdrob
Copy link
Contributor Author

tkdrob commented Sep 25, 2021

So I just tested these changes further. Adding one of the two sensors for consumption is breaking the energy dashboard:

2021-09-25 05:04:01 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [4873682656] Error handling message: Unknown error
Traceback (most recent call last):
  File "/Users/tkdrob/core/homeassistant/components/websocket_api/decorators.py", line 25, in _handle_async_response
    await func(hass, connection, msg)
  File "/Users/tkdrob/core/homeassistant/components/energy/websocket_api.py", line 167, in ws_validate
    connection.send_result(msg["id"], (await async_validate(hass)).as_dict())
  File "/Users/tkdrob/core/homeassistant/components/energy/validate.py", line 283, in async_validate
    hass.data[DOMAIN]["cost_sensors"][flow["stat_energy_from"]],
KeyError: 'sensor.energy_consumed'

@tkdrob
Copy link
Contributor Author

tkdrob commented Sep 25, 2021

Marked as draft to block merge until issue is resolved.

@tkdrob
Copy link
Contributor Author

tkdrob commented Sep 25, 2021

I've now tested this on my production machine and everything works fine. This has to do with the current dev build or just my dev environment being screwy.

@tkdrob tkdrob marked this pull request as ready for review September 25, 2021 20:33
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Thanks!

Dev automation moved this from Review in progress to Reviewer approved Sep 25, 2021
@MartinHjelmare
Copy link
Member

Please link a docs PR where we update the currency config item description and example.

https://www.home-assistant.io/integrations/efergy/#configuration

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Sep 27, 2021
@MartinHjelmare MartinHjelmare marked this pull request as draft September 27, 2021 20:22
@MartinHjelmare
Copy link
Member

MartinHjelmare commented Sep 27, 2021

Changing to draft to avoid merging accidentally. We, author and me, decided to hold this until next release to give some time to add a config flow to avoid more than one breaking change release. The config flow is in the works.

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Sep 30, 2021
@tkdrob
Copy link
Contributor Author

tkdrob commented Oct 11, 2021

Closing as merger went wrong.

@tkdrob tkdrob closed this Oct 11, 2021
Dev automation moved this from Reviewer approved to Cancelled Oct 11, 2021
@tkdrob tkdrob deleted the efergy_energy branch October 11, 2021 08:59
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Cancelled
4 participants