Skip to content

Commit

Permalink
Merge pull request home-assistant#2183 from home-assistant/dev
Browse files Browse the repository at this point in the history
0.21
  • Loading branch information
balloob committed Jun 8, 2016
2 parents 6c5efd5 + 31489a5 commit d7b0929
Show file tree
Hide file tree
Showing 135 changed files with 4,354 additions and 1,516 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ omit =
homeassistant/components/zwave.py
homeassistant/components/*/zwave.py

homeassistant/components/enocean.py
homeassistant/components/*/enocean.py

homeassistant/components/alarm_control_panel/alarmdotcom.py
homeassistant/components/alarm_control_panel/nx584.py
homeassistant/components/binary_sensor/arest.py
Expand Down Expand Up @@ -111,6 +114,8 @@ omit =
homeassistant/components/light/hyperion.py
homeassistant/components/light/lifx.py
homeassistant/components/light/limitlessled.py
homeassistant/components/light/osramlightify.py
homeassistant/components/lirc.py
homeassistant/components/media_player/cast.py
homeassistant/components/media_player/denon.py
homeassistant/components/media_player/firetv.py
Expand Down Expand Up @@ -156,6 +161,7 @@ omit =
homeassistant/components/sensor/cpuspeed.py
homeassistant/components/sensor/deutsche_bahn.py
homeassistant/components/sensor/dht.py
homeassistant/components/sensor/dte_energy_bridge.py
homeassistant/components/sensor/efergy.py
homeassistant/components/sensor/eliqonline.py
homeassistant/components/sensor/fitbit.py
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**Description:**


**Related issue (if applicable):** #
**Related issue (if applicable):** fixes #

**Pull request in [home-assistant.io](https://github.com/home-assistant/home-assistant.io) with documentation (if applicable):** home-assistant/home-assistant.io#

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ venv
*.swo

ctags.tmp

# vagrant stuff
virtualization/vagrant/setup_done
virtualization/vagrant/.vagrant
virtualization/vagrant/config
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ RUN script/build_python_openzwave && \
ln -sf /usr/src/app/build/python-openzwave/openzwave/config /usr/local/share/python-openzwave/config

COPY requirements_all.txt requirements_all.txt
RUN pip3 install --no-cache-dir -r requirements_all.txt

RUN wget http://www.openssl.org/source/openssl-1.0.2h.tar.gz && \
tar -xvzf openssl-1.0.2h.tar.gz && \
cd openssl-1.0.2h && \
./config --prefix=/usr/ && \
make && \
make install && \
rm -rf openssl-1.0.2h*
# certifi breaks Debian based installs
RUN pip3 install --no-cache-dir -r requirements_all.txt && pip3 uninstall -y certifi

# Copy source
COPY . .
Expand Down
1 change: 0 additions & 1 deletion homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ def open_browser(event):

hass.bus.listen_once(EVENT_HOMEASSISTANT_START, open_browser)

print('Starting Home-Assistant')
hass.start()
exit_code = int(hass.block_till_stopped())

Expand Down
120 changes: 64 additions & 56 deletions homeassistant/components/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import enum
import logging

from homeassistant.const import HTTP_OK, HTTP_UNPROCESSABLE_ENTITY
from homeassistant.const import HTTP_BAD_REQUEST
from homeassistant.helpers import template, script
from homeassistant.components.http import HomeAssistantView

DOMAIN = 'alexa'
DEPENDENCIES = ['http']

_LOGGER = logging.getLogger(__name__)
_CONFIG = {}

API_ENDPOINT = '/api/alexa'

Expand All @@ -26,80 +26,88 @@

def setup(hass, config):
"""Activate Alexa component."""
intents = config[DOMAIN].get(CONF_INTENTS, {})
hass.wsgi.register_view(AlexaView(hass,
config[DOMAIN].get(CONF_INTENTS, {})))

for name, intent in intents.items():
if CONF_ACTION in intent:
intent[CONF_ACTION] = script.Script(hass, intent[CONF_ACTION],
"Alexa intent {}".format(name))
return True

_CONFIG.update(intents)

hass.http.register_path('POST', API_ENDPOINT, _handle_alexa, True)
class AlexaView(HomeAssistantView):
"""Handle Alexa requests."""

return True
url = API_ENDPOINT
name = 'api:alexa'

def __init__(self, hass, intents):
"""Initialize Alexa view."""
super().__init__(hass)

for name, intent in intents.items():
if CONF_ACTION in intent:
intent[CONF_ACTION] = script.Script(
hass, intent[CONF_ACTION], "Alexa intent {}".format(name))

self.intents = intents

def post(self, request):
"""Handle Alexa."""
data = request.json

def _handle_alexa(handler, path_match, data):
"""Handle Alexa."""
_LOGGER.debug('Received Alexa request: %s', data)
_LOGGER.debug('Received Alexa request: %s', data)

req = data.get('request')
req = data.get('request')

if req is None:
_LOGGER.error('Received invalid data from Alexa: %s', data)
handler.write_json_message(
"Invalid value received for port", HTTP_UNPROCESSABLE_ENTITY)
return
if req is None:
_LOGGER.error('Received invalid data from Alexa: %s', data)
return self.json_message('Expected request value not received',
HTTP_BAD_REQUEST)

req_type = req['type']
req_type = req['type']

if req_type == 'SessionEndedRequest':
handler.send_response(HTTP_OK)
handler.end_headers()
return
if req_type == 'SessionEndedRequest':
return None

intent = req.get('intent')
response = AlexaResponse(handler.server.hass, intent)
intent = req.get('intent')
response = AlexaResponse(self.hass, intent)

if req_type == 'LaunchRequest':
response.add_speech(
SpeechType.plaintext,
"Hello, and welcome to the future. How may I help?")
handler.write_json(response.as_dict())
return
if req_type == 'LaunchRequest':
response.add_speech(
SpeechType.plaintext,
"Hello, and welcome to the future. How may I help?")
return self.json(response)

if req_type != 'IntentRequest':
_LOGGER.warning('Received unsupported request: %s', req_type)
return
if req_type != 'IntentRequest':
_LOGGER.warning('Received unsupported request: %s', req_type)
return self.json_message(
'Received unsupported request: {}'.format(req_type),
HTTP_BAD_REQUEST)

intent_name = intent['name']
config = _CONFIG.get(intent_name)
intent_name = intent['name']
config = self.intents.get(intent_name)

if config is None:
_LOGGER.warning('Received unknown intent %s', intent_name)
response.add_speech(
SpeechType.plaintext,
"This intent is not yet configured within Home Assistant.")
handler.write_json(response.as_dict())
return
if config is None:
_LOGGER.warning('Received unknown intent %s', intent_name)
response.add_speech(
SpeechType.plaintext,
"This intent is not yet configured within Home Assistant.")
return self.json(response)

speech = config.get(CONF_SPEECH)
card = config.get(CONF_CARD)
action = config.get(CONF_ACTION)
speech = config.get(CONF_SPEECH)
card = config.get(CONF_CARD)
action = config.get(CONF_ACTION)

# pylint: disable=unsubscriptable-object
if speech is not None:
response.add_speech(SpeechType[speech['type']], speech['text'])
# pylint: disable=unsubscriptable-object
if speech is not None:
response.add_speech(SpeechType[speech['type']], speech['text'])

if card is not None:
response.add_card(CardType[card['type']], card['title'],
card['content'])
if card is not None:
response.add_card(CardType[card['type']], card['title'],
card['content'])

if action is not None:
action.run(response.variables)
if action is not None:
action.run(response.variables)

handler.write_json(response.as_dict())
return self.json(response)


class SpeechType(enum.Enum):
Expand Down
Loading

0 comments on commit d7b0929

Please sign in to comment.