99from homeassistant import config_entries
1010from homeassistant .core import HomeAssistant
1111from homeassistant .config_entries import ConfigEntry
12- from homeassistant .const import CONF_HOST
1312from homeassistant .data_entry_flow import FlowResult
1413from homeassistant .helpers import config_validation as cv
1514from homeassistant .core import callback
1918 DOMAIN ,
2019 CONF_COMMUNITY ,
2120 CONF_PORTS ,
21+ CONF_HOST ,
2222 DEFAULT_PORTS ,
2323 DEFAULT_BASE_OIDS ,
2424 DEFAULT_SYSTEM_OIDS ,
25+ CONF_SNMP_PORT ,
26+ DEFAULT_SNMP_PORT ,
2527)
2628
2729_LOGGER = logging .getLogger (__name__ )
3133 {
3234 vol .Required (CONF_HOST ): str ,
3335 vol .Required (CONF_COMMUNITY , default = "public" ): str ,
36+ vol .Required (CONF_SNMP_PORT ,DEFAULT_SNMP_PORT ): vol .All (vol .Coerce (int ), vol .Range (min = 1 , max = 10000 )),
3437 }
3538)
3639
@@ -56,6 +59,7 @@ async def async_step_user(
5659 self .hass ,
5760 user_input [CONF_HOST ],
5861 user_input [CONF_COMMUNITY ],
62+ user_input [CONF_SNMP_PORT ],
5963 )
6064 except ConnectionError :
6165 errors ["base" ] = "cannot_connect"
@@ -102,12 +106,13 @@ async def async_step_user(
102106 errors = errors ,
103107 )
104108
105- async def _test_connection (self , hass : HomeAssistant , host : str , community : str ) -> None :
109+ async def _test_connection (self , hass : HomeAssistant , host : str , community : str , SNMP_port : int ) -> None :
106110 """SNMP connectivity test direct await, no executor nonsense."""
107111 await async_snmp_get (
108112 hass ,
109113 host ,
110114 community ,
115+ SNMP_port = 161 ,
111116 "1.3.6.1.2.1.1.5.0" , # sysName — more reliable than sysDescr
112117 timeout = 12 ,
113118 retries = 3 ,
0 commit comments