Skip to content

Commit

Permalink
Pass the device name without mapping to the component (home-assistant…
Browse files Browse the repository at this point in the history
…-libs#184)

* mDNS prefix of the Yeelight Ceiling Light 4 (Jiaoyue 650) added

* Pass the device name to the component

* Keep the old mapping for stable entity ids

* Unused import removed

* Indent added

* Mapping removed
  • Loading branch information
syssi authored and balloob committed Apr 8, 2018
1 parent 4138a58 commit 5b4ff1e
Showing 1 changed file with 7 additions and 19 deletions.
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)

0 comments on commit 5b4ff1e

Please sign in to comment.