bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
971 stars 258 forks source link

Adding my autodectected TP-Link HS300 results in exception #2421

Closed dtyler closed 2 months ago

dtyler commented 2 months ago

System Health details

System Information

version core-2024.7.3
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.1.71-haos
arch aarch64
timezone America/New_York
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4989 Installed Version | 1.34.0 Stage | running Available Repositories | 1384 Downloaded Repositories | 12
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 11.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.06.2 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 28.0 GB disk_used | 16.1 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | green supervisor_api | ok version_api | ok installed_addons | Matter Server (6.2.1), InfluxDB (5.0.0), Grafana (10.0.0), Grocy (0.21.0), Mosquitto broker (6.4.1), Studio Code Server (5.15.0), Advanced SSH & Web Terminal (18.0.0), Z-Wave JS UI (3.8.6), Silicon Labs Multiprotocol (2.4.5), rtl_433 (0.5.2), ESPHome (2024.7.0), Music Assistant Server (2.1.0), Home Assistant Google Drive Backup (0.112.1), OpenThread Border Router (2.9.0), Silicon Labs Flasher (0.2.3), Netdata (1.46.3)
Dashboards dashboards | 7 -- | -- resources | 6 views | 7 mode | storage
Recorder oldest_recorder_run | July 19, 2024 at 7:41 PM -- | -- current_recorder_run | July 27, 2024 at 5:58 AM estimated_db_size | 599.94 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

A recent update resulting in several "new device" notifications (one for each plug in my tp-link HS300 powerstrip). When trying to configure them, the UI reported "Unknown Error". Looking at the full log I see this stack trace:

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421
First occurred: July 27, 2024 at 3:52:22 PM (4 occurrences)
Last logged: 10:55:29 AM

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 210, 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/powercalc/config_flow.py", line 987, in async_step_library
    return await self.async_step_post_library(user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/config_flow.py", line 1096, in async_step_post_library
    if self.power_profile and self.power_profile.needs_fixed_config:
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/power_profile.py", line 156, in needs_fixed_config
    return self.is_strategy_supported(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/power_profile.py", line 149, in is_strategy_supported
    return mode == self.calculation_strategy
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/power_profile.py", line 106, in calculation_strategy
    return CalculationStrategy(str(self._json_data.get("calculation_strategy")))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/enum.py", line 757, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/enum.py", line 1171, in __new__
    raise ve_exc
ValueError: 'multi_switch' is not a valid CalculationStrategy

Reproduction steps

  1. Have a tp-link HS300 setup in HA
  2. Install powercalc 1.13.4
  3. See "New Device" device notification
  4. Try to click Configure on one of these new Devices on the Devices page
  5. Encounter error

Debug logs

https://gist.github.com/dtyler/128bb004b7fd673be174762459cad52d

Diagnostics dump or YAML config

No response

bramstroker commented 2 months ago

Ah I see, This profile has already been submitted to the library at https://powercalc.lauwbier.nl, but uses a new strategy which was released in Powercalc yet. It's only in v1.14.0-beta.0. See #2404

So you'll need to upgrade to latest beta of wait for stable v1.14.0 release.

I'll add something in the code for future version of Powercalc to prevent issues with scenarios like this. Where profile is submitted to library but code needed to execute it probably not available yet.

imhotep commented 2 months ago

@bramstroker I am getting the same error. I tried v1.14.0-beta.0 but I am still getting the same error (and stack) :/

bramstroker commented 2 months ago

@imhotep That's strange. I just released v1.14.0. Could you try another time? Make sure to restart after upgrading. Please also check in the logs if you are getting exactly the same error as when you created the issue.

When another error, please share the details.

imhotep commented 2 months ago

@bramstroker I am no longer facing the issue with that version. Thank you!