@@ -35,7 +35,7 @@ class UiCache:
3535 baseUri : str
3636 icon : CachedImage | None
3737 endpoints : UiEndpoints
38-
38+
3939 def to_response (self ) -> UiResponse | None :
4040 return UiResponse (
4141 order = self .order ,
@@ -64,7 +64,7 @@ class UisCache:
6464 plugin : list [UiCache ] = field (default_factory = list )
6565 metrics : list [UiCache ] = field (default_factory = list )
6666 infra : list [UiCache ] = field (default_factory = list )
67-
67+
6868 def to_response (self ) -> UisResponse :
6969 return UisResponse (
7070 self .home ,
@@ -73,7 +73,7 @@ def to_response(self) -> UisResponse:
7373 list (map (lambda c : c .to_response (), self .metrics )),
7474 list (map (lambda c : c .to_response (), self .infra )),
7575 )
76-
76+
7777 def getCategory (self , category : str ):
7878 if category == "core" :
7979 return self .core
@@ -89,18 +89,18 @@ def getCategory(self, category: str):
8989class UiUtils :
9090 ui_dir = os .getenv ('CHARACTERISTICS_UI_DIR' , '/data/uis/' )
9191 ui_cache = None
92-
92+
9393 @classmethod
9494 def __get_ui_endpoints (cls , uiRaw ) -> UiEndpoints :
9595 return UiEndpoints (
9696 uiRaw ["monitorEndpoint" ],
9797 uiRaw ["item" ] if "item" in uiRaw else None ,
9898 )
99-
99+
100100 @classmethod
101101 def __get_ui (cls , uiRaw ) -> UiCache :
102102 return UiCache (
103- uiRaw ["order" ],
103+ uiRaw ["order" ] if "order" in uiRaw else 999 ,
104104 uiRaw ["id" ] if "id" in uiRaw else None ,
105105 uiRaw ["name" ],
106106 uiRaw ["description" ],
@@ -111,7 +111,7 @@ def __get_ui(cls, uiRaw) -> UiCache:
111111 ) if "icon" in uiRaw else None ,
112112 cls .__get_ui_endpoints (uiRaw )
113113 )
114-
114+
115115 @classmethod
116116 def validate_ui_list (cls , uiList : list [UiCache ]) -> None :
117117 # ensure id uniqueness
@@ -127,28 +127,28 @@ def validate_ui_list(cls, uiList: list[UiCache]) -> None:
127127 )
128128 if len (filtered_list ) != 1 :
129129 raise Exception ("Invalid UI ID (duplicates): " + uiCache .id )
130-
130+
131131 @classmethod
132132 def get_uis_cache (cls ) -> UisCache :
133133 if cls .ui_cache is not None :
134134 return cls .ui_cache
135-
135+
136136 directory = os .getenv ('UIS_DATA_DIR' , "/data/uis/" )
137-
137+
138138 uisRawData : list [dict ] = list ()
139-
139+
140140 for file in os .listdir (directory ):
141141 filename = os .path .basename (file )
142142 if filename .endswith (".json" ):
143143 curUiFileLoc = os .path .join (directory , filename )
144144 with open (curUiFileLoc ) as curUiFile :
145145 uisRawData .append (json .load (curUiFile ))
146-
146+
147147 output : UisCache = UisCache (os .getenv ('UIS_HOME_URL' , " " ))
148-
148+
149149 for rawUi in uisRawData :
150150 uiCache = cls .__get_ui (rawUi )
151-
151+
152152 if rawUi ["type" ].casefold () == "core" :
153153 output .core .append (uiCache )
154154 elif rawUi ["type" ].casefold () == "plugins" :
@@ -159,25 +159,25 @@ def get_uis_cache(cls) -> UisCache:
159159 output .infra .append (uiCache )
160160 else :
161161 print ("WARN:: invalid type: " + rawUi ["type" ].casefold ())
162-
162+
163163 cls .validate_ui_list (output .core )
164164 cls .validate_ui_list (output .metrics )
165165 cls .validate_ui_list (output .infra )
166166 cls .validate_ui_list (output .plugin )
167-
167+
168168 output .core = sorted (output .core , key = lambda c : c .order )
169169 output .metrics = sorted (output .metrics , key = lambda c : c .order )
170170 output .infra = sorted (output .infra , key = lambda c : c .order )
171171 output .plugin = sorted (output .plugin , key = lambda c : c .order )
172-
172+
173173 cls .ui_cache = output
174-
174+
175175 return output
176-
176+
177177 @classmethod
178178 def get_uis_return (cls ) -> UisResponse :
179179 return cls .get_uis_cache ().to_response ()
180-
180+
181181 @classmethod
182182 def get_ui_icon (cls , category : str , uiId : str ) -> StreamingResponse :
183183 try :
@@ -190,9 +190,9 @@ def get_ui_icon(cls, category: str, uiId: str) -> StreamingResponse:
190190 )
191191 except ValueError as e :
192192 raise HTTPException (status_code = 404 , detail = "Invalid UI category: " + category )
193-
193+
194194 if len (ui ) == 0 :
195195 raise HTTPException (status_code = 404 , detail = "Invalid UI ID: " + uiId )
196196 ui = ui [0 ]
197-
197+
198198 return ImageUtils .get_image_response (ui .icon )
0 commit comments