From 5a20b35171e900cabc1c95e6e0673726e00c5281 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 13 Jan 2020 11:42:56 +0100 Subject: [PATCH] Report what data is available when ModelInfo contains unexpected types It seems that the data can cointain strings (see issue #62). Let's dump what data we have available to be able to debug this. --- tests/test_client.py | 15 ++++++++++++++- wideq/client.py | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 21b8836..cba3972 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -67,6 +67,10 @@ DATA = { 'type': 'Bit' }, 'Unexpected': {'type': 'Unexpected'}, + 'String': { + 'type': 'String', + 'option': 'some string' + }, }, 'Course': { "3": { @@ -117,6 +121,15 @@ class ModelInfoTest(unittest.TestCase): self.assertEqual(expected, actual) def test_value_unsupported(self): + data = "{'type': 'Unexpected'}" with self.assertRaisesRegex( - ValueError, 'unsupported value type Unexpected'): + ValueError, + f"unsupported value type 'Unexpected' data: '{data}'"): self.model_info.value('Unexpected') + + def test_value_unsupported_but_data_available(self): + data = "{'type': 'String', 'option': 'some string}'" + with self.assertRaises( + ValueError, + msg=f"unsupported value type 'String' data: '{data}"): + self.model_info.value('String') diff --git a/wideq/client.py b/wideq/client.py index 31e43d0..3f267ea 100644 --- a/wideq/client.py +++ b/wideq/client.py @@ -340,7 +340,8 @@ class ModelInfo(object): ref = d['option'][0] return ReferenceValue(self.data[ref]) else: - raise ValueError("unsupported value type {}".format(d['type'])) + raise ValueError( + f"unsupported value type '{str(d['type'])}' data: '{str(d)}'") def default(self, name): """Get the default value, if it exists, for a given value.