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

Fix emulated_hue with None values #104020

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Fix emulated_hue with None values #104020

merged 2 commits into from
Nov 15, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Nov 15, 2023

Proposed change

regressed from #101946

fixes #104013
likely fixes #103538 (but nobody in that issue provided logs)

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:

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
bdraco J. Nick Koston
regressed from #101946

fixes #104013
likely fixes #103538 (but nobody in that issue provided logs)
@home-assistant
Copy link

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

Code owner commands

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

@bdraco
Copy link
Member Author

bdraco commented Nov 15, 2023

test fails on dev with

-------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/view.py", line 151, in handle
    result = handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 329, in get
    json_response = state_to_json(self.config, state)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 761, in state_to_json
    state_dict = get_entity_state_dict(config, state)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 655, in get_entity_state_dict
    return _build_entity_state_dict(entity)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 687, in _build_entity_state_dict
    data[STATE_BRIGHTNESS] = hass_to_hue_brightness(
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 890, in hass_to_hue_brightness
    return max(1, round((value / 255) * HUE_API_STATE_BRI_MAX))
                         ~~~~~~^~~~~
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
INFO:aiohttp.access:127.0.0.1 [15/Nov/2023:07:43:37 +0000] "GET /api/username/lights/1 HTTP/1.1" 500 3309 "-" "Python/3.11 aiohttp/3.8.5"
---------------------------------------------------------------------- Captured log call ----------------------------------------------------------------------
2023-11-15 01:43:37.643 ERROR    MainThread aiohttp.server:web_protocol.py:403 Error handling request
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/view.py", line 151, in handle
    result = handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 329, in get
    json_response = state_to_json(self.config, state)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 761, in state_to_json
    state_dict = get_entity_state_dict(config, state)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 655, in get_entity_state_dict
    return _build_entity_state_dict(entity)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 687, in _build_entity_state_dict
    data[STATE_BRIGHTNESS] = hass_to_hue_brightness(
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/emulated_hue/hue_api.py", line 890, in hass_to_hue_brightness
    return max(1, round((value / 255) * HUE_API_STATE_BRI_MAX))
                         ~~~~~~^~~~~
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
2023-11-15 01:43:37.644 INFO     MainThread aiohttp.access:web_log.py:206 127.0.0.1 [15/Nov/2023:07:43:37 +0000] "GET /api/username/lights/1 HTTP/1.1" 500 3309 "-" "Python/3.11 aiohttp/3.8.5"

 tests/components/emulated_hue/test_hue_api.py ⨯             

passes with this PR

Verified

This commit was signed with the committer’s verified signature.
bdraco J. Nick Koston
regressed from #101946

fixes #104013
likely fixes #103538 (but nobody in that issue provided logs)
@bdraco bdraco marked this pull request as ready for review November 15, 2023 07:49
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.

Thanks, @bdraco 👍

../Frenck

@frenck frenck merged commit 7803ca2 into dev Nov 15, 2023
@frenck frenck deleted the emu_hue_fix branch November 15, 2023 09:27
@bdraco
Copy link
Member Author

bdraco commented Nov 15, 2023

Thanks

@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants