From c21f1d4a0c79e9bb2e302f458b6bb61d64045421 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Thu, 7 Nov 2024 21:19:14 +0100 Subject: [PATCH 1/5] Force int value on port --- homeassistant/components/p1_monitor/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/p1_monitor/coordinator.py b/homeassistant/components/p1_monitor/coordinator.py index 5459f88c38893c..28839867dd3abb 100644 --- a/homeassistant/components/p1_monitor/coordinator.py +++ b/homeassistant/components/p1_monitor/coordinator.py @@ -60,7 +60,7 @@ def __init__( self.p1monitor = P1Monitor( host=self.config_entry.data[CONF_HOST], - port=self.config_entry.data[CONF_PORT], + port=int(self.config_entry.data[CONF_PORT]), session=async_get_clientsession(hass), ) From e0d6b3e62dbb9962d6cd48f7970895fd5c7ce4ac Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Fri, 8 Nov 2024 08:54:01 +0100 Subject: [PATCH 2/5] Revert change --- homeassistant/components/p1_monitor/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/p1_monitor/coordinator.py b/homeassistant/components/p1_monitor/coordinator.py index 28839867dd3abb..5459f88c38893c 100644 --- a/homeassistant/components/p1_monitor/coordinator.py +++ b/homeassistant/components/p1_monitor/coordinator.py @@ -60,7 +60,7 @@ def __init__( self.p1monitor = P1Monitor( host=self.config_entry.data[CONF_HOST], - port=int(self.config_entry.data[CONF_PORT]), + port=self.config_entry.data[CONF_PORT], session=async_get_clientsession(hass), ) From c21dbee40761d8b6f1a8c596ecffcc67b07df8d8 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Fri, 8 Nov 2024 08:56:17 +0100 Subject: [PATCH 3/5] Force int on NumberSelector --- homeassistant/components/p1_monitor/config_flow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/p1_monitor/config_flow.py b/homeassistant/components/p1_monitor/config_flow.py index 055973e8e37c00..b95cf9e498faf6 100644 --- a/homeassistant/components/p1_monitor/config_flow.py +++ b/homeassistant/components/p1_monitor/config_flow.py @@ -59,6 +59,7 @@ async def async_step_user( vol.Required(CONF_HOST): TextSelector(), vol.Required(CONF_PORT, default=80): NumberSelector( NumberSelectorConfig( + as_int=True, mode=NumberSelectorMode.BOX, ) ), From cf7217dcd46692846204add5f3f2ea9ee5faaded Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Fri, 8 Nov 2024 09:06:13 +0100 Subject: [PATCH 4/5] Force int on numberSelector (current way) --- homeassistant/components/p1_monitor/config_flow.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/p1_monitor/config_flow.py b/homeassistant/components/p1_monitor/config_flow.py index b95cf9e498faf6..a7ede186d727ec 100644 --- a/homeassistant/components/p1_monitor/config_flow.py +++ b/homeassistant/components/p1_monitor/config_flow.py @@ -57,11 +57,13 @@ async def async_step_user( data_schema=vol.Schema( { vol.Required(CONF_HOST): TextSelector(), - vol.Required(CONF_PORT, default=80): NumberSelector( - NumberSelectorConfig( - as_int=True, - mode=NumberSelectorMode.BOX, - ) + vol.Required(CONF_PORT, default=80): vol.All( + NumberSelector( + NumberSelectorConfig( + min=1, max=65535, mode=NumberSelectorMode.BOX + ), + ), + vol.Coerce(int), ), } ), From 09f8ee256ae1f5de22f21ae45e8b372c1d04a98f Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Fri, 8 Nov 2024 10:07:16 +0100 Subject: [PATCH 5/5] Add type assertion for port in test_full_user_flow --- tests/components/p1_monitor/test_config_flow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/components/p1_monitor/test_config_flow.py b/tests/components/p1_monitor/test_config_flow.py index ea1d12055a0eee..cbd89320074a88 100644 --- a/tests/components/p1_monitor/test_config_flow.py +++ b/tests/components/p1_monitor/test_config_flow.py @@ -36,6 +36,7 @@ async def test_full_user_flow(hass: HomeAssistant) -> None: assert result2.get("type") is FlowResultType.CREATE_ENTRY assert result2.get("title") == "P1 Monitor" assert result2.get("data") == {CONF_HOST: "example.com", CONF_PORT: 80} + assert isinstance(result2["data"][CONF_PORT], int) assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_p1monitor.mock_calls) == 1