1111)
1212from homeassistant .components .nmap_tracker .const import (
1313 CONF_HOME_INTERVAL ,
14+ CONF_MAC_EXCLUDE ,
1415 CONF_OPTIONS ,
1516 DEFAULT_OPTIONS ,
1617 DOMAIN ,
@@ -48,6 +49,7 @@ async def test_form(hass: HomeAssistant, hosts: str) -> None:
4849 CONF_HOME_INTERVAL : 3 ,
4950 CONF_OPTIONS : DEFAULT_OPTIONS ,
5051 CONF_EXCLUDE : "4.4.4.4" ,
52+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
5153 },
5254 )
5355 await hass .async_block_till_done ()
@@ -60,6 +62,7 @@ async def test_form(hass: HomeAssistant, hosts: str) -> None:
6062 CONF_HOME_INTERVAL : 3 ,
6163 CONF_OPTIONS : DEFAULT_OPTIONS ,
6264 CONF_EXCLUDE : "4.4.4.4" ,
65+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
6366 }
6467 assert len (mock_setup_entry .mock_calls ) == 1
6568
@@ -84,6 +87,7 @@ async def test_form_range(hass: HomeAssistant) -> None:
8487 CONF_HOME_INTERVAL : 3 ,
8588 CONF_OPTIONS : DEFAULT_OPTIONS ,
8689 CONF_EXCLUDE : "4.4.4.4" ,
90+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
8791 },
8892 )
8993 await hass .async_block_till_done ()
@@ -96,6 +100,7 @@ async def test_form_range(hass: HomeAssistant) -> None:
96100 CONF_HOME_INTERVAL : 3 ,
97101 CONF_OPTIONS : DEFAULT_OPTIONS ,
98102 CONF_EXCLUDE : "4.4.4.4" ,
103+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
99104 }
100105 assert len (mock_setup_entry .mock_calls ) == 1
101106
@@ -116,6 +121,7 @@ async def test_form_invalid_hosts(hass: HomeAssistant) -> None:
116121 CONF_HOME_INTERVAL : 3 ,
117122 CONF_OPTIONS : DEFAULT_OPTIONS ,
118123 CONF_EXCLUDE : "" ,
124+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
119125 },
120126 )
121127 await hass .async_block_till_done ()
@@ -135,6 +141,7 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
135141 CONF_HOME_INTERVAL : 3 ,
136142 CONF_OPTIONS : DEFAULT_OPTIONS ,
137143 CONF_EXCLUDE : "4.4.4.4" ,
144+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
138145 },
139146 )
140147 config_entry .add_to_hass (hass )
@@ -151,6 +158,7 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
151158 CONF_HOME_INTERVAL : 3 ,
152159 CONF_OPTIONS : DEFAULT_OPTIONS ,
153160 CONF_EXCLUDE : "" ,
161+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
154162 },
155163 )
156164 await hass .async_block_till_done ()
@@ -159,8 +167,8 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
159167 assert result2 ["reason" ] == "already_configured"
160168
161169
162- async def test_form_invalid_excludes (hass : HomeAssistant ) -> None :
163- """Test invalid excludes passed in."""
170+ async def test_form_invalid_ip_excludes (hass : HomeAssistant ) -> None :
171+ """Test invalid ip excludes passed in."""
164172
165173 result = await hass .config_entries .flow .async_init (
166174 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
@@ -175,6 +183,7 @@ async def test_form_invalid_excludes(hass: HomeAssistant) -> None:
175183 CONF_HOME_INTERVAL : 3 ,
176184 CONF_OPTIONS : DEFAULT_OPTIONS ,
177185 CONF_EXCLUDE : "not an exclude" ,
186+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" ],
178187 },
179188 )
180189 await hass .async_block_till_done ()
@@ -183,6 +192,37 @@ async def test_form_invalid_excludes(hass: HomeAssistant) -> None:
183192 assert result2 ["errors" ] == {CONF_EXCLUDE : "invalid_hosts" }
184193
185194
195+ @pytest .mark .parametrize (
196+ "mac_excludes" ,
197+ [["1234567890" ], ["1234567890" , "11:22:33:44:55:66" ], ["ABCDEFGHIJK" ]],
198+ )
199+ async def test_form_invalid_mac_excludes (
200+ hass : HomeAssistant , mac_excludes : str
201+ ) -> None :
202+ """Test invalid mac excludes passed in."""
203+
204+ result = await hass .config_entries .flow .async_init (
205+ DOMAIN , context = {"source" : config_entries .SOURCE_USER }
206+ )
207+ assert result ["type" ] is FlowResultType .FORM
208+ assert result ["errors" ] == {}
209+
210+ result2 = await hass .config_entries .flow .async_configure (
211+ result ["flow_id" ],
212+ {
213+ CONF_HOSTS : "3.3.3.3" ,
214+ CONF_HOME_INTERVAL : 3 ,
215+ CONF_OPTIONS : DEFAULT_OPTIONS ,
216+ CONF_EXCLUDE : "4.4.4.4" ,
217+ CONF_MAC_EXCLUDE : mac_excludes ,
218+ },
219+ )
220+ await hass .async_block_till_done ()
221+
222+ assert result2 ["type" ] is FlowResultType .FORM
223+ assert result2 ["errors" ] == {CONF_MAC_EXCLUDE : "invalid_hosts" }
224+
225+
186226async def test_options_flow (hass : HomeAssistant ) -> None :
187227 """Test we can edit options."""
188228
@@ -194,6 +234,7 @@ async def test_options_flow(hass: HomeAssistant) -> None:
194234 CONF_HOME_INTERVAL : 3 ,
195235 CONF_OPTIONS : DEFAULT_OPTIONS ,
196236 CONF_EXCLUDE : "4.4.4.4" ,
237+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" , "11:22:33:44:55:66" ],
197238 },
198239 )
199240 config_entry .add_to_hass (hass )
@@ -214,6 +255,7 @@ async def test_options_flow(hass: HomeAssistant) -> None:
214255 CONF_CONSIDER_HOME : 180 ,
215256 CONF_SCAN_INTERVAL : 120 ,
216257 CONF_OPTIONS : "-n -sn -PR -T4 --min-rate 10 --host-timeout 5s" ,
258+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" , "11:22:33:44:55:66" ],
217259 }
218260
219261 with patch (
@@ -229,6 +271,7 @@ async def test_options_flow(hass: HomeAssistant) -> None:
229271 CONF_OPTIONS : "-sn" ,
230272 CONF_EXCLUDE : "4.4.4.4, 5.5.5.5" ,
231273 CONF_SCAN_INTERVAL : 10 ,
274+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" , "11:22:33:44:55:66" ],
232275 },
233276 )
234277 await hass .async_block_till_done ()
@@ -241,5 +284,6 @@ async def test_options_flow(hass: HomeAssistant) -> None:
241284 CONF_OPTIONS : "-sn" ,
242285 CONF_EXCLUDE : "4.4.4.4,5.5.5.5" ,
243286 CONF_SCAN_INTERVAL : 10 ,
287+ CONF_MAC_EXCLUDE : ["00:00:00:00:00:00" , "11:22:33:44:55:66" ],
244288 }
245289 assert len (mock_setup_entry .mock_calls ) == 1
0 commit comments