Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions netdisco/discoverables/yeelight.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Discover Yeelight bulbs, based on Kodi discoverable."""
import logging
from . import MDNSDiscoverable
from ..const import ATTR_DEVICE_TYPE

DEVICE_NAME_PREFIX = 'yeelink-light-'


# pylint: disable=too-few-public-methods
class Discoverable(MDNSDiscoverable):
Expand All @@ -16,25 +17,12 @@ def info_from_entry(self, entry):
"""Return most important info from mDNS entries."""
info = super().info_from_entry(entry)

device_type = "UNKNOWN"
if entry.name.startswith("yeelink-light-color1_"):
device_type = "rgb"
elif entry.name.startswith("yeelink-light-mono1_"):
device_type = "white"
elif entry.name.startswith("yeelink-light-strip1_"):
device_type = "strip"
elif entry.name.startswith("yeelink-light-bslamp1_"):
device_type = "bedside"
elif entry.name.startswith("yeelink-light-ceiling1_"):
device_type = "ceiling"
elif entry.name.startswith("yeelink-light-ceiling2_"):
device_type = "ceiling2"
else:
logging.warning("Unknown miio device found: %s", entry)

info[ATTR_DEVICE_TYPE] = device_type
# Example name: yeelink-light-ceiling4_mibt72799069._miio._udp.local.
info[ATTR_DEVICE_TYPE] = \
entry.name.replace(DEVICE_NAME_PREFIX, '').rsplit('_', 1)[0]

return info

def get_entries(self):
""" Return yeelight devices. """
return self.find_by_device_name('yeelink-light-')
return self.find_by_device_name(DEVICE_NAME_PREFIX)