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

Use entity descriptions in Roomba #102323

Merged
merged 8 commits into from
Oct 19, 2023
Merged

Conversation

joostlek
Copy link
Member

Proposed change

Use entity descriptions in Roomba.

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:

@home-assistant
Copy link

Hey there @pschmitt, @cyr-ius, @shenxn, mind taking a look at this pull request as it has been labeled with an integration (roomba) you are listed as a code owner for? Thanks!

Code owner commands

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

# Conflicts:
#	homeassistant/components/roomba/irobot_base.py
#	homeassistant/components/roomba/sensor.py
@joostlek joostlek marked this pull request as ready for review October 19, 2023 13:52
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Tested, looks like there is an issue I didn't see in review

2023-10-19 06:34:05.245 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.245 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.245 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.246 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.246 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.246 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.246 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.246 ERROR (MainThread) [homeassistant.components.sensor] Platform roomba does not generate unique IDs. ID roomba_6BCDC6ED83A24782B24D53F0E2F1A1F1 already exists - ignoring sensor.89_upstairroomba_battery
2023-10-19 06:34:05.294 ERROR (MainThread) [homeassistant.components.vacuum] Error adding entities for domain vacuum with platform roomba
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 786, in _async_generate_attributes
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/vacuum/__init__.py", line 281, in state_attributes
    data[ATTR_BATTERY_LEVEL] = self.battery_level
                               ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/roomba/irobot_base.py", line 167, in battery_level
    return self._battery_level
           ^^^^^^^^^^^^^^^^^^^
AttributeError: 'RoombaVacuumCarpetBoost' object has no attribute '_battery_level'
2023-10-19 06:34:05.299 ERROR (MainThread) [homeassistant.components.vacuum] Error while setting up roomba platform for vacuum
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 367, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 786, in _async_generate_attributes
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/vacuum/__init__.py", line 281, in state_attributes
    data[ATTR_BATTERY_LEVEL] = self.battery_level
                               ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/roomba/irobot_base.py", line 167, in battery_level
    return self._battery_level
           ^^^^^^^^^^^^^^^^^^^
AttributeError: 'RoombaVacuumCarpetBoost' object has no attribute '_battery_level'

@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 October 19, 2023 16:36
@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

Oh


    @property
    def unique_id(self):
        """Return the uniqueid of the vacuum cleaner."""
        return self.robot_unique_id

The property is overwritten in the base class

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

and it looks like _battery_level needs to still be set

@joostlek
Copy link
Member Author

oh right, I made it public

@joostlek
Copy link
Member Author

Heh, I tested that other PR. That seamed to work. This one suddenly doesn't work.

@joostlek
Copy link
Member Author

ooooh, I know whats going on

@joostlek joostlek marked this pull request as ready for review October 19, 2023 17:22
@home-assistant home-assistant bot requested a review from bdraco October 19, 2023 17:22
@joostlek
Copy link
Member Author

Tested locally, works

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

Latest push looks good

Running to grab breakfast and errands and will test when I get back

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Tested 👍

Screenshot 2023-10-19 at 8 41 22 AM

@bdraco bdraco mentioned this pull request Oct 19, 2023
20 tasks
@Xitee1
Copy link
Contributor

Xitee1 commented Oct 19, 2023

I've also tested it. At least with german translation it's not working properly. It just says "Roomba" everywhere now with no way to differentiate between the mission sensors and it seems like the battery entity now is a new sensor with different entity id.

H7JwhLf58g
chrome_bVYfSaVAvA

@joostlek
Copy link
Member Author

You have to generate translations. python3 -m script.translations develop --all

If this is your production env

cd /config
curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d roomba -p 102323

@joostlek
Copy link
Member Author

joostlek commented Oct 19, 2023

I must say, I also had that problem with the battery, but I couldn't figure out why. I reinstalled the integration like twice and it did not show up twice anymore, so its strange

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

Let me try deleting it and re-adding it to see if I can replicate the battery issue

@Xitee1
Copy link
Contributor

Xitee1 commented Oct 19, 2023

You have to generate translations. python3 -m script.translations develop --all

If this is your production env

cd /config
curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d roomba -p 102323

Thanks, I didn't know that. Now the translations are working properly.

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

Here is what the battery looks like in the registry on dev

      {
        "aliases": [],
        "area_id": null,
        "capabilities": null,
        "config_entry_id": "3c4a5a71520c374a10a028b8bdec99c5",
        "device_class": null,
        "device_id": "86d1d524aa25c213f38d60995060a0e1",
        "disabled_by": null,
        "entity_category": "diagnostic",
        "entity_id": "sensor.89_upstairroomba_battery",
        "hidden_by": null,
        "icon": null,
        "id": "46afe441f77097e9eecfec5fcb49ce29",
        "has_entity_name": true,
        "name": null,
        "options": {
          "conversation": {
            "should_expose": false
          }
        },
        "original_device_class": "battery",
        "original_icon": null,
        "original_name": "Battery",
        "platform": "roomba",
        "supported_features": 0, 
        "translation_key": null,
        "unique_id": "battery_6BCDC6ED83A24782B24D53F0E2F1A1F1",
        "previous_unique_id": null,
        "unit_of_measurement": "%"
      },

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

Its the same with this PR.

I can't replicate the issue on a test env or on production.

I will update my other production instance now

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

production before this PR

Screenshot 2023-10-19 at 9 34 05 AM

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

after update its fine.
confirmed the unique id didn't change

Screenshot 2023-10-19 at 9 36 22 AM

@bdraco bdraco merged commit 063d74c into home-assistant:dev Oct 19, 2023
@joostlek joostlek deleted the roomba_main_sensor branch October 19, 2023 19:37
@joostlek
Copy link
Member Author

Yea I checked my registry and got 2 entities with the same unique id. So it was kinda strange

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

I'm going to clean up the typing a bit in #102350

@joostlek
Copy link
Member Author

I saw the PR, nice one

@bdraco
Copy link
Member

bdraco commented Oct 19, 2023

I've also tested it.

@Xitee1 If you plan on working on this integration long term, you should add yourself to codeowners https://github.com/home-assistant/architecture/blob/master/adr/0008-code-owners.md as we generally prioritize review for codeowners higher

@Xitee1
Copy link
Contributor

Xitee1 commented Oct 19, 2023

I've also tested it.

@Xitee1 If you plan on working on this integration long term, you should add yourself to codeowners https://github.com/home-assistant/architecture/blob/master/adr/0008-code-owners.md as we generally prioritize review for codeowners higher

Okay, I'll most likely do that.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2023
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:counter",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda self: self.battery_stats.get("nLithChrg")
Copy link
Member

Choose a reason for hiding this comment

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

Can we use parenthesis to add indentation so that the lambda is easier to read?

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.

4 participants