1616
1717from  tests .common  import  MockConfigEntry 
1818
19- SWITCH_WIFI_GUEST_NETWORK  =  "switch.lte_wi_fi_guest_network " 
19+ SWITCH_WIFI_GUEST_NETWORK  =  "switch.test_router_wi_fi_guest_network " 
2020
2121
22- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
23- @patch ("homeassistant.components.huawei_lte.Client" , return_value = magic_client ({})) 
2422async  def  test_huawei_lte_wifi_guest_network_config_entry_when_network_is_not_present (
25-     client ,
26-     hass : HomeAssistant ,
27-     entity_registry : er .EntityRegistry ,
23+     hass : HomeAssistant , entity_registry : er .EntityRegistry 
2824) ->  None :
2925    """Test switch wifi guest network config entry when network is not present.""" 
3026    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
3127    huawei_lte .add_to_hass (hass )
32-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
28+     with  (
29+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
30+         patch (
31+             "homeassistant.components.huawei_lte.Client" , return_value = magic_client ()
32+         ),
33+     ):
34+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
3335    await  hass .async_block_till_done ()
36+ 
3437    assert  not  entity_registry .async_is_registered (SWITCH_WIFI_GUEST_NETWORK )
3538
3639
37- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
38- @patch ( 
39-     "homeassistant.components.huawei_lte.Client" , 
40-     return_value = magic_client ( 
41-         {"Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "0" }]}} 
42-     ), 
43- ) 
4440async  def  test_huawei_lte_wifi_guest_network_config_entry_when_network_is_present (
45-     client ,
46-     hass : HomeAssistant ,
47-     entity_registry : er .EntityRegistry ,
41+     hass : HomeAssistant , entity_registry : er .EntityRegistry 
4842) ->  None :
4943    """Test switch wifi guest network config entry when network is present.""" 
5044    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
5145    huawei_lte .add_to_hass (hass )
52-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
46+     client  =  magic_client ()
47+     client .wlan .multi_basic_settings .return_value  =  {
48+         "Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "0" }]}
49+     }
50+     with  (
51+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
52+         patch ("homeassistant.components.huawei_lte.Client" , return_value = client ),
53+     ):
54+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
5355    await  hass .async_block_till_done ()
56+ 
5457    assert  entity_registry .async_is_registered (SWITCH_WIFI_GUEST_NETWORK )
5558
5659
57- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
58- @patch ("homeassistant.components.huawei_lte.Client" ) 
59- async  def  test_turn_on_switch_wifi_guest_network (client , hass : HomeAssistant ) ->  None :
60+ async  def  test_turn_on_switch_wifi_guest_network (hass : HomeAssistant ) ->  None :
6061    """Test switch wifi guest network turn on method.""" 
61-     client .return_value  =  magic_client (
62-         {"Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "0" }]}}
63-     )
6462    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
6563    huawei_lte .add_to_hass (hass )
66-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
64+     client  =  magic_client ()
65+     client .wlan .multi_basic_settings .return_value  =  {
66+         "Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "0" }]}
67+     }
68+     with  (
69+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
70+         patch ("homeassistant.components.huawei_lte.Client" , return_value = client ),
71+     ):
72+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
6773    await  hass .async_block_till_done ()
74+ 
6875    await  hass .services .async_call (
6976        SWITCH_DOMAIN ,
7077        SERVICE_TURN_ON ,
@@ -73,20 +80,24 @@ async def test_turn_on_switch_wifi_guest_network(client, hass: HomeAssistant) ->
7380    )
7481    await  hass .async_block_till_done ()
7582    assert  hass .states .is_state (SWITCH_WIFI_GUEST_NETWORK , STATE_ON )
76-     client .return_value . wlan .wifi_guest_network_switch .assert_called_once_with (True )
83+     client .wlan .wifi_guest_network_switch .assert_called_once_with (True )
7784
7885
79- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
80- @patch ("homeassistant.components.huawei_lte.Client" ) 
81- async  def  test_turn_off_switch_wifi_guest_network (client , hass : HomeAssistant ) ->  None :
86+ async  def  test_turn_off_switch_wifi_guest_network (hass : HomeAssistant ) ->  None :
8287    """Test switch wifi guest network turn off method.""" 
83-     client .return_value  =  magic_client (
84-         {"Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "1" }]}}
85-     )
8688    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
8789    huawei_lte .add_to_hass (hass )
88-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
90+     client  =  magic_client ()
91+     client .wlan .multi_basic_settings .return_value  =  {
92+         "Ssids" : {"Ssid" : [{"wifiisguestnetwork" : "1" , "WifiEnable" : "1" }]}
93+     }
94+     with  (
95+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
96+         patch ("homeassistant.components.huawei_lte.Client" , return_value = client ),
97+     ):
98+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
8999    await  hass .async_block_till_done ()
100+ 
90101    await  hass .services .async_call (
91102        SWITCH_DOMAIN ,
92103        SERVICE_TURN_OFF ,
@@ -95,46 +106,46 @@ async def test_turn_off_switch_wifi_guest_network(client, hass: HomeAssistant) -
95106    )
96107    await  hass .async_block_till_done ()
97108    assert  hass .states .is_state (SWITCH_WIFI_GUEST_NETWORK , STATE_OFF )
98-     client .return_value . wlan .wifi_guest_network_switch .assert_called_with (False )
109+     client .wlan .wifi_guest_network_switch .assert_called_with (False )
99110
100111
101- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
102- @patch ( 
103-     "homeassistant.components.huawei_lte.Client" , 
104-     return_value = magic_client ({"Ssids" : {"Ssid" : "str" }}), 
105- ) 
106112async  def  test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_str (
107-     client ,
108-     hass : HomeAssistant ,
109-     entity_registry : er .EntityRegistry ,
113+     hass : HomeAssistant , entity_registry : er .EntityRegistry 
110114) ->  None :
111115    """Test switch wifi guest network config entry when ssid is a str. 
112116
113117    Issue #76244. Huawai models: H312-371, E5372 and E8372. 
114118    """ 
115119    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
116120    huawei_lte .add_to_hass (hass )
117-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
121+     client  =  magic_client ()
122+     client .wlan .multi_basic_settings .return_value  =  {"Ssids" : {"Ssid" : "str" }}
123+     with  (
124+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
125+         patch ("homeassistant.components.huawei_lte.Client" , return_value = client ),
126+     ):
127+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
118128    await  hass .async_block_till_done ()
129+ 
119130    assert  not  entity_registry .async_is_registered (SWITCH_WIFI_GUEST_NETWORK )
120131
121132
122- @patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()) 
123- @patch ( 
124-     "homeassistant.components.huawei_lte.Client" , 
125-     return_value = magic_client ({"Ssids" : {"Ssid" : None }}), 
126- ) 
127133async  def  test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_none (
128-     client ,
129-     hass : HomeAssistant ,
130-     entity_registry : er .EntityRegistry ,
134+     hass : HomeAssistant , entity_registry : er .EntityRegistry 
131135) ->  None :
132136    """Test switch wifi guest network config entry when ssid is a None. 
133137
134138    Issue #76244. 
135139    """ 
136140    huawei_lte  =  MockConfigEntry (domain = DOMAIN , data = {CONF_URL : "http://huawei-lte" })
137141    huawei_lte .add_to_hass (hass )
138-     await  hass .config_entries .async_setup (huawei_lte .entry_id )
142+     client  =  magic_client ()
143+     client .wlan .multi_basic_settings .return_value  =  {"Ssids" : {"Ssid" : None }}
144+     with  (
145+         patch ("homeassistant.components.huawei_lte.Connection" , MagicMock ()),
146+         patch ("homeassistant.components.huawei_lte.Client" , return_value = client ),
147+     ):
148+         await  hass .config_entries .async_setup (huawei_lte .entry_id )
139149    await  hass .async_block_till_done ()
150+ 
140151    assert  not  entity_registry .async_is_registered (SWITCH_WIFI_GUEST_NETWORK )
0 commit comments