@@ -40,8 +40,9 @@ class YeelightProtocol(SimpleServiceDiscoveryProtocol):
40
40
excluded_headers = ['DATE' , 'EXT' , 'SERVER' , 'CACHE-CONTROL' , 'LOCATION' ]
41
41
location_patter = r'yeelight://(?P<ip>\d{1,3}(\.\d{1,3}){3}):(?P<port>\d+)'
42
42
43
- def __init__ (self , bulb_class = Bulb , loop = None ):
43
+ def __init__ (self , bulb_class = Bulb , loop = None , ** kwargs ):
44
44
self .bulb_class = bulb_class
45
+ self .bulb_kwargs = kwargs
45
46
self .loop = loop or asyncio .get_event_loop ()
46
47
47
48
def connection_made (self , transport ):
@@ -94,7 +95,7 @@ def response_received(self, response, addr):
94
95
def register_bulb (self , ** kwargs ):
95
96
idx = kwargs ['id' ]
96
97
if idx not in bulbs :
97
- bulbs [idx ] = self .bulb_class (** kwargs , _registry = bulbs )
98
+ bulbs [idx ] = self .bulb_class (** kwargs , ** self . bulb_kwargs , _registry = bulbs )
98
99
else :
99
100
bulbs [idx ].last_seen = time .time ()
100
101
@@ -110,10 +111,12 @@ async def _restart():
110
111
asyncio .Task (_restart ())
111
112
112
113
113
- async def search_bulbs (bulb_class = Bulb , loop = None ):
114
+ async def search_bulbs (bulb_class = Bulb , loop = None , kwargs = None ):
114
115
if loop is None :
115
116
loop = asyncio .get_event_loop ()
117
+ if kwargs is None :
118
+ kwargs = {}
116
119
unicast_connection = loop .create_datagram_endpoint (
117
- lambda : YeelightProtocol (bulb_class ), family = socket .AF_INET )
120
+ lambda : YeelightProtocol (bulb_class , ** kwargs ), family = socket .AF_INET )
118
121
ucast_transport , _ = await unicast_connection
119
122
return bulbs
0 commit comments