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

Migrate geniushub to has entity name #126986

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

joostlek
Copy link
Member

Proposed change

Migrate geniushub to has entity name. This will add devices and allows the issue sensor names to be translated

@GeoffAtHome can you maybe test this PR and the other PR I opened today?

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

To help with the load of incoming pull requests:

@home-assistant
Copy link

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

Code owner commands

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

Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Nov 27, 2024
@manzanotti
Copy link
Contributor

@joostlek Any idea what the missing test warning is about? It looks like you are testing that line, though I can't be sure.

@github-actions github-actions bot removed the stale label Nov 27, 2024
@joostlek
Copy link
Member Author

At what line is it complaining?

Also @zxdavb, maybe you can also help out with testing

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

So, I am accessing someone else's system via access token (v1 API).

geniushub:
  token: !secret genius_token
  mac: 00:1a:22:0a:0b:0c

First issue:

2024-11-28 17:58:16.339 ERROR (MainThread) [homeassistant.setup]
 The 'geniushub' integration does not support YAML setup, please remove it from your configuration

This is despite the docs saying I can still use yaml: https://www.home-assistant.io/integrations/geniushub/

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

So, configuring via UI, we get...

Second issue:

2024-11-28 18:05:26.400 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up geniushub platform for sensor
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 366, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/sensor.py", line 37, in async_setup_entry
    GeniusBattery(broker, d, GH_STATE_ATTR)
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/sensor.py", line 54, in __init__
    super().__init__(broker, device)
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/entity.py", line 62, in __init__
    if device_name[:21] == "Dual Channel Receiver":
       ~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

... and then:

2024-11-28 18:05:26.423 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up geniushub platform for binary_sensor
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 374, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 641, in async_add_entities
    for entity in new_entities:
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/binary_sensor.py", line 28, in <genexpr>
    if GH_TYPE in d.data["type"]
                  ~~~~~~^^^^^^^^
KeyError: 'type'

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

... and then some log warnings that may be caused by me merging back the latest dev branch:

2024-11-28 18:05:26.458 WARNING (MainThread) [homeassistant.helpers.frame] Detected that integration 'geniushub' calls `device_registry.async_get_or_create` referencing a non existing `via_device` ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA'), with device info: {'identifiers': {('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA_3')}, 'name': 'Upstairs Landing', 'suggested_area': 'Upstairs Landing', 'via_device': ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA')} at homeassistant/components/geniushub/climate.py, line 38: async_add_entities(. This will stop working in Home Assistant 2025.12.0, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+geniushub%22

... and:

2024-11-28 18:05:26.514 WARNING (MainThread) [homeassistant.helpers.frame] Detected that integration 'geniushub' calls `device_registry.async_get_or_create` referencing a non existing `via_device` ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA'), with device info: {'identifiers': {('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA_11')}, 'name': 'Plugs', 'suggested_area': 'Plugs', 'via_device': ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA')} at homeassistant/components/geniushub/switch.py, line 40: async_add_entities(. This will stop working in Home Assistant 2025.12.0, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+geniushub%22

... and:

2024-11-28 18:05:26.531 WARNING (MainThread) [homeassistant.helpers.frame] Detected that integration 'geniushub' calls `device_registry.async_get_or_create` referencing a non existing `via_device` ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA'), with device info: {'identifiers': {('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA_1')}, 'name': 'Boiler Hot Water', 'suggested_area': 'Boiler Hot Water', 'via_device': ('geniushub', '01JDSZ5ZQ0XDVXAHFSXW9PNRSA')} at homeassistant/components/geniushub/water_heater.py, line 45: async_add_entities(. This will stop working in Home Assistant 2025.12.0, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+geniushub%22

... Finally:

2024-11-28 18:05:31.654 WARNING (SyncWorker_18) [py.warnings] /home/dbonnes/clients/hass/venv/lib/python3.12/site-packages/yaml/resolver.py:143: RuntimeWarning: coroutine 'EntityPlatform._async_add_entity' was never awaited
Coroutine created at (most recent call last)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_component.py", line 197, in async_setup_entry
    return await self._platforms[key].async_setup_entry(config_entry)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 333, in async_setup_entry
    return await self._async_setup_platform(async_create_setup_awaitable)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 363, in _async_setup_platform
    awaitable = create_eager_task(awaitable, loop=hass.loop)
  File "/home/dbonnes/clients/hass/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/binary_sensor.py", line 25, in async_setup_entry
    async_add_entities(
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 523, in _async_schedule_add_entities_for_entry
    task = self.config_entry.async_create_task(
  File "/home/dbonnes/clients/hass/homeassistant/config_entries.py", line 1150, in async_create_task
    task = hass.async_create_task_internal(
  File "/home/dbonnes/clients/hass/homeassistant/core.py", line 832, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/home/dbonnes/clients/hass/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 643, in async_add_entities
    self._async_add_entity(entity, update_before_add, entity_registry)
  def resolve(self, kind, value, implicit):
  ```

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

Let me know if I can help more.

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

Any idea what the missing test warning is about? It looks like you are testing that line, though I can't be sure.

Was complain that a new line of code wasn't covered by the tests - I think you can ignore this for now.

@joostlek
Copy link
Member Author

Oh lol, I forgot the docs for this one. Good catch: home-assistant/home-assistant.io#36048

@joostlek
Copy link
Member Author

Okay wait, does the integration work on dev?

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

Okay wait, does the integration work on dev?

This is what I did:

> git fetch upstream pull/126986/head:genius_has_name
> git checkout genius_has_name
> git fetch --all
> git merge upstream/dev
> script/setup
> source venv/bin/activate.fish
> hass -c ~/clients/hass_config

Is that the answer to your question? Or do you want me to test on the dev branch?

Gimme sec...

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

OK, on dev, I'm getting:

2024-11-28 19:39:27.367 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up geniushub platform for binary_sensor
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 374, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 641, in async_add_entities
    for entity in new_entities:
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/binary_sensor.py", line 28, in <genexpr>
    if GH_TYPE in d.data["type"]
                  ~~~~~~^^^^^^^^
KeyError: 'type'

... and:

2024-11-28 19:39:27.389 WARNING (MainThread) [py.warnings] /home/dbonnes/clients/hass/homeassistant/helpers/event.py:491: RuntimeWarning: coroutine 'EntityPlatform._async_add_entity' was never awaited
Coroutine created at (most recent call last)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_component.py", line 197, in async_setup_entry
    return await self._platforms[key].async_setup_entry(config_entry)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 333, in async_setup_entry
    return await self._async_setup_platform(async_create_setup_awaitable)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 363, in _async_setup_platform
    awaitable = create_eager_task(awaitable, loop=hass.loop)
  File "/home/dbonnes/clients/hass/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/home/dbonnes/clients/hass/homeassistant/components/geniushub/binary_sensor.py", line 25, in async_setup_entry
    async_add_entities(
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 523, in _async_schedule_add_entities_for_entry
    task = self.config_entry.async_create_task(
  File "/home/dbonnes/clients/hass/homeassistant/config_entries.py", line 1150, in async_create_task
    task = hass.async_create_task_internal(
  File "/home/dbonnes/clients/hass/homeassistant/core.py", line 832, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/home/dbonnes/clients/hass/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 643, in async_add_entities
    self._async_add_entity(entity, update_before_add, entity_registry)
  return partial(_remove_listener, hass, tracker, keys, job, callbacks)

@zxdavb
Copy link
Contributor

zxdavb commented Nov 28, 2024

For teh first:

    if GH_TYPE in d.data["type"]

KeyError: 'type'

I wonder if this is because development of client library has been progressing against device's v3 API (via LAN) and hasn't been tested against v1 API (using token via vendor's webserver).

The latter:

... coroutine 'EntityPlatform._async_add_entity' was never awaited

is a bit odd... Oh: just a consequence of the first error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants