andrew-codechimp / HA-Battery-Notes

A Home Assistant integration to provide battery notes of devices
MIT License
491 stars 87 forks source link

Adding to entity results in "Unknown error occurred" message #1840

Closed BlaM closed 2 months ago

BlaM commented 2 months ago

System Health details

System Information

version core-2024.7.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.31-haos-raspi
arch aarch64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1389 Downloaded Repositories | 60
Airly can_reach_server | ok -- | -- requests_remaining | 42 requests_per_day | 100
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | December 20, 2024 at 1:00 AM relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | true google_enabled | true remote_server | eu-central-1-15.ui.nabu.casa certificate_status | ready instance_id | fcb44a216d85445a946cf653bd2aa6ab can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.06.2 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 234.0 GB disk_used | 127.7 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | Advanced SSH & Web Terminal (18.0.0), Studio Code Server (5.15.0), Node-RED (18.0.4), MariaDB (2.7.1), InfluxDB (5.0.0), ESPHome (2024.6.6), Grafana (10.0.0), Zigbee2MQTT (1.39.0-1), Matter Server (6.2.1)
Dashboards dashboards | 9 -- | -- resources | 33 views | 29 mode | storage
Recorder oldest_recorder_run | November 25, 2023 at 1:55 PM -- | -- current_recorder_run | July 11, 2024 at 2:31 PM estimated_db_size | 9762.33 MiB database_engine | mysql database_version | 10.11.6

Checklist

Describe the issue

I'm trying to add battery notes to an entity that does not have a device (a plant. sensor that is set up through configuration.yaml).

When I press the "NEXT" button on the setup wizard where I selected the entity I get an "Unknown error occured" message and the corresponding http request contains this:

500 Internal Server Error

Server got itself in trouble

image

Reproduction steps

  1. In config.yaml have something like this:

    plant:
    flower1:
      sensors:
        moisture: sensor.bluetooth_gateway_2_xiaomi_miflora_baa3_moisture
        temperature: sensor.bluetooth_gateway_2_xiaomi_miflora_baa3_temperature
  2. On the Devices page add an integration "Battery Notes"

  3. Select "Entity"

  4. Choose the new plant entity plant.flower1

  5. Press NEXT

  6. See Error

Debug logs

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421
First occurred: 4:46:38 PM (8 occurrences)
Last logged: 4:55:12 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 415, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 518, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/battery_notes/config_flow.py", line 229, in async_step_entity
    if entity_entry.device_id:
       ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'device_id'

Diagnostics dump

I

andrew-codechimp commented 2 months ago

Thanks for raising this and providing so much detail.

Battery notes can only be added to entities that are created via the UI, config.yaml entities do not have enough detail for battery notes to create the associated entities unfortunately.

I'll update with nicer handling of this error but unfortunately you won't be able to add battery notes to these entities.

BlaM commented 2 months ago

I kind of thought that it might be something like that - just the error message was not very helpful 👍