2929 OutputMode ,
3030 WATCHDOG_SETTING ,
3131)
32- from crystalfontz .dbus .bus import select_session_bus , select_system_bus
3332from crystalfontz .dbus .client import DbusClient
3433from crystalfontz .dbus .config import StagedConfig
3534from crystalfontz .dbus .domain import (
5251 VersionsM ,
5352)
5453from crystalfontz .dbus .error import handle_dbus_error
54+ from crystalfontz .dbus .report import DbusClientCliReportHandler
55+ from crystalfontz .dbus .select import (
56+ select_default_bus ,
57+ select_session_bus ,
58+ select_system_bus ,
59+ )
5560from crystalfontz .gpio import GpioDriveMode , GpioFunction
5661from crystalfontz .lcd import LcdRegister
5762from crystalfontz .temperature import (
@@ -70,6 +75,7 @@ class Obj:
7075 output : OutputMode
7176 timeout : TimeoutT
7277 retry_times : RetryTimesT
78+ report_handler : DbusClientCliReportHandler
7379
7480
7581def pass_config (fn : AsyncCommand ) -> AsyncCommand :
@@ -101,6 +107,15 @@ async def wrapped(obj: Obj, *args, **kwargs) -> None:
101107 return wrapped
102108
103109
110+ def pass_report_handler (fn : AsyncCommand ) -> AsyncCommand :
111+ @click .pass_obj
112+ @functools .wraps (fn )
113+ async def wrapped (obj : Obj , * args , ** kwargs ) -> None :
114+ await fn (obj .report_handler , * args , ** kwargs )
115+
116+ return wrapped
117+
118+
104119def should_sudo (config_file : str ) -> bool :
105120 st = os .stat (config_file )
106121 return os .geteuid () != st .st_uid
@@ -202,14 +217,20 @@ async def load() -> None:
202217 select_session_bus ()
203218 elif user is None :
204219 select_system_bus ()
220+ else :
221+ select_default_bus ()
222+
223+ report_handler = DbusClientCliReportHandler ()
224+ report_handler .mode = output
205225
206- client = DbusClient ()
226+ client = DbusClient (report_handler = report_handler )
207227 ctx .obj = Obj (
208228 client = client ,
209229 log_level = log_level ,
210230 output = output ,
211231 timeout = TimeoutM .pack (timeout ),
212232 retry_times = RetryTimesM .pack (retry_times ),
233+ report_handler = report_handler ,
213234 )
214235
215236 asyncio .run (load ())
@@ -355,16 +376,26 @@ async def detect(
355376@main .command ()
356377@click .option ("--for" , "for_" , type = float , help = "Amount of time to listen for reports" )
357378@async_command
379+ @pass_report_handler
358380@pass_client
359- async def listen (client : DbusClient , for_ : Optional [float ]) -> None :
381+ async def listen (
382+ client : DbusClient ,
383+ report_handler : DbusClientCliReportHandler ,
384+ for_ : Optional [float ],
385+ ) -> None :
360386 """
361387 Listen for key and temperature reports.
362388
363389 To configure which reports to receive, use 'crystalfontz keypad reporting' and
364390 'crystalfontz temperature reporting' respectively.
365391 """
366392
367- raise NotImplementedError ("listen" )
393+ await report_handler .listen ()
394+
395+ if for_ is not None :
396+ await asyncio .sleep (for_ )
397+ report_handler .stop ()
398+ await report_handler .done
368399
369400
370401@main .command (help = "0 (0x00): Ping command" )
0 commit comments