mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Nanoleaf availability check (#21945)
* Added availability check for nanoleaf lights * pylint errors fixed * pynanoleaf bump
This commit is contained in:
parent
deb66bb748
commit
cac8e34841
@ -19,7 +19,7 @@ from homeassistant.util.color import \
|
|||||||
color_temperature_mired_to_kelvin as mired_to_kelvin
|
color_temperature_mired_to_kelvin as mired_to_kelvin
|
||||||
from homeassistant.util.json import load_json, save_json
|
from homeassistant.util.json import load_json, save_json
|
||||||
|
|
||||||
REQUIREMENTS = ['pynanoleaf==0.0.2']
|
REQUIREMENTS = ['pynanoleaf==0.0.5']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Nanoleaf light."""
|
"""Set up the Nanoleaf light."""
|
||||||
import pynanoleaf
|
from pynanoleaf import Nanoleaf, Unavailable
|
||||||
if DATA_NANOLEAF not in hass.data:
|
if DATA_NANOLEAF not in hass.data:
|
||||||
hass.data[DATA_NANOLEAF] = dict()
|
hass.data[DATA_NANOLEAF] = dict()
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
name = config[CONF_NAME]
|
name = config[CONF_NAME]
|
||||||
token = config[CONF_TOKEN]
|
token = config[CONF_TOKEN]
|
||||||
|
|
||||||
nanoleaf_light = pynanoleaf.Nanoleaf(host)
|
nanoleaf_light = Nanoleaf(host)
|
||||||
|
|
||||||
if not token:
|
if not token:
|
||||||
token = nanoleaf_light.request_token()
|
token = nanoleaf_light.request_token()
|
||||||
@ -78,7 +78,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
nanoleaf_light.token = token
|
nanoleaf_light.token = token
|
||||||
|
|
||||||
if nanoleaf_light.on is None:
|
try:
|
||||||
|
nanoleaf_light.available
|
||||||
|
except Unavailable:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Could not connect to Nanoleaf Light: %s on %s", name, host)
|
"Could not connect to Nanoleaf Light: %s on %s", name, host)
|
||||||
return
|
return
|
||||||
@ -92,6 +94,7 @@ class NanoleafLight(Light):
|
|||||||
|
|
||||||
def __init__(self, light, name):
|
def __init__(self, light, name):
|
||||||
"""Initialize an Nanoleaf light."""
|
"""Initialize an Nanoleaf light."""
|
||||||
|
self._available = True
|
||||||
self._brightness = None
|
self._brightness = None
|
||||||
self._color_temp = None
|
self._color_temp = None
|
||||||
self._effect = None
|
self._effect = None
|
||||||
@ -101,6 +104,11 @@ class NanoleafLight(Light):
|
|||||||
self._hs_color = None
|
self._hs_color = None
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return availability."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light."""
|
||||||
@ -187,9 +195,15 @@ class NanoleafLight(Light):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
self._brightness = self._light.brightness
|
try:
|
||||||
self._color_temp = self._light.color_temperature
|
self._available = self._light.available
|
||||||
self._effect = self._light.effect
|
self._brightness = self._light.brightness
|
||||||
self._effects_list = self._light.effects
|
self._color_temp = self._light.color_temperature
|
||||||
self._hs_color = self._light.hue, self._light.saturation
|
self._effect = self._light.effect
|
||||||
self._state = self._light.on
|
self._effects_list = self._light.effects
|
||||||
|
self._hs_color = self._light.hue, self._light.saturation
|
||||||
|
self._state = self._light.on
|
||||||
|
except Exception as err: # pylint:disable=broad-except
|
||||||
|
_LOGGER.error("Could not update status for %s (%s)",
|
||||||
|
self.name, err)
|
||||||
|
self._available = False
|
||||||
|
@ -1174,7 +1174,7 @@ pymyq==1.1.0
|
|||||||
pymysensors==0.18.0
|
pymysensors==0.18.0
|
||||||
|
|
||||||
# homeassistant.components.light.nanoleaf
|
# homeassistant.components.light.nanoleaf
|
||||||
pynanoleaf==0.0.2
|
pynanoleaf==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.lock.nello
|
# homeassistant.components.lock.nello
|
||||||
pynello==2.0.2
|
pynello==2.0.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user