Remove unreachable code in logbook (#103309)
This commit is contained in:
parent
22306bd309
commit
8b30a901dd
2 changed files with 23 additions and 9 deletions
|
@ -42,9 +42,6 @@ class LazyEventPartialState:
|
||||||
"event_type",
|
"event_type",
|
||||||
"entity_id",
|
"entity_id",
|
||||||
"state",
|
"state",
|
||||||
"context_id_bin",
|
|
||||||
"context_user_id_bin",
|
|
||||||
"context_parent_id_bin",
|
|
||||||
"data",
|
"data",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -60,9 +57,6 @@ class LazyEventPartialState:
|
||||||
self.event_type: str | None = self.row.event_type
|
self.event_type: str | None = self.row.event_type
|
||||||
self.entity_id: str | None = self.row.entity_id
|
self.entity_id: str | None = self.row.entity_id
|
||||||
self.state = self.row.state
|
self.state = self.row.state
|
||||||
self.context_id_bin: bytes | None = self.row.context_id_bin
|
|
||||||
self.context_user_id_bin: bytes | None = self.row.context_user_id_bin
|
|
||||||
self.context_parent_id_bin: bytes | None = self.row.context_parent_id_bin
|
|
||||||
# We need to explicitly check for the row is EventAsRow as the unhappy path
|
# We need to explicitly check for the row is EventAsRow as the unhappy path
|
||||||
# to fetch row.data for Row is very expensive
|
# to fetch row.data for Row is very expensive
|
||||||
if type(row) is EventAsRow: # noqa: E721
|
if type(row) is EventAsRow: # noqa: E721
|
||||||
|
@ -83,17 +77,17 @@ class LazyEventPartialState:
|
||||||
@property
|
@property
|
||||||
def context_id(self) -> str | None:
|
def context_id(self) -> str | None:
|
||||||
"""Return the context id."""
|
"""Return the context id."""
|
||||||
return bytes_to_ulid_or_none(self.context_id_bin)
|
return bytes_to_ulid_or_none(self.row.context_id_bin)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def context_user_id(self) -> str | None:
|
def context_user_id(self) -> str | None:
|
||||||
"""Return the context user id."""
|
"""Return the context user id."""
|
||||||
return bytes_to_uuid_hex_or_none(self.context_user_id_bin)
|
return bytes_to_uuid_hex_or_none(self.row.context_user_id_bin)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def context_parent_id(self) -> str | None:
|
def context_parent_id(self) -> str | None:
|
||||||
"""Return the context parent id."""
|
"""Return the context parent id."""
|
||||||
return bytes_to_ulid_or_none(self.context_parent_id_bin)
|
return bytes_to_ulid_or_none(self.row.context_parent_id_bin)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True, frozen=True)
|
@dataclass(slots=True, frozen=True)
|
||||||
|
|
20
tests/components/logbook/test_models.py
Normal file
20
tests/components/logbook/test_models.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
"""The tests for the logbook component models."""
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
from homeassistant.components.logbook.models import LazyEventPartialState
|
||||||
|
|
||||||
|
|
||||||
|
def test_lazy_event_partial_state_context():
|
||||||
|
"""Test we can extract context from a lazy event partial state."""
|
||||||
|
state = LazyEventPartialState(
|
||||||
|
Mock(
|
||||||
|
context_id_bin=b"1234123412341234",
|
||||||
|
context_user_id_bin=b"1234123412341234",
|
||||||
|
context_parent_id_bin=b"4444444444444444",
|
||||||
|
event_data={},
|
||||||
|
),
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
assert state.context_id == "1H68SK8C9J6CT32CHK6GRK4CSM"
|
||||||
|
assert state.context_user_id == "31323334313233343132333431323334"
|
||||||
|
assert state.context_parent_id == "1M6GT38D1M6GT38D1M6GT38D1M"
|
Loading…
Add table
Add a link
Reference in a new issue