Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -367,6 +367,7 @@ omit =
homeassistant/components/light/flux_led.py
homeassistant/components/light/hue.py
homeassistant/components/light/hyperion.py
homeassistant/components/light/iglo.py
homeassistant/components/light/lifx.py
homeassistant/components/light/lifx_legacy.py
homeassistant/components/light/limitlessled.py
Expand Down
126 changes: 126 additions & 0 deletions homeassistant/components/light/iglo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
Support for lights under the iGlo brand.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.iglo/
"""
import logging

import voluptuous as vol

from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PORT)
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP,
SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR,
Light, PLATFORM_SCHEMA

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SyntaxError: invalid syntax

)

import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['iglo==1.0.0']

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'iGlo Light'
DEFAULT_PORT = 8080

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.string,
})


def setup_platform(hass, config, add_devices, discovery_info=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

"""Set up the iGlo lighs."""
host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
port = config.get(CONF_PORT)
add_devices([IGloLamp(name, host, port)])

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.

Use True as second parameter.

I assume that there will be a exception of the device is not present.



class IGloLamp(Light):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

"""Representation of an iGlo light."""

def __init__(self, name, host, port):
"""Initialize the light."""
from iglo import Lamp
self._name = name
self._host = host

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.

Not used.

self._port = port

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.

Dito.

self._lamp = Lamp(0, host, port)
self.update()

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.

See above.

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.

See above.

self._on = True

@property
def name(self):
"""Return the name of the light."""
return self._name

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return int((self._brightness / 200.0) * 255)

@property
def color_temp(self):
"""Return the color temperature."""
return self._color_temp

@property
def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
return 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just saw this merged so I know I am too late to the party.

Anyway, this is supposed to be in mired, the unknown "reciprocal megakelvin" unit.

You find the mired value with this formula: 1000000/kelvin. So if the light does 7000 Kelvin as its coldest white, the min_mired value should be 143.

Same goes for max_mireds and color_temp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't really understand the mirad thing, but the lights accept a colour temp value between 1 and 255 to change between warm and cool white. Maybe I will look into it more once I move back into the part of my house with my new lights and start using this on my main HA.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doing it this way will mean that examples for other lights do not work properly. It also breaks the kelvin alias for white temperature.

But now you know where the problem is, once you notice :)


@property
def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
return 255

@property
def rgb_color(self):
"""Return the RGB value."""
return self._rgb

@property
def supported_features(self):
"""Flag supported features."""
return (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR)

@property
def is_on(self):
"""Return true if light is on."""
return self._on

def turn_on(self, **kwargs):
"""Turn the light on."""
if not self._on:
self._lamp.switch(True)
self._on = True

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 shouldn't change any instance attributes that store state in the turn on/off methods. The update method will be called after turn_on or turn_off is called, since this is a polling entity, so state will be updated that way.

if ATTR_BRIGHTNESS in kwargs:
self._brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0)

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.

See above.

self._lamp.brightness(self._brightness)
return

if ATTR_RGB_COLOR in kwargs:
self._rgb = kwargs[ATTR_RGB_COLOR]

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.

See above.

self._lamp.rgb(*self._rgb)
return

if ATTR_COLOR_TEMP in kwargs:
self._color_temp = 255 - kwargs[ATTR_COLOR_TEMP]

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.

See above.

self._lamp.white(self._color_temp)
return

def turn_off(self, **kwargs):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too many blank lines (2)

"""Turn the light off."""
self._on = False

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.

See above.

self._lamp.switch(False)

def update(self):
"""Update light status."""
state = self._lamp.state()
self._on = state['on']
self._brightness = state['brightness']
self._rgb = state['rgb']
self._color_temp = 255 - state['white']
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ https://github.com/wokar/pylgnetcast/archive/v0.2.0.zip#pylgnetcast==0.2.0
# homeassistant.components.sensor.htu21d
# i2csense==0.0.4

# homeassistant.components.light.iglo
iglo==1.0.0

# homeassistant.components.influxdb
# homeassistant.components.sensor.influxdb
influxdb==4.1.1
Expand Down