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 unique id to emoncms integration #117911

Conversation

alexandrecuer
Copy link
Contributor

@alexandrecuer alexandrecuer commented May 22, 2024

Proposed change

This PR adds unique_id for all sensors, so that so users can edit the feed settings

If you dont have emoncms, you can run it as a standalone docker container : https://hub.docker.com/r/alexjunk/emoncms

BEFORE
image

AFTER
image

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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

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 @alexandrecuer

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!

@home-assistant home-assistant bot marked this pull request as draft May 22, 2024 08:41
@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
Copy link

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

Code owner commands

Code owners of emoncms 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 emoncms 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.

Comment on lines 156 to 158
self._attr_unique_id = get_id(
sensorid, elem["tag"], elem["name"], elem["id"], elem["userid"]
)
Copy link
Member

Choose a reason for hiding this comment

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

Names cannot be part of a unique identifier.

See also our developer documentation around this, which lists the requirements: https://developers.home-assistant.io/docs/entity_registry_index/#unique-id

../Frenck

Copy link
Contributor Author

@alexandrecuer alexandrecuer May 22, 2024

Choose a reason for hiding this comment

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

tag and name removed from the unique id

emoncms API does not provide mac address at the moment, so I've kept sensor id, feed id and emoncms user_id

Copy link
Member

Choose a reason for hiding this comment

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

Are these unique across different installations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sensor id must be unique as specified in the doc :

id integer Required

Positive integer identifier for the sensor. Must be unique if you specify multiple Emoncms sensors.

cf https://www.home-assistant.io/integrations/emoncms/#id

unless I'm mistaken, I understand it is what you call unique id of last resort in the doc ?
https://developers.home-assistant.io/docs/entity_registry_index/#unique-id-of-last-resort

I've seen it used like that in the modbus integration

self._attr_unique_id = f"{self._attr_unique_id}_{idx}"

Copy link
Member

Choose a reason for hiding this comment

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

unless I'm mistaken, I understand it is what you call unique id of last resort in the doc ?

No, that is not the ID @ emoncms, that is the UUID of the config flow entry. As this integration doesn't have a configuration flow, it means there is no unique ID of last resort available.

In that case, this integration first needs to be migrated to a config flow (and thus UI configuration).

../Frenck

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK sorry, I was misled when I saw that the modbus did that way without having a flow config.

So going to close that PR, there is more work than expected

@home-assistant home-assistant bot marked this pull request as draft May 22, 2024 10:26
@alexandrecuer alexandrecuer requested a review from frenck May 22, 2024 12:56
@alexandrecuer alexandrecuer marked this pull request as ready for review May 22, 2024 12:56
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label May 25, 2024
@frenck frenck marked this pull request as draft May 29, 2024 08:43
@frenck
Copy link
Member

frenck commented May 29, 2024

Converted back to draft, as I had a followup question (see above).

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label May 29, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2024
@alexandrecuer alexandrecuer deleted the emoncms-integration-add-unique-id branch June 16, 2024 08:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants