@@ -141,20 +141,30 @@ def _do_connect(self):
141141
142142 def _reconnect_cb (self ):
143143 """Callback to reconnect to the server."""
144+ _LOGGER .info ('try reconnect' )
144145 @asyncio .coroutine
145146 def try_reconnect ():
146147 """Actual coroutine ro try to reconnect or reschedule."""
147148 try :
148149 yield from self ._do_connect ()
149- except IOError :
150+ except OSError :
150151 self ._loop .call_later (SERVER_RECONNECT_DELAY ,
151152 self ._reconnect_cb )
153+ else :
154+ status = yield from self .status ()
155+ self .synchronize (status )
156+ self ._on_server_connect ()
152157 asyncio .ensure_future (try_reconnect ())
153158
154159 @asyncio .coroutine
155160 def _transact (self , method , params = None ):
156161 """Wrap requests."""
157- result , error = yield from self ._protocol .request (method , params )
162+ result = error = None
163+ try :
164+ result , error = yield from self ._protocol .request (method , params )
165+ except :
166+ _LOGGER .warning ('could not send request' )
167+ error = 'could not send request'
158168 return result or error
159169
160170 @property
@@ -303,11 +313,13 @@ def _request(self, method, identifier, key=None, value=None, parameters=None):
303313
304314 def _on_server_connect (self ):
305315 """Handle server connection."""
316+ _LOGGER .info ('Server connected' )
306317 if self ._on_connect_callback_func and callable (self ._on_connect_callback_func ):
307318 self ._on_connect_callback_func ()
308319
309320 def _on_server_disconnect (self , exception ):
310321 """Handle server disconnection."""
322+ _LOGGER .info ('Server disconnected' )
311323 if self ._on_disconnect_callback_func and callable (self ._on_disconnect_callback_func ):
312324 self ._on_disconnect_callback_func (exception )
313325 if not self ._is_stopped :
0 commit comments