@@ -31,15 +31,18 @@ class Fritzhome(object):
3131 _templates : Optional [Dict [str , FritzhomeTemplate ]] = None
3232 _triggers : Optional [Dict [str , FritzhomeTrigger ]] = None
3333
34- def __init__ (self , host , user , password , ssl_verify = True ):
34+ def __init__ (self , host , user , password , port = None , ssl_verify = True ):
3535 """Create a fritzhome object."""
36- self ._host = host
3736 self ._user = user
3837 self ._password = password
3938 self ._session = Session ()
4039 self ._ssl_verify = ssl_verify
4140 self ._has_getdeviceinfos = True
4241 self ._has_txbusy = True
42+ if host .startswith ("https://" ) or host .startswith ("http://" ):
43+ self .base_url = f"{ host } :{ port } " if port else host
44+ else :
45+ self .base_url = f"http://{ host } :{ port } " if port else f"http://{ host } "
4346
4447 def _request (self , url , params = None , timeout = 10 ):
4548 """Send a request with parameters."""
@@ -51,7 +54,7 @@ def _request(self, url, params=None, timeout=10):
5154
5255 def _login_request (self , username = None , secret = None ):
5356 """Send a login request with paramerters."""
54- url = self .get_prefixed_host () + " /login_sid.lua?version=2"
57+ url = f" { self .base_url } /login_sid.lua?version=2"
5558 params = {}
5659 if username :
5760 params ["username" ] = username
@@ -69,7 +72,7 @@ def _login_request(self, username=None, secret=None):
6972 def _logout_request (self ):
7073 """Send a logout request."""
7174 _LOGGER .debug ("logout" )
72- url = self .get_prefixed_host () + " /login_sid.lua"
75+ url = f" { self .base_url } /login_sid.lua"
7376 params = {"security:command/logout" : "1" , "sid" : self ._sid }
7477
7578 self ._request (url , params )
@@ -105,7 +108,7 @@ def _create_login_secret_md5(challenge, password):
105108
106109 def _aha_request (self , cmd , ain = None , param = None , rf = str ):
107110 """Send an AHA request."""
108- url = self .get_prefixed_host () + " /webservices/homeautoswitch.lua"
111+ url = f" { self .base_url } /webservices/homeautoswitch.lua"
109112
110113 _LOGGER .debug ("self._sid:%s" , self ._sid )
111114
@@ -152,20 +155,6 @@ def logout(self):
152155 self ._logout_request ()
153156 self ._sid = None
154157
155- def get_prefixed_host (self ):
156- """Choose the correct protocol prefix for the host.
157-
158- Supports three input formats:
159- - https://<host>(requests use strict certificate validation by default)
160- - http://<host> (unecrypted)
161- - <host> (unencrypted)
162- """
163- host = self ._host
164- if host .startswith ("https://" ) or host .startswith ("http://" ):
165- return host
166- else :
167- return "http://" + host
168-
169158 def update_devices (self , ignore_removed = True ):
170159 """Update the device."""
171160 _LOGGER .info ("Updating Devices ..." )
0 commit comments