8000 0.50.2 by balloob · Pull Request #8757 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

0.50.2 #8757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 1, 2017
Merged

0.50.2 #8757

Show file tree
Hide file tree
Changes from all 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
9 changes: 3 additions & 6 deletions homeassistant/components/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def post(self, request):

if 'simple' in intent_response.card:
alexa_response.add_card(
'simple', intent_response.card['simple']['title'],
CardType.simple, intent_response.card['simple']['title'],
intent_response.card['simple']['content'])

return self.json(alexa_response)
Expand Down Expand Up @@ -208,8 +208,8 @@ def add_card(self, card_type, title, content):
self.card = card
return

card["title"] = title.async_render(self.variables)
card["content"] = content.async_render(self.variables)
card["title"] = title
card["content"] = content
self.card = card

def add_speech(self, speech_type, text):
Expand All @@ -218,9 +218,6 @@ def add_speech(self, speech_type, text):

key = 'ssml' if speech_type == SpeechType.ssml else 'text'

if isinstance(text, template.Template):
text = text.async_render(self.variables)

self.speech = {
'type': speech_type.value,
key: text
Expand Down
55 changes: 39 additions & 16 deletions homeassistant/components/cover/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ def get_device(hass, values, node_config, **kwargs):
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL
and values.primary.index == 0):
return ZwaveRollershutter(hass, values, invert_buttons)
elif (values.primary.command_class in [
zwave.const.COMMAND_CLASS_SWITCH_BINARY,
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR]):
return ZwaveGarageDoor(values)
elif (values.primary.command_class ==
zwave.const.COMMAND_CLASS_SWITCH_BINARY):
return ZwaveGarageDoorSwitch(values)
elif (values.primary.command_class ==
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR):
return ZwaveGarageDoorBarrier(values)
return None


Expand Down Expand Up @@ -104,8 +106,8 @@ def stop_cover(self, **kwargs):
self._network.manager.releaseButton(self._open_id)


class ZwaveGarageDoor(zwave.ZWaveDeviceEntity, CoverDevice):
"""Representation of an Zwave garage door device."""
class ZwaveGarageDoorBase(zwave.ZWaveDeviceEntity, CoverDevice):
"""Base class for a Zwave garage door device."""

def __init__(self, values):
"""Initialize the zwave garage door."""
Expand All @@ -118,6 +120,37 @@ def update_properties(self):
self._state = self.values.primary.data
_LOGGER.debug("self._state=%s", self._state)

@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return 'garage'

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_GARAGE


class ZwaveGarageDoorSwitch(ZwaveGarageDoorBase):
"""Representation of a switch based Zwave garage door device."""

@property
def is_closed(self):
"""Return the current position of Zwave garage door."""
return not self._state

def close_cover(self):
"""Close the garage door."""
self.values.primary.data = False

def open_cover(self):
"""Open the garage door."""
self.values.primary.data = True


class ZwaveGarageDoorBarrier(ZwaveGarageDoorBase):
"""Representation of a barrier operator Zwave garage door device."""

@property
def is_opening(self):
"""Return true if cover is in an opening state."""
Expand All @@ -140,13 +173,3 @@ def close_cover(self):
def open_cover(self):
"""Open the garage door."""
self.values.primary.data = "Opened"

@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return 'garage'

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_GARAGE
31 changes: 15 additions & 16 deletions homeassistant/components/light/tplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

def brightness_to_percentage(byt):
"""Convert brightness from absolute 0..255 to percentage."""
return (byt*100.0)/255.0
return int((byt*100.0)/255.0)


def brightness_from_percentage(percent):
Expand All @@ -53,6 +53,8 @@ def __init__(self, smartbulb, name):
self._name = name

self._state = None
self._color_temp = None
self._brightness = None
_LOGGER.debug("Setting up TP-Link Smart Bulb")

@property
Expand All @@ -70,7 +72,6 @@ def turn_on(self, **kwargs):
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)
self.smartbulb.brightness = brightness_to_percentage(brightness)

self.smartbulb.state = self.smartbulb.BULB_STATE_ON

def turn_off(self):
Expand All @@ -80,33 +81,31 @@ def turn_off(self):
@property
def color_temp(self):
"""Return the color temperature of this light in mireds for HA."""
if self.smartbulb.is_color:
if (self.smartbulb.color_temp is not None and
self.smartbulb.color_temp != 0):
return kelvin_to_mired(self.smartbulb.color_temp)
else:
return None
else:
return None
return self._color_temp

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return brightness_from_percentage(self.smartbulb.brightness)
return self._brightness

@property
def is_on(self):
"""True if device is on."""
return self.smartbulb.state == \
self.smartbulb.BULB_STATE_ON
return self._state

def update(self):
"""Update the TP-Link Bulb's state."""
from pyHS100 import SmartPlugException
try:
self._state = self.smartbulb.state == \
self.smartbulb.BULB_STATE_ON

self._state = (
self.smartbulb.state == self.smartbulb.BULB_STATE_ON)
self._brightness = brightness_from_percentage(
self.smartbulb.brightness)
if self.smartbulb.is_color:
if (self.smartbulb.color_temp is not None and
self.smartbulb.color_temp != 0):
self._color_temp = kelvin_to_mired(
self.smartbulb.color_temp)
except (SmartPlugException, OSError) as ex:
_LOGGER.warning('Could not read state for %s: %s', self.name, ex)

Expand Down
16 changes: 12 additions & 4 deletions 16 homeassistant/components/light/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def brightness(self):

def turn_off(self, **kwargs):
"""Instruct the group lights to turn off."""
return self._group.set_state(0)
self._group.set_state(0)

def turn_on(self, **kwargs):
"""Instruct the group lights to turn on, or dim."""
Expand All @@ -82,7 +82,11 @@ def turn_on(self, **kwargs):

def update(self):
"""Fetch new state data for this group."""
self._group.update()
from pytradfri import RequestTimeout
try:
self._group.update()
except RequestTimeout:
_LOGGER.warning("Tradfri update request timed out")


class Tradfri(Light):
Expand Down Expand Up @@ -153,7 +157,7 @@ def rgb_color(self):

def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
return self._light_control.set_state(False)
self._light_control.set_state(False)

def turn_on(self, **kwargs):
"""
Expand Down Expand Up @@ -181,7 +185,11 @@ def turn_on(self, **kwargs):

def update(self):
"""Fetch new state data for this light."""
self._light.update()
from pytradfri import RequestTimeout
try:
self._light.update()
except RequestTimeout:
_LOGGER.warning("Tradfri update request timed out")

# Handle Hue lights paired with the gateway
# hex_color is 0 when bulb is unreachable
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/media_player/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def async_on_quit(self, sender, data):
self._properties = {}
self._item = {}
self._app_properties = {}
self.hass.async_add_job(self.async_update_ha_state())
self.hass.async_add_job(self._ws_server.close())

@asyncio.coroutine
def _get_players(self):
Expand Down Expand Up @@ -410,6 +410,8 @@ def ws_loop_wrapper():
# Kodi abruptly ends ws connection when exiting. We will try
# to reconnect on the next poll.
pass
# Update HA state after Kodi disconnects
self.hass.async_add_job(self.async_update_ha_state())

# Create a task instead of adding a tracking job, since this task will
# run until the websocket connection is closed.
Expand Down
15 changes: 7 additions & 8 deletions homeassistant/components/media_player/pioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ def telnet_request(cls, telnet, command, expected_prefix):
return None

def telnet_command(self, command):
"""Establish a telnet connection and sends `command`."""
"""Establish a telnet connection and sends command."""
try:
try:
telnet = telnetlib.Telnet(self._host,
self._port,
self._timeout)
except ConnectionRefusedError:
_LOGGER.debug("Pioneer %s refused connection", self._name)
telnet = telnetlib.Telnet(
self._host, self._port, self._timeout)
except (ConnectionRefusedError, OSError):
_LOGGER.warning("Pioneer %s refused connection", self._name)
return
telnet.write(command.encode("ASCII") + b"\r")
telnet.read_very_eager() # skip response
Expand All @@ -105,8 +104,8 @@ def update(self):
"""Get the latest details from the device."""
try:
telnet = telnetlib.Telnet(self._host, self._port, self._timeout)
except ConnectionRefusedError:
_LOGGER.debug("Pioneer %s refused connection", self._name)
except (ConnectionRefusedError, OSError):
_LOGGER.warning("Pioneer %s refused connection", self._name)
return False

pwstate = self.telnet_request(telnet, "?P", "PWR")
Expand Down
Loading
0