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

Explicitly set entity name for VenstarSensor #102158

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

dseven
Copy link
Contributor

@dseven dseven commented Oct 17, 2023

Proposed change

Address:

[homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22

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

@home-assistant
Copy link

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

Code owner commands

Code owners of venstar 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 venstar Removes the current integration label and assignees on the pull request, add the integration domain after the command.

Copy link

@rainepretorius rainepretorius left a comment

Choose a reason for hiding this comment

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

Looks all good. WHy do you want to update the _attr_name to None? It will cause multiple names on the device name?

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

This is not the right way to solve this issue. This will rename every sensor to the device name, causing sensor.{device_name} and sensor.{device_name}_1. This means one of the entities created doesn't have a translation key or device class (or name)

@home-assistant home-assistant bot marked this pull request as draft October 17, 2023 11:58
@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.

@joostlek
Copy link
Member

I just checked the code, and every sensor does have a name, so I am curious where this message comes from

@joostlek
Copy link
Member

So to explain it more, this message only pops up when the entity has has_entity_name = True and has no name. translation key or device class (in this specific order).

    @property
    def name(self):
        """Return the name of the device."""
        return self.entity_description.name_fn(self.sensor_name)

This part of the code makes sure the code always returns a name. This function never seems to return None.

I am guessing you can set this integration up in a development environment. Can you maybe give it a shot to change that piece of code to this?

    @property
    def name(self):
        """Return the name of the device."""
        name = self.entity_description.name_fn(self.sensor_name)
        print(name)
        return name

This would print out the name of the sensor before being returned. If I have to believe the code, this should never print None in the logs. If it does, we have something to investigate.

@dseven
Copy link
Contributor Author

dseven commented Oct 17, 2023

FWIW, the proposed change did make the warning go away for me, did not generate any new errors, and didn't appear to affect functionality at all.

I changed the diagnostic code to use logging instead of print() (and reverted my change). Here's what I get on startup...

homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Thermostat Temperature
homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Thermostat Temperature
homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:11:18.344 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 1 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 1 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 2 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 2 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 1 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 1 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 2 Runtime
homeassistant  | 2023-10-17 07:11:18.345 WARNING (MainThread) [homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22
homeassistant  | 2023-10-17 07:11:18.346 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 2 Runtime
homeassistant  | 2023-10-17 07:11:18.346 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Schedule Part
homeassistant  | 2023-10-17 07:11:18.346 WARNING (MainThread) [homeassistant.helpers.entity] Entity None (<class 'homeassistant.components.venstar.sensor.VenstarSensor'>) is implicitly using device name by not setting its name. Instead, the name should be set to None, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+venstar%22
homeassistant  | 2023-10-17 07:11:18.346 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Schedule Part
homeassistant  | 2023-10-17 07:12:20.972 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Thermostat Temperature
homeassistant  | 2023-10-17 07:12:20.972 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:12:20.973 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 1 Runtime
homeassistant  | 2023-10-17 07:12:20.973 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 2 Runtime
homeassistant  | 2023-10-17 07:12:20.973 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 1 Runtime
homeassistant  | 2023-10-17 07:12:20.973 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 2 Runtime
homeassistant  | 2023-10-17 07:12:20.973 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Schedule Part
homeassistant  | 2023-10-17 07:13:24.184 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Thermostat Temperature
homeassistant  | 2023-10-17 07:13:24.184 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:13:24.184 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 1 Runtime
homeassistant  | 2023-10-17 07:13:24.184 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 2 Runtime
homeassistant  | 2023-10-17 07:13:24.184 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 1 Runtime
homeassistant  | 2023-10-17 07:13:24.185 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 2 Runtime
homeassistant  | 2023-10-17 07:13:24.185 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Schedule Part
homeassistant  | 2023-10-17 07:14:27.327 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Thermostat Temperature
homeassistant  | 2023-10-17 07:14:27.327 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Space Temperature
homeassistant  | 2023-10-17 07:14:27.327 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 1 Runtime
homeassistant  | 2023-10-17 07:14:27.327 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Heating Stage 2 Runtime
homeassistant  | 2023-10-17 07:14:27.327 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 1 Runtime
homeassistant  | 2023-10-17 07:14:27.328 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Cooling Stage 2 Runtime
homeassistant  | 2023-10-17 07:14:27.328 WARNING (MainThread) [homeassistant.components.venstar.const] My name is Schedule Part

@joostlek
Copy link
Member

Heh, this doesn't make sense

@joostlek
Copy link
Member

Right, I looked it up and I might found something. has_entity_name doesn't really like the name property.

Can you try self._attr_name = entity_description.name_fn(sensor_name) in the constructor of the entity and remove the name property?

@dseven
Copy link
Contributor Author

dseven commented Oct 17, 2023

Can you try self._attr_name = entity_description.name_fn(sensor_name) in the constructor of the entity and remove the name property?

That seems to make everything happy. If I don't hear any counter arguments, I'l update the commit in a bit.

@joostlek
Copy link
Member

I copied this from Unifi, so I would say go for it

@dseven dseven force-pushed the venstar-sensor-entity-name branch from 35b0cb8 to 8ed5b8d Compare October 17, 2023 15:34
Set entity name using _attr_name instead of a name property, to
avoid warnings about name being implicitly set to None.
@dseven dseven force-pushed the venstar-sensor-entity-name branch from 8ed5b8d to 3be0e64 Compare October 17, 2023 15:36
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

If you put this ready for review I will merge this

@dseven dseven marked this pull request as ready for review October 17, 2023 15:56
@home-assistant home-assistant bot requested a review from joostlek October 17, 2023 15:56
@joostlek joostlek merged commit 44a5a2d into home-assistant:dev Oct 17, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
@joostlek joostlek added this to the 2023.10.4 milestone Oct 19, 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.

Venstar HVAC thermostat VenstarSensor Entity name error
4 participants