1313from homeassistant .components .sensor import PLATFORM_SCHEMA
1414from homeassistant .const import (
1515 CONF_HOST ,
16+ CONF_PORT ,
1617 CONF_NAME ,
1718 CONF_SCAN_INTERVAL ,
1819 ATTR_ATTRIBUTION ,
3435PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend (
3536 {
3637 vol .Required (CONF_HOST ): cv .string ,
38+ vol .Optional (CONF_PORT ): cv .positive_int ,
3739 vol .Optional (CONF_NAME ): cv .string ,
3840 }
3941)
@@ -76,6 +78,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
7678 update_interval = config .get (CONF_SCAN_INTERVAL , SCAN_INTERVAL )
7779
7880 host = config .get (CONF_HOST )
81+ port = config .get (CONF_PORT , 80 )
7982
8083 try :
8184 session = []
@@ -84,22 +87,23 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
8487 return False
8588 fbx = freepybox .freepybox ( token_file = manageDirectory () )
8689 _LOGGER .info ("host %s" % (host ))
87- fbx .open (host , 80 )
90+ fbx .open (host , port )
8891 fbxlstPlayer = fbx .freeplayer .get_freeplayer_list ()
8992 fbx .close ()
90- add_entities ([myFreeBox (session , name , update_interval , host )], True )
93+ add_entities ([myFreeBox (session , name , update_interval , host , port )], True )
9194 for monPlayer in fbxlstPlayer :
92- add_entities ([myFreeBoxPlayer (session , name , update_interval , host , monPlayer ["id" ] )], True )
95+ add_entities ([myFreeBoxPlayer (session , name , update_interval , host , port , monPlayer ["id" ] )], True )
9396 # on va gerer un element par heure ... maintenant
9497
9598class myFreeBox (Entity ):
9699 """."""
97100
98- def __init__ (self , session , name , interval , host ):
101+ def __init__ (self , session , name , interval , host , port ):
99102 """Initialize the sensor."""
100103 self ._session = session
101104 self ._name = name
102105 self ._host = host
106+ self ._port = port
103107 self ._attributes = None
104108 self ._state = None
105109 self .update = Throttle (interval )(self ._update )
@@ -123,7 +127,7 @@ def _update(self):
123127 """Update device state."""
124128 status_counts = defaultdict (int )
125129 fbx = freepybox .freepybox ( token_file = manageDirectory () )
126- fbx .open (self ._host , 80 )
130+ fbx .open (self ._host , self . _port )
127131 fbx_connection_status_details = fbx .connection .get_status_details ()
128132 fbx_connection_xdsl_details = fbx .connection .get_xdsl_stats ()
129133 fbx .close ()
@@ -161,11 +165,12 @@ def icon(self):
161165class myFreeBoxPlayer (Entity ):
162166 """."""
163167
164- def __init__ (self , session , name , interval , host , id ):
168+ def __init__ (self , session , name , interval , host , port , id ):
165169 """Initialize the sensor."""
166170 self ._session = session
167171 self ._name = name
168172 self ._host = host
173+ self ._port = port
169174 self ._id = id
170175 self ._attributes = None
171176 self ._state = None
@@ -195,7 +200,7 @@ def _update(self):
195200 status_counts ["version" ] = __VERSION__
196201 status_counts ["lastSynchro" ] = datetime .datetime .now ()
197202 try :
198- fbx .open (self ._host , 80 )
203+ fbx .open (self ._host , self . _port )
199204 myfbx_player_status_details = fbx .freeplayer .get_freeplayer (self ._id )
200205 fbx .close ()
201206 status_counts ["power_stat" ] = myfbx_player_status_details ["power_state" ]
0 commit comments