diff --git a/supervisor/addons/options.py b/supervisor/addons/options.py index 1c7e4d737..46309c015 100644 --- a/supervisor/addons/options.py +++ b/supervisor/addons/options.py @@ -37,8 +37,8 @@ RE_SCHEMA_ELEMENT = re.compile( r"|device(?:\((?Psubsystem=[a-z]+)\))?" r"|str(?:\((?P\d+)?,(?P\d+)?\))?" r"|password(?:\((?P\d+)?,(?P\d+)?\))?" - r"|int(?:\((?P\d+)?,(?P\d+)?\))?" - r"|float(?:\((?P[\d\.]+)?,(?P[\d\.]+)?\))?" + r"|int(?:\((?P-?\d+)?,(?P-?\d+)?\))?" + r"|float(?:\((?P-?\d*\.?\d+)?,(?P-?\d*\.?\d+)?\))?" r"|match\((?P.*)\)" r"|list\((?P.+)\)" r")\??$" diff --git a/tests/addons/test_options.py b/tests/addons/test_options.py index 72e2d7a54..aa70a00b5 100644 --- a/tests/addons/test_options.py +++ b/tests/addons/test_options.py @@ -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(