From 03aff0d6625c40ca8eb3c079c803c18aa21b17d8 Mon Sep 17 00:00:00 2001
From: Simone Chemelli <simone.chemelli@gmail.com>
Date: Sun, 9 Mar 2025 13:07:20 +0100
Subject: [PATCH] Use CONF_* const in Shelly tests (#140189)

---
 tests/components/shelly/__init__.py         |   4 +-
 tests/components/shelly/test_config_flow.py | 237 ++++++++++++--------
 tests/components/shelly/test_coordinator.py |   4 +-
 tests/components/shelly/test_init.py        |  18 +-
 4 files changed, 163 insertions(+), 100 deletions(-)

diff --git a/tests/components/shelly/__init__.py b/tests/components/shelly/__init__.py
index 5cba8e5e3b8..ddece280d8a 100644
--- a/tests/components/shelly/__init__.py
+++ b/tests/components/shelly/__init__.py
@@ -18,7 +18,7 @@ from homeassistant.components.shelly.const import (
     RPC_SENSORS_POLLING_INTERVAL,
 )
 from homeassistant.config_entries import ConfigEntry
-from homeassistant.const import CONF_HOST
+from homeassistant.const import CONF_HOST, CONF_MODEL
 from homeassistant.core import HomeAssistant
 from homeassistant.helpers import entity_registry as er
 from homeassistant.helpers.device_registry import (
@@ -47,7 +47,7 @@ async def init_integration(
         data = {
             CONF_HOST: "192.168.1.37",
             CONF_SLEEP_PERIOD: sleep_period,
-            "model": model,
+            CONF_MODEL: model,
         }
     if gen is not None:
         data[CONF_GEN] = gen
diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py
index 50b8b552268..0b2d355cfd8 100644
--- a/tests/components/shelly/test_config_flow.py
+++ b/tests/components/shelly/test_config_flow.py
@@ -18,10 +18,19 @@ from homeassistant import config_entries
 from homeassistant.components.shelly import MacAddressMismatchError, config_flow
 from homeassistant.components.shelly.const import (
     CONF_BLE_SCANNER_MODE,
+    CONF_GEN,
+    CONF_SLEEP_PERIOD,
     DOMAIN,
     BLEScannerMode,
 )
 from homeassistant.components.shelly.coordinator import ENTRY_RELOAD_COOLDOWN
+from homeassistant.const import (
+    CONF_HOST,
+    CONF_MODEL,
+    CONF_PASSWORD,
+    CONF_PORT,
+    CONF_USERNAME,
+)
 from homeassistant.core import HomeAssistant
 from homeassistant.data_entry_flow import FlowResultType
 from homeassistant.helpers.service_info.zeroconf import (
@@ -100,18 +109,18 @@ async def test_form(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1", "port": port},
+            {CONF_HOST: "1.1.1.1", CONF_PORT: port},
         )
         await hass.async_block_till_done()
 
     assert result2["type"] is FlowResultType.CREATE_ENTRY
     assert result2["title"] == "Test name"
     assert result2["data"] == {
-        "host": "1.1.1.1",
-        "port": port,
-        "model": model,
-        "sleep_period": 0,
-        "gen": gen,
+        CONF_HOST: "1.1.1.1",
+        CONF_PORT: port,
+        CONF_MODEL: model,
+        CONF_SLEEP_PERIOD: 0,
+        CONF_GEN: gen,
     }
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
@@ -163,18 +172,18 @@ async def test_user_flow_overrides_existing_discovery(
         assert result["errors"] == {}
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1", "port": 80},
+            {CONF_HOST: "1.1.1.1", CONF_PORT: 80},
         )
         await hass.async_block_till_done()
 
     assert result2["type"] is FlowResultType.CREATE_ENTRY
     assert result2["title"] == "Test name"
     assert result2["data"] == {
-        "host": "1.1.1.1",
-        "port": 80,
-        "model": MODEL_PLUS_2PM,
-        "sleep_period": 0,
-        "gen": 2,
+        CONF_HOST: "1.1.1.1",
+        CONF_PORT: 80,
+        CONF_MODEL: MODEL_PLUS_2PM,
+        CONF_SLEEP_PERIOD: 0,
+        CONF_GEN: 2,
     }
     assert result2["context"]["unique_id"] == "AABBCCDDEEFF"
     assert len(mock_setup.mock_calls) == 1
@@ -220,19 +229,19 @@ async def test_form_gen1_custom_port(
         (
             1,
             MODEL_1,
-            {"username": "test user", "password": "test1 password"},
+            {CONF_USERNAME: "test user", CONF_PASSWORD: "test1 password"},
             "test user",
         ),
         (
             2,
             MODEL_PLUS_2PM,
-            {"password": "test2 password"},
+            {CONF_PASSWORD: "test2 password"},
             "admin",
         ),
         (
             3,
             MODEL_PLUS_2PM,
-            {"password": "test2 password"},
+            {CONF_PASSWORD: "test2 password"},
             "admin",
         ),
     ],
@@ -259,7 +268,7 @@ async def test_form_auth(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     assert result2["type"] is FlowResultType.FORM
@@ -282,13 +291,13 @@ async def test_form_auth(
     assert result3["type"] is FlowResultType.CREATE_ENTRY
     assert result3["title"] == "Test name"
     assert result3["data"] == {
-        "host": "1.1.1.1",
-        "port": DEFAULT_HTTP_PORT,
-        "model": model,
-        "sleep_period": 0,
-        "gen": gen,
-        "username": username,
-        "password": user_input["password"],
+        CONF_HOST: "1.1.1.1",
+        CONF_PORT: DEFAULT_HTTP_PORT,
+        CONF_MODEL: model,
+        CONF_SLEEP_PERIOD: 0,
+        CONF_GEN: gen,
+        CONF_USERNAME: username,
+        CONF_PASSWORD: user_input[CONF_PASSWORD],
     }
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
@@ -312,7 +321,7 @@ async def test_form_errors_get_info(
     with patch("homeassistant.components.shelly.config_flow.get_info", side_effect=exc):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     assert result2["type"] is FlowResultType.FORM
@@ -333,7 +342,7 @@ async def test_form_missing_model_key(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     assert result2["type"] is FlowResultType.FORM
@@ -356,7 +365,7 @@ async def test_form_missing_model_key_auth_enabled(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     assert result2["type"] is FlowResultType.FORM
@@ -364,7 +373,7 @@ async def test_form_missing_model_key_auth_enabled(
 
     monkeypatch.setattr(mock_rpc_device, "shelly", {"gen": 2})
     result3 = await hass.config_entries.flow.async_configure(
-        result2["flow_id"], {"password": "1234"}
+        result2["flow_id"], {CONF_PASSWORD: "1234"}
     )
     assert result3["type"] is FlowResultType.FORM
     assert result3["errors"] == {"base": "firmware_not_fully_provisioned"}
@@ -424,7 +433,7 @@ async def test_form_errors_test_connection(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     assert result2["type"] is FlowResultType.FORM
@@ -435,7 +444,7 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
     """Test we get the form."""
 
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0"}
+        domain="shelly", unique_id="test-mac", data={CONF_HOST: "0.0.0.0"}
     )
     entry.add_to_hass(hass)
 
@@ -449,14 +458,14 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
         assert result2["type"] is FlowResultType.ABORT
         assert result2["reason"] == "already_configured"
 
     # Test config entry got updated with latest IP
-    assert entry.data["host"] == "1.1.1.1"
+    assert entry.data[CONF_HOST] == "1.1.1.1"
 
 
 async def test_user_setup_ignored_device(
@@ -467,7 +476,7 @@ async def test_user_setup_ignored_device(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="test-mac",
-        data={"host": "0.0.0.0"},
+        data={CONF_HOST: "0.0.0.0"},
         source=config_entries.SOURCE_IGNORE,
     )
     entry.add_to_hass(hass)
@@ -491,13 +500,13 @@ async def test_user_setup_ignored_device(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
         assert result2["type"] is FlowResultType.CREATE_ENTRY
 
     # Test config entry got updated with latest IP
-    assert entry.data["host"] == "1.1.1.1"
+    assert entry.data[CONF_HOST] == "1.1.1.1"
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
 
@@ -525,7 +534,7 @@ async def test_form_auth_errors_test_connection_gen1(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     with patch(
@@ -534,7 +543,7 @@ async def test_form_auth_errors_test_connection_gen1(
     ):
         result3 = await hass.config_entries.flow.async_configure(
             result2["flow_id"],
-            {"username": "test username", "password": "test password"},
+            {CONF_USERNAME: "test username", CONF_PASSWORD: "test password"},
         )
     assert result3["type"] is FlowResultType.FORM
     assert result3["errors"] == {"base": base_error}
@@ -563,7 +572,7 @@ async def test_form_auth_errors_test_connection_gen2(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
 
     with patch(
@@ -571,7 +580,7 @@ async def test_form_auth_errors_test_connection_gen2(
         new=AsyncMock(side_effect=exc),
     ):
         result3 = await hass.config_entries.flow.async_configure(
-            result2["flow_id"], {"password": "test password"}
+            result2["flow_id"], {CONF_PASSWORD: "test password"}
         )
     assert result3["type"] is FlowResultType.FORM
     assert result3["errors"] == {"base": base_error}
@@ -642,10 +651,10 @@ async def test_zeroconf(
     assert result2["type"] is FlowResultType.CREATE_ENTRY
     assert result2["title"] == "Test name"
     assert result2["data"] == {
-        "host": "1.1.1.1",
-        "model": model,
-        "sleep_period": 0,
-        "gen": gen,
+        CONF_HOST: "1.1.1.1",
+        CONF_MODEL: model,
+        CONF_SLEEP_PERIOD: 0,
+        CONF_GEN: gen,
     }
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
@@ -700,10 +709,10 @@ async def test_zeroconf_sleeping_device(
     assert result2["type"] is FlowResultType.CREATE_ENTRY
     assert result2["title"] == "Test name"
     assert result2["data"] == {
-        "host": "1.1.1.1",
-        "model": MODEL_1,
-        "sleep_period": 600,
-        "gen": 1,
+        CONF_HOST: "1.1.1.1",
+        CONF_MODEL: MODEL_1,
+        CONF_SLEEP_PERIOD: 600,
+        CONF_GEN: 1,
     }
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
@@ -739,7 +748,7 @@ async def test_zeroconf_already_configured(hass: HomeAssistant) -> None:
     """Test we get the form."""
 
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0"}
+        domain="shelly", unique_id="test-mac", data={CONF_HOST: "0.0.0.0"}
     )
     entry.add_to_hass(hass)
 
@@ -756,7 +765,7 @@ async def test_zeroconf_already_configured(hass: HomeAssistant) -> None:
         assert result["reason"] == "already_configured"
 
     # Test config entry got updated with latest IP
-    assert entry.data["host"] == "1.1.1.1"
+    assert entry.data[CONF_HOST] == "1.1.1.1"
 
 
 async def test_zeroconf_ignored(hass: HomeAssistant) -> None:
@@ -787,7 +796,7 @@ async def test_zeroconf_with_wifi_ap_ip(hass: HomeAssistant) -> None:
     """Test we ignore the Wi-FI AP IP."""
 
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "2.2.2.2"}
+        domain="shelly", unique_id="test-mac", data={CONF_HOST: "2.2.2.2"}
     )
     entry.add_to_hass(hass)
 
@@ -806,7 +815,7 @@ async def test_zeroconf_with_wifi_ap_ip(hass: HomeAssistant) -> None:
         assert result["reason"] == "already_configured"
 
     # Test config entry was not updated with the wifi ap ip
-    assert entry.data["host"] == "2.2.2.2"
+    assert entry.data[CONF_HOST] == "2.2.2.2"
 
 
 async def test_zeroconf_cannot_connect(hass: HomeAssistant) -> None:
@@ -852,20 +861,20 @@ async def test_zeroconf_require_auth(
     ):
         result2 = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"username": "test username", "password": "test password"},
+            {CONF_USERNAME: "test username", CONF_PASSWORD: "test password"},
         )
         await hass.async_block_till_done()
 
     assert result2["type"] is FlowResultType.CREATE_ENTRY
     assert result2["title"] == "Test name"
     assert result2["data"] == {
-        "host": "1.1.1.1",
-        "port": DEFAULT_HTTP_PORT,
-        "model": MODEL_1,
-        "sleep_period": 0,
-        "gen": 1,
-        "username": "test username",
-        "password": "test password",
+        CONF_HOST: "1.1.1.1",
+        CONF_PORT: DEFAULT_HTTP_PORT,
+        CONF_MODEL: MODEL_1,
+        CONF_SLEEP_PERIOD: 0,
+        CONF_GEN: 1,
+        CONF_USERNAME: "test username",
+        CONF_PASSWORD: "test password",
     }
     assert len(mock_setup.mock_calls) == 1
     assert len(mock_setup_entry.mock_calls) == 1
@@ -874,9 +883,9 @@ async def test_zeroconf_require_auth(
 @pytest.mark.parametrize(
     ("gen", "user_input"),
     [
-        (1, {"username": "test user", "password": "test1 password"}),
-        (2, {"password": "test2 password"}),
-        (3, {"password": "test2 password"}),
+        (1, {CONF_USERNAME: "test user", CONF_PASSWORD: "test1 password"}),
+        (2, {CONF_PASSWORD: "test2 password"}),
+        (3, {CONF_PASSWORD: "test2 password"}),
     ],
 )
 async def test_reauth_successful(
@@ -888,7 +897,9 @@ async def test_reauth_successful(
 ) -> None:
     """Test starting a reauthentication flow."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": gen}
+        domain="shelly",
+        unique_id="test-mac",
+        data={CONF_HOST: "0.0.0.0", CONF_GEN: gen},
     )
     entry.add_to_hass(hass)
     result = await entry.start_reauth_flow(hass)
@@ -912,9 +923,9 @@ async def test_reauth_successful(
 @pytest.mark.parametrize(
     ("gen", "user_input"),
     [
-        (1, {"username": "test user", "password": "test1 password"}),
-        (2, {"password": "test2 password"}),
-        (3, {"password": "test2 password"}),
+        (1, {CONF_USERNAME: "test user", CONF_PASSWORD: "test1 password"}),
+        (2, {CONF_PASSWORD: "test2 password"}),
+        (3, {CONF_PASSWORD: "test2 password"}),
     ],
 )
 @pytest.mark.parametrize(
@@ -933,7 +944,9 @@ async def test_reauth_unsuccessful(
 ) -> None:
     """Test reauthentication flow failed."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": gen}
+        domain="shelly",
+        unique_id="test-mac",
+        data={CONF_HOST: "0.0.0.0", CONF_GEN: gen},
     )
     entry.add_to_hass(hass)
     result = await entry.start_reauth_flow(hass)
@@ -943,7 +956,12 @@ async def test_reauth_unsuccessful(
     with (
         patch(
             "homeassistant.components.shelly.config_flow.get_info",
-            return_value={"mac": "test-mac", "type": MODEL_1, "auth": True, "gen": gen},
+            return_value={
+                "mac": "test-mac",
+                "type": MODEL_1,
+                "auth": True,
+                "gen": gen,
+            },
         ),
         patch(
             "aioshelly.block_device.BlockDevice.create", new=AsyncMock(side_effect=exc)
@@ -962,7 +980,7 @@ async def test_reauth_unsuccessful(
 async def test_reauth_get_info_error(hass: HomeAssistant) -> None:
     """Test reauthentication flow failed with error in get_info()."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": 2}
+        domain="shelly", unique_id="test-mac", data={CONF_HOST: "0.0.0.0", CONF_GEN: 2}
     )
     entry.add_to_hass(hass)
     result = await entry.start_reauth_flow(hass)
@@ -975,7 +993,7 @@ async def test_reauth_get_info_error(hass: HomeAssistant) -> None:
     ):
         result = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            user_input={"password": "test2 password"},
+            user_input={CONF_PASSWORD: "test2 password"},
         )
 
         assert result["type"] is FlowResultType.ABORT
@@ -1106,7 +1124,12 @@ async def test_zeroconf_already_configured_triggers_refresh_mac_in_name(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 0, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 0,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1141,7 +1164,12 @@ async def test_zeroconf_already_configured_triggers_refresh(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 0, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 0,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1181,7 +1209,12 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 1000, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 1000,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1228,7 +1261,12 @@ async def test_zeroconf_sleeping_device_attempts_configure(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 1000, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 1000,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1288,7 +1326,12 @@ async def test_zeroconf_sleeping_device_attempts_configure_ws_disabled(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 1000, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 1000,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1348,7 +1391,12 @@ async def test_zeroconf_sleeping_device_attempts_configure_no_url_available(
     entry = MockConfigEntry(
         domain="shelly",
         unique_id="AABBCCDDEEFF",
-        data={"host": "1.1.1.1", "gen": 2, "sleep_period": 1000, "model": MODEL_1},
+        data={
+            CONF_HOST: "1.1.1.1",
+            CONF_GEN: 2,
+            CONF_SLEEP_PERIOD: 1000,
+            CONF_MODEL: MODEL_1,
+        },
     )
     entry.add_to_hass(hass)
     await hass.config_entries.async_setup(entry.entry_id)
@@ -1415,20 +1463,20 @@ async def test_sleeping_device_gen2_with_new_firmware(
     ):
         result = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            {"host": "1.1.1.1"},
+            {CONF_HOST: "1.1.1.1"},
         )
         await hass.async_block_till_done()
 
     assert result["data"] == {
-        "host": "1.1.1.1",
-        "port": DEFAULT_HTTP_PORT,
-        "model": MODEL_PLUS_2PM,
-        "sleep_period": 666,
-        "gen": 2,
+        CONF_HOST: "1.1.1.1",
+        CONF_PORT: DEFAULT_HTTP_PORT,
+        CONF_MODEL: MODEL_PLUS_2PM,
+        CONF_SLEEP_PERIOD: 666,
+        CONF_GEN: 2,
     }
 
 
-@pytest.mark.parametrize("gen", [1, 2, 3])
+@pytest.mark.parametrize(CONF_GEN, [1, 2, 3])
 async def test_reconfigure_successful(
     hass: HomeAssistant,
     gen: int,
@@ -1437,7 +1485,9 @@ async def test_reconfigure_successful(
 ) -> None:
     """Test starting a reconfiguration flow."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": gen}
+        domain="shelly",
+        unique_id="test-mac",
+        data={CONF_HOST: "0.0.0.0", CONF_GEN: gen},
     )
     entry.add_to_hass(hass)
 
@@ -1452,12 +1502,12 @@ async def test_reconfigure_successful(
     ):
         result = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            user_input={"host": "10.10.10.10", "port": 99},
+            user_input={CONF_HOST: "10.10.10.10", CONF_PORT: 99},
         )
 
     assert result["type"] is FlowResultType.ABORT
     assert result["reason"] == "reconfigure_successful"
-    assert entry.data == {"host": "10.10.10.10", "port": 99, "gen": gen}
+    assert entry.data == {CONF_HOST: "10.10.10.10", CONF_PORT: 99, CONF_GEN: gen}
 
 
 @pytest.mark.parametrize("gen", [1, 2, 3])
@@ -1469,7 +1519,9 @@ async def test_reconfigure_unsuccessful(
 ) -> None:
     """Test reconfiguration flow failed."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": gen}
+        domain="shelly",
+        unique_id="test-mac",
+        data={CONF_HOST: "0.0.0.0", CONF_GEN: gen},
     )
     entry.add_to_hass(hass)
 
@@ -1480,11 +1532,16 @@ async def test_reconfigure_unsuccessful(
 
     with patch(
         "homeassistant.components.shelly.config_flow.get_info",
-        return_value={"mac": "another-mac", "type": MODEL_1, "auth": False, "gen": gen},
+        return_value={
+            "mac": "another-mac",
+            "type": MODEL_1,
+            "auth": False,
+            "gen": gen,
+        },
     ):
         result = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            user_input={"host": "10.10.10.10", "port": 99},
+            user_input={CONF_HOST: "10.10.10.10", CONF_PORT: 99},
         )
 
     assert result["type"] is FlowResultType.ABORT
@@ -1506,7 +1563,7 @@ async def test_reconfigure_with_exception(
 ) -> None:
     """Test reconfiguration flow when an exception is raised."""
     entry = MockConfigEntry(
-        domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": 2}
+        domain="shelly", unique_id="test-mac", data={CONF_HOST: "0.0.0.0", CONF_GEN: 2}
     )
     entry.add_to_hass(hass)
 
@@ -1518,7 +1575,7 @@ async def test_reconfigure_with_exception(
     with patch("homeassistant.components.shelly.config_flow.get_info", side_effect=exc):
         result = await hass.config_entries.flow.async_configure(
             result["flow_id"],
-            user_input={"host": "10.10.10.10", "port": 99},
+            user_input={CONF_HOST: "10.10.10.10", CONF_PORT: 99},
         )
 
     assert result["errors"] == {"base": base_error}
diff --git a/tests/components/shelly/test_coordinator.py b/tests/components/shelly/test_coordinator.py
index 8de434d19d0..55a1d8958cd 100644
--- a/tests/components/shelly/test_coordinator.py
+++ b/tests/components/shelly/test_coordinator.py
@@ -562,7 +562,7 @@ async def test_rpc_update_entry_sleep_period(
     mock_rpc_device.mock_online()
     await hass.async_block_till_done(wait_background_tasks=True)
 
-    assert entry.data["sleep_period"] == 600
+    assert entry.data[CONF_SLEEP_PERIOD] == 600
 
     # Move time to generate sleep period update
     monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 3600)
@@ -570,7 +570,7 @@ async def test_rpc_update_entry_sleep_period(
     async_fire_time_changed(hass)
     await hass.async_block_till_done(wait_background_tasks=True)
 
-    assert entry.data["sleep_period"] == 3600
+    assert entry.data[CONF_SLEEP_PERIOD] == 3600
 
 
 async def test_rpc_sleeping_device_no_periodic_updates(
diff --git a/tests/components/shelly/test_init.py b/tests/components/shelly/test_init.py
index c9e4ce253e4..ef9b8f72616 100644
--- a/tests/components/shelly/test_init.py
+++ b/tests/components/shelly/test_init.py
@@ -25,7 +25,13 @@ from homeassistant.components.shelly.const import (
     BLEScannerMode,
 )
 from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
-from homeassistant.const import CONF_HOST, CONF_PORT, STATE_ON, STATE_UNAVAILABLE
+from homeassistant.const import (
+    CONF_HOST,
+    CONF_MODEL,
+    CONF_PORT,
+    STATE_ON,
+    STATE_UNAVAILABLE,
+)
 from homeassistant.core import HomeAssistant
 from homeassistant.helpers import issue_registry as ir
 from homeassistant.helpers.device_registry import DeviceRegistry, format_mac
@@ -245,7 +251,7 @@ async def test_sleeping_block_device_online(
     await hass.async_block_till_done(wait_background_tasks=True)
 
     assert "online, resuming setup" in caplog.text
-    assert entry.data["sleep_period"] == device_sleep
+    assert entry.data[CONF_SLEEP_PERIOD] == device_sleep
 
 
 @pytest.mark.parametrize(("entry_sleep", "device_sleep"), [(None, 0), (1000, 1000)])
@@ -267,7 +273,7 @@ async def test_sleeping_rpc_device_online(
     await hass.async_block_till_done(wait_background_tasks=True)
 
     assert "online, resuming setup" in caplog.text
-    assert entry.data["sleep_period"] == device_sleep
+    assert entry.data[CONF_SLEEP_PERIOD] == device_sleep
 
 
 async def test_sleeping_rpc_device_online_new_firmware(
@@ -286,7 +292,7 @@ async def test_sleeping_rpc_device_online_new_firmware(
     await hass.async_block_till_done(wait_background_tasks=True)
 
     assert "online, resuming setup" in caplog.text
-    assert entry.data["sleep_period"] == 1500
+    assert entry.data[CONF_SLEEP_PERIOD] == 1500
 
 
 async def test_sleeping_rpc_device_online_during_setup(
@@ -474,7 +480,7 @@ async def test_entry_missing_port(hass: HomeAssistant) -> None:
     data = {
         CONF_HOST: "192.168.1.37",
         CONF_SLEEP_PERIOD: 0,
-        "model": MODEL_PLUS_2PM,
+        CONF_MODEL: MODEL_PLUS_2PM,
         CONF_GEN: 2,
     }
     entry = await init_integration(hass, 2, data=data, skip_setup=True)
@@ -497,7 +503,7 @@ async def test_rpc_entry_custom_port(hass: HomeAssistant) -> None:
     data = {
         CONF_HOST: "192.168.1.37",
         CONF_SLEEP_PERIOD: 0,
-        "model": MODEL_PLUS_2PM,
+        CONF_MODEL: MODEL_PLUS_2PM,
         CONF_GEN: 2,
         CONF_PORT: 8001,
     }
-- 
GitLab