Explorar o código

Fix config loading tests.

Some of the tests were not really testing the component themselves, the error raised will have been because no entity was configured rather than an entity not in the config.
Jason Rumney %!s(int64=4) %!d(string=hai) anos
pai
achega
1792aefdaa

+ 10 - 2
tests/test_binary_sensor.py

@@ -41,7 +41,11 @@ async def test_init_entry_fails_if_device_has_no_binary_sensor(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "mirabella_genio_usb", CONF_DEVICE_ID: "dummy"},
+        data={
+            CONF_TYPE: "mirabella_genio_usb",
+            CONF_DEVICE_ID: "dummy",
+            "binary_sensor": True,
+        },
     )
     m_add_entities = Mock()
     m_device = AsyncMock()
@@ -61,7 +65,11 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={
+            CONF_TYPE: "non_existing",
+            CONF_DEVICE_ID: "dummy",
+            "binary_sensor": True,
+        },
     )
     m_add_entities = Mock()
     m_device = AsyncMock()

+ 2 - 2
tests/test_cover.py

@@ -38,7 +38,7 @@ async def test_init_entry_fails_if_device_has_no_cover(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy", "cover": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()
@@ -60,7 +60,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", "cover": True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use

+ 2 - 2
tests/test_fan.py

@@ -62,7 +62,7 @@ async def test_init_entry_fails_if_device_has_no_fan(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy", CONF_FAN: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use
@@ -85,7 +85,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", CONF_FAN: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use

+ 10 - 2
tests/test_humidifier.py

@@ -41,7 +41,11 @@ async def test_init_entry_fails_if_device_has_no_humidifier(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy"},
+        data={
+            CONF_TYPE: "kogan_heater",
+            CONF_DEVICE_ID: "dummy",
+            CONF_HUMIDIFIER: True,
+        },
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use
@@ -64,7 +68,11 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={
+            CONF_TYPE: "non_existing",
+            CONF_DEVICE_ID: "dummy",
+            CONF_HUMIDIFIER: True,
+        },
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use

+ 2 - 2
tests/test_light.py

@@ -41,7 +41,7 @@ async def test_init_entry_fails_if_device_has_no_light(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_switch", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "kogan_switch", CONF_DEVICE_ID: "dummy", CONF_LIGHT: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use
@@ -64,7 +64,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", CONF_LIGHT: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use

+ 2 - 2
tests/test_lock.py

@@ -41,7 +41,7 @@ async def test_init_entry_fails_if_device_has_no_lock(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_switch", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "kogan_switch", CONF_DEVICE_ID: "dummy", CONF_LOCK: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use
@@ -64,7 +64,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", CONF_LOCK: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use

+ 2 - 2
tests/test_number.py

@@ -38,7 +38,7 @@ async def test_init_entry_fails_if_device_has_no_number(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "simple_switch", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "simple_switch", CONF_DEVICE_ID: "dummy", "number": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()
@@ -58,7 +58,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", "number": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()

+ 2 - 2
tests/test_select.py

@@ -38,7 +38,7 @@ async def test_init_entry_fails_if_device_has_no_select(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "simple_switch", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "simple_switch", CONF_DEVICE_ID: "dummy", "select": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()
@@ -58,7 +58,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", "select": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()

+ 6 - 2
tests/test_sensor.py

@@ -42,7 +42,11 @@ async def test_init_entry_fails_if_device_has_no_sensor(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "mirabella_genio_usb", CONF_DEVICE_ID: "dummy"},
+        data={
+            CONF_TYPE: "mirabella_genio_usb",
+            CONF_DEVICE_ID: "dummy",
+            "sensor": True,
+        },
     )
     m_add_entities = Mock()
     m_device = AsyncMock()
@@ -62,7 +66,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", "sensor": True},
     )
     m_add_entities = Mock()
     m_device = AsyncMock()

+ 2 - 2
tests/test_switch.py

@@ -58,7 +58,7 @@ async def test_init_entry_fails_if_device_has_no_switch(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "kogan_heater", CONF_DEVICE_ID: "dummy", CONF_SWITCH: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use
@@ -81,7 +81,7 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     """Test initialisation when device has no matching entity"""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy"},
+        data={CONF_TYPE: "non_existing", CONF_DEVICE_ID: "dummy", CONF_SWITCH: True},
     )
     # although async, the async_add_entities function passed to
     # async_setup_entry is called truly asynchronously. If we use