Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 17 additions & 10 deletions homeassistant/components/light/greenwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from homeassistant.const import CONF_HOST
import homeassistant.helpers.config_validation as cv

SUPPORTED_FEATURES = (SUPPORT_BRIGHTNESS)
SUPPORTED_FEATURES = SUPPORT_BRIGHTNESS

REQUIREMENTS = ['greenwavereality==0.2.9']
REQUIREMENTS = ['greenwavereality==0.4.1']
_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand All @@ -36,14 +36,20 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
token = tokenfile.read()
tokenfile.close()
else:
token = greenwave.grab_token(host, 'hass', 'homeassistant')
try:
token = greenwave.grab_token(host, 'hass', 'homeassistant')
except PermissionError:
_LOGGER.error('The Gateway Is Not In Sync Mode')
raise
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)
for room in doc:
add_devices(GreenwaveLight(device, host, token)
for device in room['device'])


class GreenwaveLight(Light):
Expand Down Expand Up @@ -104,9 +110,10 @@ def update(self):
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']
for room in doc:
for device in room['device']:
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']

@pvizeli pvizeli Jan 22, 2018

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.

That is a realy bad runtime. Make a data object like this: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/sensor/yweather.py#L174-L190
On this data object you can map it to a usefuly data format and access without loop.

Your code actual:

  • Hit the device with 10x bulbs it call the gateway 10x times
  • Loop over 1000x

2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ googlemaps==2.5.1
gps3==0.33.3

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

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