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

Statistics graph with % unit #86877

Closed
luca-angemi opened this issue Jan 29, 2023 · 8 comments
Closed

Statistics graph with % unit #86877

luca-angemi opened this issue Jan 29, 2023 · 8 comments

Comments

@luca-angemi
Copy link
Contributor

The problem

I'm not sure if this is a Core or Frontend issue.

In case of a Statistics graph card with unit '%' the graph is not shown and the following error is reported in the logs (sensor from the systemmonitor component).

2023-01-29 07:54:41.788 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1853049608] Error handling message: extra keys not allowed @ data['units']['unitless']. Got '%' (invalid_format) from xx.xx.xx.xx (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36)

What version of Home Assistant Core has the issue?

2023.2.0b4

What was the last working version of Home Assistant Core?

2023.1

What type of installation are you running?

Home Assistant OS

Integration causing the issue

websocket_api

Link to integration documentation on our website

https://www.home-assistant.io/integrations/websocket_api/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (websocket_api) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of websocket_api can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign websocket_api Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


websocket_api documentation
websocket_api source
(message by IssueLinks)

@lancer73
Copy link

lancer73 commented Feb 1, 2023

Can confirm this. All statistics graphs with % as the unit are broken.

2023-02-01 23:40:32.222 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281473155856416] Error handling message: extra keys not allowed @ data['units']['unitless']. Got '%' (invalid_format) from 192.168.14.97 (Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Home Assistant/2023.2 (io.robbie.HomeAssistant; build:2023.443; iOS 16.3.0) Mobile/HomeAssistant, like Safari)
Happens since update to 2023.2.0

@vqvu
Copy link

vqvu commented Feb 2, 2023

Here are the relevant WS request/response from my browser.

get_statistics_metadata

{
  "type": "recorder/get_statistics_metadata",
  "statistic_ids": ["sensor.humidity"],
  "id": 35
}
{
  "id": 35,
  "type": "result",
  "success": true,
  "result": [
    {
      "statistic_id": "sensor.humidity",
      "display_unit_of_measurement": "%",
      "has_mean": true,
      "has_sum": false,
      "name": null,
      "source": "recorder",
      "statistics_unit_of_measurement": "%",
      "unit_class": "unitless"
    }
  ]
}

statistics_during_period

{
  "type": "recorder/statistics_during_period",
  "start_time": "2023-01-03T04:21:32.623Z",
  "statistic_ids": ["sensor.humidity"],
  "period": "hour",
  "units": { "unitless": "%" },
  "types": ["state", "sum", "min", "max", "mean"],
  "id": 37
}
{
  "id": 37,
  "type": "result",
  "success": false,
  "error": {
    "code": "invalid_format",
    "message": "extra keys not allowed @ data['units']['unitless']. Got '%'"
  }
}

So the recorder integration is claiming that there is a unit_class named unitless but the WS request validator does not agree. Looks like the unitless unit_class was added in #85694. Pinging @emontnemery who was the author of that PR.

As a side note, the fact that the request schema for the unit is hard-coded like this seems incredibly brittle. IMO, the schema should be inferred from STATISTIC_UNIT_TO_UNIT_CONVERTER or a related constant or this issue will inevitably re-occur the next time a new unit class is added. Or at least there should be a test that verifies that they are consistent with each other.

@alefab
Copy link

alefab commented Feb 2, 2023

Home Assistant 2023.2.0 has been released with this issue. More people will certainly complains about that one now.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:104
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 09:58:48 (4 occurrences)
Last logged: 10:03:39

[139770275744448] Error handling message: extra keys not allowed @ data['units']['unitless']. Got '%' (invalid_format) from a.b.c.d (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36)

@erik3rik
Copy link

erik3rik commented Feb 2, 2023

Same here. All statistics graphs with % (e.g. humidity, processor usage, disk usage, etc.) is now completely broken and causes spamming of the error log. They were working perfect before the 2023.2.0-release.

@7floor
Copy link

7floor commented Feb 2, 2023

Confirming same issue @2023.2 release

@DeimicUser
Copy link

DeimicUser commented Feb 2, 2023

Confirm same issue after 2023.2 release....

@balloob
Copy link
Member

balloob commented Feb 2, 2023

Fixes in #87202

@balloob balloob closed this as completed Feb 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants