Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ omit =
homeassistant/components/light/decora.py
homeassistant/components/light/decora_wifi.py
homeassistant/components/light/flux_led.py
homeassistant/components/light/greenwave.py
homeassistant/components/light/hue.py
homeassistant/components/light/hyperion.py
homeassistant/components/light/lifx.py
Expand Down
112 changes: 112 additions & 0 deletions homeassistant/components/light/greenwave.py
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)
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both are required.


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']
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ googlemaps==2.5.1
# homeassistant.components.sensor.gpsd
gps3==0.33.3

# homeassistant.components.light.greenwave
greenwavereality==0.2.9

# homeassistant.components.media_player.gstreamer
gstreamer-player==1.1.0

Expand Down