Skip to content

Commit

Permalink
fix(config): allow users to remove configuration for alarm modes (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem authored Sep 8, 2023
1 parent 6249eba commit 3947e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions custom_components/econnect_alarm/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def parse_areas_config(config: str, raises: bool = False):
>>> parse_areas_config("3,a")
[]
"""
if config == "" or config is None:
# Empty config is considered valid (no sectors configured)
return []

try:
return [int(x) for x in config.split(",")]
except (ValueError, AttributeError):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def test_parse_areas_config_valid_input():
assert parse_areas_config("") == []


def test_parse_areas_config_valid_empty_input():
assert parse_areas_config("", raises=True) == []
assert parse_areas_config(None, raises=True) == []


def test_parse_areas_config_invalid_input():
assert parse_areas_config("3,a") == []
assert parse_areas_config("3.4") == []
Expand All @@ -24,10 +29,5 @@ def test_parse_areas_config_raises_value_error():
parse_areas_config("3.4", raises=True)


def test_parse_areas_config_raises_attribute_error():
with pytest.raises(InvalidAreas):
parse_areas_config(None, raises=True)


def test_parse_areas_config_whitespace():
assert parse_areas_config(" 3 , 4 ") == [3, 4]

0 comments on commit 3947e00

Please sign in to comment.