Move imports in piglow component (#28046)
* Move imports in piglow component * Fix pylint
This commit is contained in:
parent
6c39d77e23
commit
4935ef5233
1 changed files with 13 additions and 15 deletions
|
@ -2,18 +2,19 @@
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
import piglow
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
Light,
|
||||
PLATFORM_SCHEMA,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -29,23 +30,20 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Piglow Light platform."""
|
||||
import piglow
|
||||
|
||||
if subprocess.getoutput("i2cdetect -q -y 1 | grep -o 54") != "54":
|
||||
_LOGGER.error("A Piglow device was not found")
|
||||
return False
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
|
||||
add_entities([PiglowLight(piglow, name)])
|
||||
add_entities([PiglowLight(name)])
|
||||
|
||||
|
||||
class PiglowLight(Light):
|
||||
"""Representation of an Piglow Light."""
|
||||
|
||||
def __init__(self, piglow, name):
|
||||
def __init__(self, name):
|
||||
"""Initialize an PiglowLight."""
|
||||
self._piglow = piglow
|
||||
self._name = name
|
||||
self._is_on = False
|
||||
self._brightness = 255
|
||||
|
@ -88,7 +86,7 @@ class PiglowLight(Light):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Instruct the light to turn on."""
|
||||
self._piglow.clear()
|
||||
piglow.clear()
|
||||
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
|
@ -99,16 +97,16 @@ class PiglowLight(Light):
|
|||
rgb = color_util.color_hsv_to_RGB(
|
||||
self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100
|
||||
)
|
||||
self._piglow.red(rgb[0])
|
||||
self._piglow.green(rgb[1])
|
||||
self._piglow.blue(rgb[2])
|
||||
self._piglow.show()
|
||||
piglow.red(rgb[0])
|
||||
piglow.green(rgb[1])
|
||||
piglow.blue(rgb[2])
|
||||
piglow.show()
|
||||
self._is_on = True
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Instruct the light to turn off."""
|
||||
self._piglow.clear()
|
||||
self._piglow.show()
|
||||
piglow.clear()
|
||||
piglow.show()
|
||||
self._is_on = False
|
||||
self.schedule_update_ha_state()
|
||||
|
|
Loading…
Add table
Reference in a new issue