1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-04-02 00:07:16 +01:00

Add support for negative numbers in apps options (#6673)

* Added support for negative numbers in options

* Do not allow -. as float

* Added tests for integers and floats in options.

* Fixed ruff errors

* Added tests for outside of int/float limits
This commit is contained in:
sepahewe
2026-03-30 12:08:57 +02:00
committed by GitHub
parent ef71ffb32b
commit 98bbb8869e
2 changed files with 61 additions and 2 deletions

View File

@@ -37,8 +37,8 @@ RE_SCHEMA_ELEMENT = re.compile(
r"|device(?:\((?P<filter>subsystem=[a-z]+)\))?"
r"|str(?:\((?P<s_min>\d+)?,(?P<s_max>\d+)?\))?"
r"|password(?:\((?P<p_min>\d+)?,(?P<p_max>\d+)?\))?"
r"|int(?:\((?P<i_min>\d+)?,(?P<i_max>\d+)?\))?"
r"|float(?:\((?P<f_min>[\d\.]+)?,(?P<f_max>[\d\.]+)?\))?"
r"|int(?:\((?P<i_min>-?\d+)?,(?P<i_max>-?\d+)?\))?"
r"|float(?:\((?P<f_min>-?\d*\.?\d+)?,(?P<f_max>-?\d*\.?\d+)?\))?"
r"|match\((?P<match>.*)\)"
r"|list\((?P<list>.+)\)"
r")\??$"

View File

@@ -45,6 +45,65 @@ def test_simple_schema(coresys):
)({"name": "Pascal", "fires": True})
def test_simple_schema_integers(coresys):
"""Test integer limits."""
assert AddonOptions(
coresys,
{"name": "str", "password": "password", "pos": "int(0,10)", "neg": "int(-5,0)"},
MOCK_ADDON_NAME,
MOCK_ADDON_SLUG,
)({"name": "Pascal", "password": "1234", "pos": 5, "neg": "-4"})
with pytest.raises(vol.error.Invalid):
assert AddonOptions(
coresys,
{
"name": "str",
"password": "password",
"pos": "int(0,10)",
"neg": "int(-5,0)",
},
MOCK_ADDON_NAME,
MOCK_ADDON_SLUG,
)({"name": "Pascal", "password": "1234", "pos": 11, "neg": "-6"})
def test_simple_schema_floats(coresys):
"""Test float limits."""
assert AddonOptions(
coresys,
{
"name": "str",
"password": "password",
"pos": "float(0.0,10.5)",
"neg": "float(-5.0,-.5)",
},
MOCK_ADDON_NAME,
MOCK_ADDON_SLUG,
)({"name": "Pascal", "password": "1234", "pos": 5.0, "neg": "-4.0"})
with pytest.raises(vol.error.Invalid):
assert AddonOptions(
coresys,
{
"name": "str",
"password": "password",
"pos": "float(0.0,10.5)",
"neg": "float(-5.0,-.5)",
},
MOCK_ADDON_NAME,
MOCK_ADDON_SLUG,
)({"name": "Pascal", "password": "1234", "pos": 11.0, "neg": "-6.0"})
with pytest.raises(vol.error.Invalid):
assert AddonOptions(
coresys,
{"name": "str", "password": "password", "float": "float(-1.0,-.)"},
MOCK_ADDON_NAME,
MOCK_ADDON_SLUG,
)({"name": "Pascal", "password": "1234", "float": "0.0"})
def test_complex_schema_list(coresys):
"""Test with complex list schema."""
assert AddonOptions(