Homekit schema gracefully fail with integer (#12725)

* Homekit schema gracefully fail with integer
* Fix return value
* Added test
* Fix 2
pull/12730/head
Johann Kellerman 2018-02-27 02:09:49 +02:00 committed by cdce8p
parent 446390a8d1
commit 4821858afb
2 changed files with 5 additions and 5 deletions

View File

@ -19,7 +19,7 @@ from homeassistant.util.decorator import Registry
TYPES = Registry()
_LOGGER = logging.getLogger(__name__)
_RE_VALID_PINCODE = re.compile(r"^(\d{3}-\d{2}-\d{3})$")
_RE_VALID_PINCODE = r"^(\d{3}-\d{2}-\d{3})$"
DOMAIN = 'homekit'
REQUIREMENTS = ['HAP-python==1.1.7']
@ -32,10 +32,10 @@ HOMEKIT_FILE = '.homekit.state'
def valid_pin(value):
"""Validate pin code value."""
match = _RE_VALID_PINCODE.findall(value.strip())
if match == []:
match = re.match(_RE_VALID_PINCODE, str(value).strip())
if not match:
raise vol.Invalid("Pin must be in the format: '123-45-678'")
return match[0]
return match.group(0)
CONFIG_SCHEMA = vol.Schema({

View File

@ -73,7 +73,7 @@ class TestHomeKit(unittest.TestCase):
"""Test async_setup with invalid config option."""
schema = vol.Schema(valid_pin)
for value in ('', '123-456-78', 'a23-45-678', '12345678'):
for value in ('', '123-456-78', 'a23-45-678', '12345678', 1234):
with self.assertRaises(vol.MultipleInvalid):
schema(value)