Skip to content

Commit 8926961

Browse files
authored
Update config_flow.py
1 parent 766eede commit 8926961

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

custom_components/switch_port_card_pro/config_flow.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from homeassistant import config_entries
1010
from homeassistant.core import HomeAssistant
1111
from homeassistant.config_entries import ConfigEntry
12-
from homeassistant.const import CONF_HOST
1312
from homeassistant.data_entry_flow import FlowResult
1413
from homeassistant.helpers import config_validation as cv
1514
from homeassistant.core import callback
@@ -19,9 +18,12 @@
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__)
@@ -31,6 +33,7 @@
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

Comments
 (0)