-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Add config entry for LIFX #17201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add config entry for LIFX #17201
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "no_devices_found": "No LIFX devices found on the network.", | ||
| "single_instance_allowed": "Only a single configuration of LIFX is possible." | ||
| }, | ||
| "step": { | ||
| "confirm": { | ||
| "description": "Do you want to set up LIFX?", | ||
| "title": "LIFX" | ||
| } | ||
| }, | ||
| "title": "LIFX" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Component to embed LIFX.""" | ||
| import asyncio | ||
| import socket | ||
|
|
||
| import async_timeout | ||
| import voluptuous as vol | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.helpers import config_entry_flow | ||
| from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN | ||
|
|
||
|
|
||
| DOMAIN = 'lifx' | ||
| REQUIREMENTS = ['aiolifx==0.6.3'] | ||
|
|
||
| CONF_SERVER = 'server' | ||
| CONF_BROADCAST = 'broadcast' | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema({ | ||
| DOMAIN: { | ||
| LIGHT_DOMAIN: { | ||
| vol.Optional(CONF_SERVER): cv.string, | ||
| vol.Optional(CONF_BROADCAST): cv.string, | ||
| } | ||
| } | ||
| }, extra=vol.ALLOW_EXTRA) | ||
|
|
||
|
|
||
| async def async_setup(hass, config): | ||
| """Set up the LIFX component.""" | ||
| conf = config.get(DOMAIN) | ||
|
|
||
| hass.data[DOMAIN] = conf or {} | ||
|
|
||
| if conf is not None: | ||
| hass.async_create_task(hass.config_entries.flow.async_init( | ||
| DOMAIN, context={'source': config_entries.SOURCE_IMPORT})) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, entry): | ||
| """Set up LIFX from a config entry.""" | ||
| hass.async_create_task(hass.config_entries.async_forward_entry_setup( | ||
| entry, LIGHT_DOMAIN)) | ||
| return True | ||
|
|
||
|
|
||
| async def _async_has_devices(hass): | ||
| """Return if there are devices that can be discovered.""" | ||
| import aiolifx | ||
|
|
||
| manager = DiscoveryManager() | ||
| lifx_discovery = aiolifx.LifxDiscovery(hass.loop, manager) | ||
| coro = hass.loop.create_datagram_endpoint( | ||
| lambda: lifx_discovery, | ||
| family=socket.AF_INET) | ||
| hass.async_create_task(coro) | ||
|
|
||
| has_devices = await manager.found_devices() | ||
| lifx_discovery.cleanup() | ||
|
|
||
| return has_devices | ||
|
|
||
|
|
||
| config_entry_flow.register_discovery_flow( | ||
| DOMAIN, 'LIFX', _async_has_devices, config_entries.CONN_CLASS_LOCAL_POLL) | ||
|
|
||
|
|
||
| class DiscoveryManager: | ||
| """Temporary LIFX manager for discovering any bulb.""" | ||
|
|
||
| def __init__(self): | ||
| """Initialize the manager.""" | ||
| self._event = asyncio.Event() | ||
|
|
||
| async def found_devices(self): | ||
| """Return whether any device could be discovered.""" | ||
| try: | ||
| async with async_timeout.timeout(2): | ||
| await self._event.wait() | ||
|
|
||
| # Let bulbs recover from the discovery | ||
| await asyncio.sleep(1) | ||
|
|
||
| return True | ||
| except asyncio.TimeoutError: | ||
| return False | ||
|
|
||
| def register(self, bulb): | ||
| """Handle aiolifx detected bulb.""" | ||
| self._event.set() | ||
|
|
||
| def unregister(self, bulb): | ||
| """Handle aiolifx disappearing bulbs.""" | ||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "config": { | ||
| "title": "LIFX", | ||
| "step": { | ||
| "confirm": { | ||
| "title": "LIFX", | ||
| "description": "Do you want to set up LIFX?" | ||
| } | ||
| }, | ||
| "abort": { | ||
| "single_instance_allowed": "Only a single configuration of LIFX is possible.", | ||
| "no_devices_found": "No LIFX devices found on the network." | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,7 @@ async def async_step_discovery(info): | |
| 'hue', | ||
| 'ifttt', | ||
| 'ios', | ||
| 'lifx', | ||
| 'mqtt', | ||
| 'nest', | ||
| 'openuv', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.