Skip to content

Commit

Permalink
Collapse valid state check when creating a state (#93655)
Browse files Browse the repository at this point in the history
Inline valid state check when creating a state

This was added in #9696 and only used in one place so
it does not need to be another function
  • Loading branch information
bdraco committed May 27, 2023
1 parent 560e744 commit c721cbd
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ def valid_entity_id(entity_id: str) -> bool:
return VALID_ENTITY_ID.match(entity_id) is not None


def valid_state(state: str) -> bool:
"""Test if a state is valid."""
return len(state) <= MAX_LENGTH_STATE_STATE


def callback(func: _CallableT) -> _CallableT:
"""Annotation to mark method as safe to call from within the event loop."""
setattr(func, "_hass_callback", True)
Expand Down Expand Up @@ -1256,7 +1251,7 @@ def __init__(
"Format should be <domain>.<object_id>"
)

if not valid_state(state):
if len(state) > MAX_LENGTH_STATE_STATE:
raise InvalidStateError(
f"Invalid state encountered for entity ID: {entity_id}. "
"State max length is 255 characters."
Expand Down

0 comments on commit c721cbd

Please sign in to comment.