2626from ..exception import ExecutionError
2727
2828
29- def _get_hostname_and_password (url : str ) -> tuple [str , str ]:
29+ def _get_hostname_port_and_password (url : str ) -> tuple [str , int , str ]:
3030 """Obtain credentials from url or default and return hostname and password.
3131
3232 If no password is in the URL return "P4ssword", which fulfills the minimal requirements from Netgear:
@@ -35,20 +35,23 @@ def _get_hostname_and_password(url: str) -> tuple[str, str]:
3535 - at least one lower case character
3636 - at least one number
3737
38+ If no port is in the URL, return 80.
39+
3840 Args:
3941 url: A URL with an optional basic auth prefix.
4042
4143 Returns:
42- A tuple of the hostname, and the extracted or default password
44+ A tuple of the hostname, port and the extracted or default password
4345
4446 """
4547 parse_result = urlparse (url )
4648 if parse_result .scheme != "http" :
4749 raise ExecutionError (f"URL must start with http://, found { parse_result .scheme } for { url } ." )
4850
49- password = "P4ssword" if parse_result .password is None else parse_result .password
51+ password = parse_result .password or "P4ssword"
52+ port = parse_result .port or 80
5053
51- return parse_result .hostname , password
54+ return parse_result .hostname , port , password
5255
5356
5457def power_set (host : str , _port : int , index : int , value : bool ) -> None :
@@ -64,9 +67,11 @@ def power_set(host: str, _port: int, index: int, value: bool) -> None:
6467 index = int (index )
6568 netgear_port_number = index + 1
6669
67- (hostname , password ) = _get_hostname_and_password (host )
70+ (hostname , port , password ) = _get_hostname_port_and_password (host )
71+
72+ network_address = f"{ hostname } :{ port } "
6873
69- sw = NetgearSwitchConnector (hostname , password )
74+ sw = NetgearSwitchConnector (network_address , password )
7075 sw .autodetect_model ()
7176 try :
7277 sw .get_login_cookie ()
@@ -97,9 +102,10 @@ def power_get(host: str, _port: int, index: int) -> bool:
97102 index = int (index )
98103 netgear_port_number = index + 1
99104
100- (hostname , password ) = _get_hostname_and_password (host )
105+ (hostname , port , password ) = _get_hostname_port_and_password (host )
106+ network_address = f"{ hostname } :{ port } "
101107
102- sw = NetgearSwitchConnector (hostname , password )
108+ sw = NetgearSwitchConnector (network_address , password )
103109 sw .autodetect_model ()
104110 try :
105111 sw .get_login_cookie ()
0 commit comments