mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Catch an extra error that could break util.convert
This commit is contained in:
parent
c3bb6d32aa
commit
7c6dcdb082
@ -57,7 +57,7 @@ def convert(value, to_type, default=None):
|
||||
""" Converts value to to_type, returns default if fails. """
|
||||
try:
|
||||
return default if value is None else to_type(value)
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
# If value could not be converted
|
||||
return default
|
||||
|
||||
|
@ -53,6 +53,7 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual(True, util.convert("True", bool))
|
||||
self.assertEqual(1, util.convert("NOT A NUMBER", int, 1))
|
||||
self.assertEqual(1, util.convert(None, int, 1))
|
||||
self.assertEqual(1, util.convert(object, int, 1))
|
||||
|
||||
def test_ensure_unique_string(self):
|
||||
""" Test ensure_unique_string. """
|
||||
|
Loading…
x
Reference in New Issue
Block a user