diff --git a/netdisco/discoverables/yeelight.py b/netdisco/discoverables/yeelight.py index e223556f..ba2f9dbf 100644 --- a/netdisco/discoverables/yeelight.py +++ b/netdisco/discoverables/yeelight.py @@ -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): @@ -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)