You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
881 B

4 years ago
  1. """Discover Yeelight bulbs, based on Kodi discoverable."""
  2. from . import MDNSDiscoverable
  3. from ..const import ATTR_DEVICE_TYPE
  4. DEVICE_NAME_PREFIX = 'yeelink-light-'
  5. class Discoverable(MDNSDiscoverable):
  6. """Add support for discovering Yeelight."""
  7. def __init__(self, nd):
  8. """Initialize the Yeelight discovery."""
  9. super(Discoverable, self).__init__(nd, '_miio._udp.local.')
  10. def info_from_entry(self, entry):
  11. """Return most important info from mDNS entries."""
  12. info = super().info_from_entry(entry)
  13. # Example name: yeelink-light-ceiling4_mibt72799069._miio._udp.local.
  14. info[ATTR_DEVICE_TYPE] = \
  15. entry.name.replace(DEVICE_NAME_PREFIX, '').split('_', 1)[0]
  16. return info
  17. def get_entries(self):
  18. """ Return yeelight devices. """
  19. return self.find_by_device_name(DEVICE_NAME_PREFIX)