1- import asyncio
21from typing import Optional
32
43import flet as ft
@@ -39,11 +38,11 @@ class Flashlight(ft.Service):
3938 contains information on the error.
4039 """
4140
42- async def turn_on_async (self ):
41+ async def turn_on (self ):
4342 """
4443 Turns the flashlight on.
4544 """
46- r = await self ._invoke_method_async ("on" )
45+ r = await self ._invoke_method ("on" )
4746 if r is True :
4847 self .on = True
4948 else : # error occured
@@ -56,17 +55,11 @@ async def turn_on_async(self):
5655 else :
5756 raise FlashlightEnableException (error_msg )
5857
59- def turn_on (self ):
60- """
61- Turns the flashlight on.
62- """
63- asyncio .create_task (self .turn_on_async ())
64-
65- async def turn_off_async (self ):
58+ async def turn_off (self ):
6659 """
6760 Turns the flashlight off.
6861 """
69- r = await self ._invoke_method_async ("off" )
62+ r = await self ._invoke_method ("off" )
7063 if r is True :
7164 self .on = False
7265 else : # error occured
@@ -79,31 +72,19 @@ async def turn_off_async(self):
7972 else :
8073 raise FlashlightDisableException (error_msg )
8174
82- def turn_off (self ):
83- """
84- Turns the flashlight off.
85- """
86- asyncio .create_task (self .turn_off_async ())
87-
88- async def toggle_async (self ):
75+ async def toggle (self ):
8976 """
9077 Toggles the flashlight on and off.
9178 """
9279 if self .on :
93- await self .turn_off_async ()
94- await self .turn_on_async ()
95-
96- def toggle (self ):
97- """
98- Toggles the flashlight on and off.
99- """
100- asyncio .create_task (self .toggle_async ())
80+ await self .turn_off ()
81+ await self .turn_on ()
10182
102- async def is_available_async (self ):
83+ async def is_available (self ):
10384 """
10485 Checks if the flashlight is available on the device.
10586 """
106- r = await self ._invoke_method_async ("is_available" )
87+ r = await self ._invoke_method ("is_available" )
10788 if r is bool :
10889 return r
10990 else : # error occured
0 commit comments