File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,23 @@ def new_api(*args):
180180        assert  app .version  is  sentinel .version 
181181
182182
183+ async  def  test_connect_failure (app ):
184+     with  patch .object (application , "Deconz" ) as  api_mock :
185+         api  =  api_mock .return_value  =  MagicMock ()
186+         api .connect  =  AsyncMock ()
187+         api .version  =  AsyncMock (side_effect = RuntimeError ("Broken" ))
188+ 
189+         app ._api  =  None 
190+ 
191+         with  pytest .raises (RuntimeError ):
192+             await  app .connect ()
193+ 
194+         assert  app ._api  is  None 
195+         api .connect .assert_called_once ()
196+         api .version .assert_called_once ()
197+         api .close .assert_called_once ()
198+ 
199+ 
183200async  def  test_disconnect (app ):
184201    reset_watchdog_task  =  app ._reset_watchdog_task  =  MagicMock ()
185202    api_close  =  app ._api .close  =  MagicMock ()
Original file line number Diff line number Diff line change 33# coding: utf-8 
44MAJOR_VERSION  =  0 
55MINOR_VERSION  =  19 
6- PATCH_VERSION  =  "0 " 
6+ PATCH_VERSION  =  "1 " 
77__short_version__  =  f"{ MAJOR_VERSION } { MINOR_VERSION }  
88__version__  =  f"{ __short_version__ } { PATCH_VERSION }  
Original file line number Diff line number Diff line change @@ -76,8 +76,14 @@ async def _reset_watchdog(self):
7676
7777    async  def  connect (self ):
7878        api  =  Deconz (self , self ._config [zigpy .config .CONF_DEVICE ])
79-         await  api .connect ()
80-         self .version  =  await  api .version ()
79+ 
80+         try :
81+             await  api .connect ()
82+             self .version  =  await  api .version ()
83+         except  Exception :
84+             api .close ()
85+             raise 
86+ 
8187        self ._api  =  api 
8288        self ._written_endpoints .clear ()
8389
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments