-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add Unifi Led #27475
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 Unifi Led #27475
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
684b070
Added Unifi Led
db1ab3d
fixed manifest
a12569d
fixed style issue
c72e91c
removed unused setting
5f9a529
added sugested changes.
fa043e6
fixed order
78e0fbc
fixed settings that are required
5eb0702
Fix review issues
35dad4d
fix variable name that was too short
de2acc1
Testing something
085e7c0
Reverted to a previous version for testing
348f369
Reverted testing changes.
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
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 @@ | ||
| """Unifi LED Lights integration.""" |
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,105 @@ | ||
| """Support for Unifi Led lights.""" | ||
| import logging | ||
|
|
||
| from unifiled import unifiled | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, | ||
| PLATFORM_SCHEMA, | ||
| SUPPORT_BRIGHTNESS, | ||
| Light, | ||
| ) | ||
| from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| # Validation of the user's configuration | ||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( | ||
| { | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Required(CONF_USERNAME): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string, | ||
| vol.Optional(CONF_PORT, default=20443): vol.All(cv.port, cv.string), | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| """Set up the Unifi LED platform.""" | ||
|
|
||
| # Assign configuration variables. | ||
| # The configuration check takes care they are present. | ||
| host = config[CONF_HOST] | ||
| port = config[CONF_PORT] | ||
| username = config[CONF_USERNAME] | ||
| password = config[CONF_PASSWORD] | ||
|
|
||
| api = unifiled(host, port, username=username, password=password) | ||
|
|
||
| # Verify that passed in configuration works | ||
| if not api.getloginstate(): | ||
| _LOGGER.error("Could not connect to unifiled controller") | ||
| return | ||
|
|
||
| add_entities(UnifiLedLight(light, api) for light in api.getlights()) | ||
|
|
||
|
|
||
| class UnifiLedLight(Light): | ||
| """Representation of an unifiled Light.""" | ||
|
|
||
| def __init__(self, light, api): | ||
| """Init Unifi LED Light.""" | ||
|
|
||
| self._api = api | ||
| self._light = light | ||
| self._name = light["name"] | ||
| self._unique_id = light["id"] | ||
| self._state = light["status"]["output"] | ||
| self._brightness = self._api.convertfrom100to255(light["status"]["led"]) | ||
|
florisvdk marked this conversation as resolved.
|
||
| self._features = SUPPORT_BRIGHTNESS | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the display name of this light.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def brightness(self): | ||
| """Return the brightness name of this light.""" | ||
| return self._brightness | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| """Return the unique id of this light.""" | ||
| return self._unique_id | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if light is on.""" | ||
| return self._state | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Return the supported features of this light.""" | ||
| return self._features | ||
|
|
||
| def turn_on(self, **kwargs): | ||
| """Instruct the light to turn on.""" | ||
| self._api.setdevicebrightness( | ||
| self._unique_id, | ||
| str(self._api.convertfrom255to100(kwargs.get(ATTR_BRIGHTNESS, 255))), | ||
| ) | ||
| self._api.setdeviceoutput(self._unique_id, 1) | ||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Instruct the light to turn off.""" | ||
| self._api.setdeviceoutput(self._unique_id, 0) | ||
|
|
||
| def update(self): | ||
| """Update the light states.""" | ||
| self._state = self._api.getlightstate(self._unique_id) | ||
| self._brightness = self._api.convertfrom100to255( | ||
| self._api.getlightbrightness(self._unique_id) | ||
| ) | ||
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,8 @@ | ||
| { | ||
| "domain": "unifiled", | ||
| "name": "Unifi LED", | ||
| "documentation": "https://www.home-assistant.io/integrations/unifiled", | ||
| "dependencies": [], | ||
| "codeowners": ["@florisvdk"], | ||
| "requirements": ["unifiled==0.10"] | ||
| } |
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.