diff --git a/homeassistant/components/tankerkoenig/__init__.py b/homeassistant/components/tankerkoenig/__init__.py index 3f654f245228f1..b9a75b92bde558 100755 --- a/homeassistant/components/tankerkoenig/__init__.py +++ b/homeassistant/components/tankerkoenig/__init__.py @@ -27,16 +27,16 @@ DEFAULT_SCAN_INTERVAL = timedelta(minutes=30) -def uuid4_string(value): - """Validate a v4 UUID in string format.""" +def uuid_string(value): + """Validate a UUID in string format.""" try: - result = UUID(value, version=4) + result = UUID(value) except (ValueError, AttributeError, TypeError) as error: - raise vol.Invalid("Invalid Version4 UUID", error_message=str(error)) + raise vol.Invalid("Invalid UUID", error_message=str(error)) if str(result) != value.lower(): # UUID() will create a uuid4 if input is invalid - raise vol.Invalid("Invalid Version4 UUID") + raise vol.Invalid("Invalid UUID") return str(result) @@ -45,7 +45,7 @@ def uuid4_string(value): { DOMAIN: vol.Schema( { - vol.Required(CONF_API_KEY): uuid4_string, + vol.Required(CONF_API_KEY): uuid_string, vol.Optional( CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL ): cv.time_period, @@ -66,7 +66,7 @@ def uuid4_string(value): cv.positive_int, vol.Range(min=1) ), vol.Optional(CONF_STATIONS, default=[]): vol.All( - cv.ensure_list, [uuid4_string] + cv.ensure_list, [uuid_string] ), } ) diff --git a/tests/components/tankerkoenig/test_tankerkoenig_validators.py b/tests/components/tankerkoenig/test_tankerkoenig_validators.py index 7dba88b24fb30a..84fc16ba24e4a3 100755 --- a/tests/components/tankerkoenig/test_tankerkoenig_validators.py +++ b/tests/components/tankerkoenig/test_tankerkoenig_validators.py @@ -5,28 +5,20 @@ import pytest import voluptuous as vol -from homeassistant.components.tankerkoenig import uuid4_string +from homeassistant.components.tankerkoenig import uuid_string -class TestUUID4StringValidator(unittest.TestCase): - """Test the UUID4 string custom validator.""" +class TestUUIDStringValidator(unittest.TestCase): + """Test the UUID string custom validator.""" - def test_uuid4_string(caplog): + def test_uuid_string(caplog): """Test string uuid validation.""" - schema = vol.Schema(uuid4_string) + schema = vol.Schema(uuid_string) for value in ["Not a hex string", "0", 0]: with pytest.raises(vol.Invalid): schema(value) - with pytest.raises(vol.Invalid): - # the third block should start with 4 - schema("a03d31b2-2eee-2acc-bb90-eec40be6ed23") - - with pytest.raises(vol.Invalid): - # the fourth block should start with 8-a - schema("a03d31b2-2eee-4acc-1b90-eec40be6ed23") - - _str = str(uuid.uuid4()) + _str = str(uuid.uuid()) assert schema(_str) == _str assert schema(_str.upper()) == _str