Skip to content

Commit 57b525a

Browse files
committed
Allow custom kwargs being passed to bulb during init
1 parent 3f4a34d commit 57b525a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

yeelib/discover.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class YeelightProtocol(SimpleServiceDiscoveryProtocol):
4040
excluded_headers = ['DATE', 'EXT', 'SERVER', 'CACHE-CONTROL', 'LOCATION']
4141
location_patter = r'yeelight://(?P<ip>\d{1,3}(\.\d{1,3}){3}):(?P<port>\d+)'
4242

43-
def __init__(self, bulb_class=Bulb, loop=None):
43+
def __init__(self, bulb_class=Bulb, loop=None, **kwargs):
4444
self.bulb_class = bulb_class
45+
self.bulb_kwargs = kwargs
4546
self.loop = loop or asyncio.get_event_loop()
4647

4748
def connection_made(self, transport):
@@ -94,7 +95,7 @@ def response_received(self, response, addr):
9495
def register_bulb(self, **kwargs):
9596
idx = kwargs['id']
9697
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)
9899
else:
99100
bulbs[idx].last_seen = time.time()
100101

@@ -110,10 +111,12 @@ async def _restart():
110111
asyncio.Task(_restart())
111112

112113

113-
async def search_bulbs(bulb_class=Bulb, loop=None):
114+
async def search_bulbs(bulb_class=Bulb, loop=None, kwargs=None):
114115
if loop is None:
115116
loop = asyncio.get_event_loop()
117+
if kwargs is None:
118+
kwargs = {}
116119
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)
118121
ucast_transport, _ = await unicast_connection
119122
return bulbs

0 commit comments

Comments
 (0)