33from .exceptions import AirOSMultipleMatchesFoundException
44
55MODELS : dict [str , str ] = {
6+ # Generated list from https://store.ui.com/us/en/category/wireless
67 "Wave MLO5" : "Wave-MLO5" ,
78 "airMAX Rocket Prism 5AC" : "RP-5AC-Gen2" ,
89 "airFiber 5XHD" : "AF-5XHD" ,
7576 "airMAX 5 GHz, 19/20 dBi Sector" : "AM-5G2" ,
7677 "airMAX 2.4 GHz, 10 dBi Omni" : "AMO-2G10" ,
7778 "airMAX 2.4 GHz, 15 dBi, 120º Sector" : "AM-2G15-120" ,
79+ # Manually added entries for common unofficial names
7880}
7981
8082
@@ -90,15 +92,39 @@ def get_sku_by_devmodel(self, devmodel: str) -> str:
9092 if devmodel in MODELS :
9193 return MODELS [devmodel ]
9294
93- match_key = None
94- matches_found = 0
95+ match_key : str | None = None
96+ matches_found : int = 0
97+
98+ best_match_key : str | None = None
99+ best_match_is_prefix = False
95100
96101 lower_devmodel = devmodel .lower ()
97102
98103 for model_name in MODELS :
99- if lower_devmodel in model_name .lower ():
100- match_key = model_name
104+ lower_model_name = model_name .lower ()
105+
106+ if lower_model_name .startswith (lower_devmodel ):
107+ if not best_match_is_prefix or len (lower_model_name ) == len (
108+ lower_devmodel
109+ ):
110+ best_match_key = model_name
111+ best_match_is_prefix = True
112+ matches_found = 1
113+ match_key = model_name
114+ else :
115+ matches_found += 1
116+ best_match_key = None
117+
118+ elif not best_match_is_prefix and lower_devmodel in lower_model_name :
101119 matches_found += 1
120+ match_key = model_name
121+
122+ if best_match_key and best_match_is_prefix and matches_found == 1 :
123+ # If a unique prefix match was found ("LiteBeam 5AC" -> "airMAX LiteBeam 5AC")
124+ return MODELS [best_match_key ]
125+
126+ if best_match_key and best_match_is_prefix and matches_found > 1 :
127+ pass # fall through exception
102128
103129 if match_key is None or matches_found == 0 :
104130 raise KeyError (f"No product found for devmodel: { devmodel } " )
0 commit comments