Skip to content

Commit

Permalink
Add updating took longer error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 12, 2024
1 parent 533f357 commit 930060a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions custom_components/hass_diagnostics/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def extra_state_attributes(self):

RE_CUSTOM_DOMAIN = re.compile(r"\bcustom_components[/.]([0-9a-z_]+)")
RE_DOMAIN = re.compile(r"\bcomponents[/.]([0-9a-z_]+)")
RE_CONNECTION = re.compile(r"(disconnected|not available)", flags=re.IGNORECASE)
RE_DEPRECATED = re.compile(r"will stop working in Home Assistant.+?[0-9.]+")
RE_SETUP = re.compile(r"Setup of (.+?) is taking over")
RE_SETUP = re.compile(r"^Setup of ([^ ]+) is taking over")
RE_UPDATING = re.compile(r"^Updating ([^ ]+) [^ ]+ took longer than")
# RE_ERROR = re.compile(r"\('(.+?)'\)")
RE_PACKAGE = re.compile(r"/site-packages/([^/]+)")
RE_TEMPLATE = re.compile(r"Template<template=\((.+?)\) renders=", flags=re.DOTALL)
Expand Down Expand Up @@ -129,6 +129,9 @@ def parse_log_record(record: logging.LogRecord) -> dict:
elif m := RE_SETUP.search(message):
entry["category"] = "performance"
entry["domain"] = m[1]
elif m := RE_UPDATING.search(message):
entry["category"] = "performance"
entry["domain"] = m[1]
elif m := RE_TEMPLATE.search(message):
entry["category"] = "template"
short = m[1]
Expand Down
21 changes: 21 additions & 0 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ def test_is_taking_over():
"name": "homeassistant.setup",
"short": "Setup of dataplicity is taking over 10 seconds.",
}


def test_took_longer():
entry = {
"name": "homeassistant.components.media_player",
"message": [
"Updating samsungtv media_player took longer than the scheduled update interval 0:00:10"
],
"level": "WARNING",
"source": ["helpers/entity_platform.py", 1010],
"timestamp": 1712901964.4957683,
"exception": "",
"count": 2,
"first_occurred": 1712901954.4951386,
}
assert parse_log_entry(entry) == {
"category": "performance",
"domain": "samsungtv",
"name": "homeassistant.components.media_player",
"short": "Updating samsungtv media_player took longer than the schedu...",
}

0 comments on commit 930060a

Please sign in to comment.