11import dataclasses
2- from typing import Optional
32
43from ualfred import (
54 ICON_ACCOUNT ,
@@ -84,47 +83,74 @@ def afw_responses_to_feedback(responses: list[AFWResponse]) -> list[dict]:
8483
8584
8685class AFWFuncAbc :
86+ _icon_success = ICON_INFO
87+ _icon_default = ICON_INFO
88+ _icon_error = ICON_ERROR
89+ _icon_tip = ICON_NOTE
90+
8791 def __init__ (self , args : list [str ], logger ) -> None :
8892 self .args = args
8993 self .logger = logger
9094
9195 @property
92- def _data_defaulte (self ) -> list :
96+ def _data_success (self ) -> list :
9397 raise NotImplementedError
9498
9599 @property
96- def _data_tips (self ) -> list :
100+ def _data_defaulte (self ) -> list :
97101 raise NotImplementedError
98102
99103 @property
100- def _data_success (self ) -> list :
104+ def _data_error (self ) -> list :
101105 raise NotImplementedError
102106
103107 @property
104- def _data_error (self ) -> list :
108+ def _data_tips (self ) -> list :
105109 raise NotImplementedError
106110
107- def get_response_success (self ) -> list [AFWResponse ]:
108- return [
111+ @staticmethod
112+ def _afw_response_to_feedback_data (responses : list [AFWResponse ]) -> list [dict ]:
113+ result = list ()
114+ for obj in responses :
115+ data = dataclasses .asdict (obj )
116+ for k in list (data .keys ()):
117+ if data [k ] is None :
118+ data .pop (k )
119+
120+ result .append (data )
121+
122+ return result
123+
124+ def get_feedback_success (self ) -> list [dict ]:
125+ responses = [
109126 AFWResponse (
110- title = title , arg = title , subtitle = subtitle , icon = ICON_INFO , valid = True
127+ title = title ,
128+ arg = title ,
129+ subtitle = subtitle ,
130+ icon = self ._icon_success ,
131+ valid = True ,
111132 )
112133 for title , subtitle in self ._data_success
113134 ] + [
114135 AFWResponse (
115- title = title , arg = title , subtitle = subtitle , icon = ICON_NOTE , valid = False
136+ title = title ,
137+ arg = title ,
138+ subtitle = subtitle ,
139+ icon = self ._icon_tip ,
140+ valid = False ,
116141 )
117142 for title , subtitle in self ._data_tips
118143 ]
144+ return self ._afw_response_to_feedback_data (responses )
119145
120- def get_response_fail (self ) -> list [AFWResponse ]:
121- return (
146+ def get_feedback_fail (self ) -> list [dict ]:
147+ responses = (
122148 [
123149 AFWResponse (
124150 title = title ,
125151 arg = title ,
126152 subtitle = subtitle ,
127- icon = ICON_ERROR ,
153+ icon = self . _icon_error ,
128154 valid = False ,
129155 )
130156 for title , subtitle in self ._data_error
@@ -134,7 +160,7 @@ def get_response_fail(self) -> list[AFWResponse]:
134160 title = title ,
135161 arg = title ,
136162 subtitle = subtitle ,
137- icon = ICON_INFO ,
163+ icon = self . _icon_default ,
138164 valid = True ,
139165 )
140166 for title , subtitle in self ._data_defaulte
@@ -144,18 +170,19 @@ def get_response_fail(self) -> list[AFWResponse]:
144170 title = title ,
145171 arg = title ,
146172 subtitle = subtitle ,
147- icon = ICON_NOTE ,
173+ icon = self . _data_tips ,
148174 valid = False ,
149175 )
150176 for title , subtitle in self ._data_tips
151177 ]
152178 )
179+ return self ._afw_response_to_feedback_data (responses )
153180
154181 def _process (self ) -> bool :
155182 raise NotImplementedError
156183
157- def __call__ (self ) -> list [AFWResponse ]:
184+ def __call__ (self ) -> list [dict ]:
158185 if self ._process ():
159- return self .get_response_success ()
186+ return self .get_feedback_success ()
160187
161- return self .get_response_fail ()
188+ return self .get_feedback_fail ()
0 commit comments