-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Greenwave Reality (TCP Connected) Lighting Component #11282
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac0bf3e
Create greenwave.py
dfiel 8b53e74
Update .coveragerc
dfiel d70d478
Update requirements_all.txt
dfiel a44e843
Update greenwave.py
dfiel def8448
Update greenwave.py
dfiel 6f5fd03
Update requirements_all.txt
dfiel 7583a2f
Update greenwave.py
dfiel e9b35a3
Update greenwave.py
dfiel 8d462bc
fix style
pvizeli 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,112 @@ | ||
| """ | ||
| Support for Greenwave Reality (TCP Connected) lights. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/light.greenwave/ | ||
| """ | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, Light, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS) | ||
| from homeassistant.const import CONF_HOST | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| SUPPORTED_FEATURES = (SUPPORT_BRIGHTNESS) | ||
|
|
||
| REQUIREMENTS = ['greenwavereality==0.2.9'] | ||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Required("version"): cv.positive_int, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Setup Greenwave Reality Platform.""" | ||
| import greenwavereality as greenwave | ||
| import os | ||
| host = config.get(CONF_HOST) | ||
| tokenfile = hass.config.path('.greenwave') | ||
| if config.get("version") == 3: | ||
| if os.path.exists(tokenfile): | ||
| tokenfile = open(tokenfile) | ||
| token = tokenfile.read() | ||
| tokenfile.close() | ||
| else: | ||
| token = greenwave.grab_token(host, 'hass', 'homeassistant') | ||
| tokenfile = open(tokenfile, "w+") | ||
| tokenfile.write(token) | ||
| tokenfile.close() | ||
| else: | ||
| token = None | ||
| doc = greenwave.grab_xml(host, token) | ||
| add_devices(GreenwaveLight(device, host, token) for device in doc) | ||
|
|
||
|
|
||
| class GreenwaveLight(Light): | ||
| """Representation of an Greenwave Reality Light.""" | ||
|
|
||
| def __init__(self, light, host, token): | ||
| """Initialize a Greenwave Reality Light.""" | ||
| import greenwavereality as greenwave | ||
| self._did = light['did'] | ||
| self._name = light['name'] | ||
| self._state = int(light['state']) | ||
| self._brightness = greenwave.hass_brightness(light) | ||
| self._host = host | ||
| self._online = greenwave.check_online(light) | ||
| self.token = token | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Flag supported features.""" | ||
| return SUPPORTED_FEATURES | ||
|
|
||
| @property | ||
| def available(self): | ||
| """Return True if entity is available.""" | ||
| return self._online | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the display name of this light.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def brightness(self): | ||
| """Return the brightness of the light.""" | ||
| return self._brightness | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if light is on.""" | ||
| return self._state | ||
|
|
||
| def turn_on(self, **kwargs): | ||
| """Instruct the light to turn on.""" | ||
| import greenwavereality as greenwave | ||
| temp_brightness = int((kwargs.get(ATTR_BRIGHTNESS, 255) | ||
| / 255) * 100) | ||
| greenwave.set_brightness(self._host, self._did, | ||
| temp_brightness, self.token) | ||
| greenwave.turn_on(self._host, self._did, self.token) | ||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Instruct the light to turn off.""" | ||
| import greenwavereality as greenwave | ||
| greenwave.turn_off(self._host, self._did, self.token) | ||
|
|
||
| def update(self): | ||
| """Fetch new state data for this light.""" | ||
| import greenwavereality as greenwave | ||
| doc = greenwave.grab_xml(self._host, self.token) | ||
|
|
||
| for device in doc: | ||
| if device['did'] == self._did: | ||
| self._state = int(device['state']) | ||
| self._brightness = greenwave.hass_brightness(device) | ||
| self._online = greenwave.check_online(device) | ||
| self._name = device['name'] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are sure that is also need to send a brightness and after that also a on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, both are required.