Skip to content

Commit

Permalink
update flux led
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel authored and Daniel committed Jul 18, 2016
1 parent 7aa3fd9 commit 3d7f5f9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions homeassistant/components/light/flux_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def _valid_lights(value):
return config

PLATFORM_SCHEMA = vol.Schema({
vol.Required("platform"): DOMAIN,
vol.Optional('devices', default={}): vol.All(dict, _valid_lights),
vol.Required('platform'): DOMAIN,
vol.Optional('devices', default={}): {cv.string: DEVICE_SCHEMA},
vol.Optional('automatic_add', default=False): cv.boolean,
}, extra=vol.ALLOW_EXTRA)

Expand All @@ -47,13 +47,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
light_ips = []
for ipaddr, device_config in config["devices"].items():
device = {}
device["id"] = device_config[ATTR_NAME]
device["ipaddr"] = ipaddr
device['id'] = device_config[ATTR_NAME]
device['ipaddr'] = ipaddr
light = FluxLight(device)
if light.is_valid:
lights.append(light)
light_ips.append(ipaddr)

if not config['automatic_add']:
add_devices_callback(lights)
return

# Find the bulbs on the LAN
scanner = flux_led.BulbScanner()
scanner.scan(timeout=20)
Expand All @@ -76,21 +80,21 @@ def __init__(self, device):
import flux_led

self._name = device['id']
ipaddr = device['ipaddr']
self._ipaddr = device['ipaddr']
self.is_valid = True
self._bulb = None
try:
self._bulb = flux_led.WifiLedBulb(ipaddr)
self._bulb = flux_led.WifiLedBulb(self._ipaddr)
except socket.error:
self.is_valid = False
_LOGGER.error("Failed to connect to bulb %s, %s",
ipaddr, self._name)
self._ipaddr, self._name)

@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(
self.__class__, self._name)
self.__class__, self._ipaddr)

@property
def name(self):
Expand All @@ -100,7 +104,6 @@ def name(self):
@property
def is_on(self):
"""Return true if device is on."""
self.update()
return self._bulb.isOn()

def turn_on(self, **kwargs):
Expand Down

0 comments on commit 3d7f5f9

Please sign in to comment.