Skip to content

Commit

Permalink
Merge pull request home-assistant#5032 from home-assistant/release-0-…
Browse files Browse the repository at this point in the history
…35-3

0.35.3
  • Loading branch information
balloob authored Dec 23, 2016
2 parents 3ea984c + 203c1cf commit 308d71c
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 73 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/alarm_control_panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def async_alarm_service_handler(service):
update_coro = hass.loop.create_task(
alarm.async_update_ha_state(True))
if hasattr(alarm, 'async_update'):
update_tasks.append(hass.loop.create_task(update_coro))
update_tasks.append(update_coro)
else:
yield from update_coro

Expand Down
18 changes: 9 additions & 9 deletions homeassistant/components/binary_sensor/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.components.sensor.nest import NestSensor
from homeassistant.const import (CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS)
from homeassistant.components.nest import (
DATA_NEST, is_thermostat, is_camera)
from homeassistant.components.nest import DATA_NEST
import homeassistant.helpers.config_validation as cv

DEPENDENCIES = ['nest']
Expand Down Expand Up @@ -76,19 +75,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error(wstr)

sensors = []
device_chain = chain(nest.devices(),
nest.protect_devices(),
nest.camera_devices())
device_chain = chain(nest.thermostats(),
nest.smoke_co_alarms(),
nest.cameras())
for structure, device in device_chain:
sensors += [NestBinarySensor(structure, device, variable)
for variable in conf
if variable in BINARY_TYPES]
sensors += [NestBinarySensor(structure, device, variable)
for variable in conf
if variable in CLIMATE_BINARY_TYPES
and is_thermostat(device)]
and device.is_thermostat]

if is_camera(device):
if device.is_camera:
sensors += [NestBinarySensor(structure, device, variable)
for variable in conf
if variable in CAMERA_BINARY_TYPES]
Expand Down Expand Up @@ -118,13 +117,14 @@ class NestActivityZoneSensor(NestBinarySensor):

def __init__(self, structure, device, zone):
"""Initialize the sensor."""
super(NestActivityZoneSensor, self).__init__(structure, device, None)
super(NestActivityZoneSensor, self).__init__(structure, device, "")
self.zone = zone
self._name = "{} {} activity".format(self._name, self.zone.name)

@property
def name(self):
"""Return the name of the nest, if any."""
return "{} {} activity".format(self._name, self.zone.name)
return self._name

def update(self):
"""Retrieve latest state."""
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/camera/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if discovery_info is None:
return

camera_devices = hass.data[nest.DATA_NEST].camera_devices()
camera_devices = hass.data[nest.DATA_NEST].cameras()
cameras = [NestCamera(structure, device)
for structure, device in camera_devices]
add_devices(cameras, True)
Expand All @@ -43,7 +43,7 @@ def __init__(self, structure, device):
self.device = device
self._location = None
self._name = None
self._is_online = None
self._online = None
self._is_streaming = None
self._is_video_history_enabled = False
# Default to non-NestAware subscribed, but will be fixed during update
Expand Down Expand Up @@ -76,7 +76,7 @@ def update(self):
"""Cache value from Python-nest."""
self._location = self.device.where
self._name = self.device.name
self._is_online = self.device.is_online
self._online = self.device.online
self._is_streaming = self.device.is_streaming
self._is_video_history_enabled = self.device.is_video_history_enabled

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/climate/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

add_devices(
[NestThermostat(structure, device, temp_unit)
for structure, device in hass.data[DATA_NEST].devices()],
for structure, device in hass.data[DATA_NEST].thermostats()],
True
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def async_handle_light_service(service):
update_coro = hass.loop.create_task(
light.async_update_ha_state(True))
if hasattr(light, 'async_update'):
update_tasks.append(hass.loop.create_task(update_coro))
update_tasks.append(update_coro)
else:
yield from update_coro

Expand Down
37 changes: 11 additions & 26 deletions homeassistant/components/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

REQUIREMENTS = [
'http://github.com/technicalpickles/python-nest'
'/archive/b8391d2b3cb8682f8b0c2bdff477179983609f39.zip' # nest-cam branch
'#python-nest==3.0.2']
'/archive/e6c9d56a8df455d4d7746389811f2c1387e8cb33.zip' # nest-cam branch
'#python-nest==3.0.3']

DOMAIN = 'nest'

Expand Down Expand Up @@ -132,12 +132,12 @@ def __init__(self, hass, conf, nest):
self._structure = conf[CONF_STRUCTURE]
_LOGGER.debug("Structures to include: %s", self._structure)

def devices(self):
"""Generator returning list of devices and their location."""
def thermostats(self):
"""Generator returning list of thermostats and their location."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
for device in structure.devices:
for device in structure.thermostats:
yield (structure, device)
else:
_LOGGER.debug("Ignoring structure %s, not in %s",
Expand All @@ -146,12 +146,12 @@ def devices(self):
_LOGGER.error(
"Connection error logging into the nest web service.")

def protect_devices(self):
"""Generator returning list of protect devices."""
def smoke_co_alarms(self):
"""Generator returning list of smoke co alarams."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
for device in structure.protectdevices:
for device in structure.smoke_co_alarms:
yield(structure, device)
else:
_LOGGER.info("Ignoring structure %s, not in %s",
Expand All @@ -160,31 +160,16 @@ def protect_devices(self):
_LOGGER.error(
"Connection error logging into the nest web service.")

def camera_devices(self):
"""Generator returning list of camera devices."""
def cameras(self):
"""Generator returning list of cameras."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
for device in structure.cameradevices:
for device in structure.cameras:
yield(structure, device)
else:
_LOGGER.info("Ignoring structure %s, not in %s",
structure.name, self._structure)
except socket.error:
_LOGGER.error(
"Connection error logging into the nest web service.")


def is_thermostat(device):
"""Target devices that are Nest Thermostats."""
return bool(device.__class__.__name__ == 'Device')


def is_protect(device):
"""Target devices that are Nest Protect Smoke Alarms."""
return bool(device.__class__.__name__ == 'ProtectDevice')


def is_camera(device):
"""Target devices that are Nest Protect Smoke Alarms."""
return bool(device.__class__.__name__ == 'CameraDevice')
2 changes: 1 addition & 1 deletion homeassistant/components/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def async_handle_remote_service(service):
update_coro = hass.loop.create_task(
remote.async_update_ha_state(True))
if hasattr(remote, 'async_update'):
update_tasks.append(hass.loop.create_task(update_coro))
update_tasks.append(update_coro)
else:
yield from update_coro

Expand Down
21 changes: 6 additions & 15 deletions homeassistant/components/sensor/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import voluptuous as vol

from homeassistant.components.nest import DATA_NEST, DOMAIN
from homeassistant.components.nest import (
DATA_NEST, DOMAIN)
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_PLATFORM,
Expand Down Expand Up @@ -93,31 +94,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error(wstr)

all_sensors = []
for structure, device in chain(nest.devices(), nest.protect_devices()):
for structure, device in chain(nest.thermostats(), nest.smoke_co_alarms()):
sensors = [NestBasicSensor(structure, device, variable)
for variable in conf
if variable in SENSOR_TYPES and is_thermostat(device)]
if variable in SENSOR_TYPES and device.is_thermostat]
sensors += [NestTempSensor(structure, device, variable)
for variable in conf
if variable in SENSOR_TEMP_TYPES and is_thermostat(device)]
if variable in SENSOR_TEMP_TYPES and device.is_thermostat]
sensors += [NestProtectSensor(structure, device, variable)
for variable in conf
if variable in PROTECT_VARS and is_protect(device)]
if variable in PROTECT_VARS and device.is_smoke_co_alarm]
all_sensors.extend(sensors)

add_devices(all_sensors, True)


def is_thermostat(device):
"""Target devices that are Nest Thermostats."""
return bool(device.__class__.__name__ == 'Device')


def is_protect(device):
"""Target devices that are Nest Protect Smoke Alarms."""
return bool(device.__class__.__name__ == 'ProtectDevice')


class NestSensor(Entity):
"""Representation of a Nest sensor."""

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def async_handle_switch_service(service):
update_coro = hass.loop.create_task(
switch.async_update_ha_state(True))
if hasattr(switch, 'async_update'):
update_tasks.append(hass.loop.create_task(update_coro))
update_tasks.append(update_coro)
else:
yield from update_coro

Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/tts/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ say:

fields:
entity_id:
description: Name(s) of media player entities
description: Name(s) of media player entities.
example: 'media_player.floor'

message:
description: Text to speak on devices
description: Text to speak on devices.
example: 'My name is hanna'

cache:
description: Control file cache of this message.
example: 'true'

clear_cache:
description: Remove cache files and RAM cache.
27 changes: 23 additions & 4 deletions homeassistant/components/tts/voicerss.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@

VOICERSS_API_URL = "https://api.voicerss.org/"

ERROR_MSG = [
b'Error description',
b'The subscription is expired or requests count limitation is exceeded!',
b'The request content length is too large!',
b'The language does not support!',
b'The language is not specified!',
b'The text is not specified!',
b'The API key is not available!',
b'The API key is not specified!',
b'The subscription does not support SSML!',
]

SUPPORT_LANGUAGES = [
'ca-es', 'zh-cn', 'zh-hk', 'zh-tw', 'da-dk', 'nl-nl', 'en-au', 'en-ca',
'en-gb', 'en-in', 'en-us', 'fi-fi', 'fr-ca', 'fr-fr', 'de-de', 'it-it',
Expand Down Expand Up @@ -83,7 +95,7 @@ def __init__(self, hass, conf):
self.hass = hass
self.extension = conf.get(CONF_CODEC)

self.params = {
self.form_data = {
'key': conf.get(CONF_API_KEY),
'hl': conf.get(CONF_LANG),
'c': (conf.get(CONF_CODEC)).upper(),
Expand All @@ -94,21 +106,28 @@ def __init__(self, hass, conf):
def async_get_tts_audio(self, message):
"""Load TTS from voicerss."""
websession = async_get_clientsession(self.hass)
form_data = self.form_data.copy()

form_data['src'] = message

request = None
try:
with async_timeout.timeout(10, loop=self.hass.loop):
request = yield from websession.post(
VOICERSS_API_URL, params=self.params,
data=bytes(message, 'utf-8')
VOICERSS_API_URL, data=form_data
)

if request.status != 200:
_LOGGER.error("Error %d on load url %s",
_LOGGER.error("Error %d on load url %s.",
request.status, request.url)
return (None, None)
data = yield from request.read()

if data in ERROR_MSG:
_LOGGER.error(
"Error receive %s from voicerss.", str(data, 'utf-8'))
return (None, None)

except (asyncio.TimeoutError, aiohttp.errors.ClientError):
_LOGGER.error("Timeout for voicerss api.")
return (None, None)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 35
PATCH_VERSION = '2'
PATCH_VERSION = '3'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
REQUIRED_PYTHON_VER = (3, 4, 2)
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/util/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def async_close(self, blocking=False):
When blocking=True, will wait till closed.
"""
self.close()
if not self._thread.is_alive():
return
yield from self._queue.put(None)

if blocking:
# Python 3.4.4+
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ hikvision==0.4
# http://github.com/adafruit/Adafruit_Python_DHT/archive/310c59b0293354d07d94375f1365f7b9b9110c7d.zip#Adafruit_DHT==1.3.0

# homeassistant.components.nest
http://github.com/technicalpickles/python-nest/archive/b8391d2b3cb8682f8b0c2bdff477179983609f39.zip#python-nest==3.0.2
http://github.com/technicalpickles/python-nest/archive/e6c9d56a8df455d4d7746389811f2c1387e8cb33.zip#python-nest==3.0.3

# homeassistant.components.light.flux_led
https://github.com/Danielhiversen/flux_led/archive/0.10.zip#flux_led==0.10
Expand Down
Loading

0 comments on commit 308d71c

Please sign in to comment.