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

Introduce base entity for ping #104197

Merged
merged 4 commits into from Nov 24, 2023
Merged

Conversation

jpbede
Copy link
Member

@jpbede jpbede commented Nov 19, 2023

Proposed change

Introduce a base entity for ping, also move the device tracker from ScannerEntity to BaseTrackerEntity so we can attach device infos.ScannerEntity tries to attach the entity to an existing device entry based on MAC, but this integration has no MAC.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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 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.

To help with the load of incoming pull requests:

"""Initialize the Ping Binary sensor."""
super().__init__(coordinator)

self._attr_name = config_entry.title
Copy link
Member

Choose a reason for hiding this comment

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

_attr_has_entity_name = True and _attr_name=None? Maybe need to check how this works with the device tracker entity

Copy link
Member Author

Choose a reason for hiding this comment

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

But this will not rename the entities when renaming the config entry. It was suggested in #103743 (comment) not to use a "name" option in the config flow, instead use the config entry title.

Copy link
Member

Choose a reason for hiding this comment

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

What @joostlek is proposing is to use the device name instead of just the entity name.
I don't know either if this works well on this case but we should strive for implementing _attr_has_entity_name on as many as possible to go for devices and its name in case of config flows.

Copy link
Member Author

Choose a reason for hiding this comment

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

I fully agree and I'm fine with this change, it was just a note that the user then has to change the title of the config entry and the device name, but that is something the user already knows.

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Nov 23, 2023
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Nice! Thanks, @jpbede 👍

../Frenck

@frenck frenck merged commit 6f54aaf into home-assistant:dev Nov 24, 2023
23 checks passed
@jpbede jpbede deleted the ping-base-entity branch November 24, 2023 10:23
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2023
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.

This PR was badly named. It sounds like it's a refactor but it's actually changing features and the design of the device tracker.

homeassistant/components/ping/entity.py Show resolved Hide resolved
def is_connected(self) -> bool:
"""Return true if ping returns is_alive."""
return self.coordinator.data.is_alive
def state(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Overriding state isn't really according to our design intentions. I think this needs further discussion. I suggest we revert this PR for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Revert PR #104682

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't know that, I just saw that ibeacon and private_ble_device do it the same way (extend BaseTrackerEntity and override state) and thought it would be fine.

Copy link
Member

Choose a reason for hiding this comment

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

The two device tracker entity classes we've documented are ScannerEntity and TrackerEntity. If those aren't sufficient to cover all cases we should make an architecture discussion and figure out what else is needed.

https://developers.home-assistant.io/docs/core/entity/device-tracker

@home-assistant home-assistant unlocked this conversation Nov 29, 2023
jpbede added a commit that referenced this pull request Nov 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2023
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

5 participants