From 9876a2a0810e2730ff01ae41dc84efed9c0da7ca Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 22 Dec 2015 02:08:46 -0800 Subject: [PATCH 1/2] Fix Alexa bug if no value for slots --- homeassistant/components/alexa.py | 2 +- tests/components/test_alexa.py | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/alexa.py b/homeassistant/components/alexa.py index c261cfd3f6a..0b06f3c9a79 100644 --- a/homeassistant/components/alexa.py +++ b/homeassistant/components/alexa.py @@ -116,7 +116,7 @@ class AlexaResponse(object): self.should_end_session = True if intent is not None and 'slots' in intent: self.variables = {key: value['value'] for key, value - in intent['slots'].items()} + in intent['slots'].items() if 'value' in value} else: self.variables = {} diff --git a/tests/components/test_alexa.py b/tests/components/test_alexa.py index 75aec2b087c..741cfff4bb8 100644 --- a/tests/components/test_alexa.py +++ b/tests/components/test_alexa.py @@ -149,6 +149,45 @@ class TestAlexa(unittest.TestCase): text = req.json().get('response', {}).get('outputSpeech', {}).get('text') self.assertEqual('You told us your sign is virgo.', text) + def test_intent_request_with_slots_but_no_value(self): + data = { + 'version': '1.0', + 'session': { + 'new': False, + 'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000', + 'application': { + 'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe' + }, + 'attributes': { + 'supportedHoroscopePeriods': { + 'daily': True, + 'weekly': False, + 'monthly': False + } + }, + 'user': { + 'userId': 'amzn1.account.AM3B00000000000000000000000' + } + }, + 'request': { + 'type': 'IntentRequest', + 'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000', + 'timestamp': '2015-05-13T12:34:56Z', + 'intent': { + 'name': 'GetZodiacHoroscopeIntent', + 'slots': { + 'ZodiacSign': { + 'name': 'ZodiacSign', + } + } + } + } + } + req = _req(data) + self.assertEqual(200, req.status_code) + text = req.json().get('response', {}).get('outputSpeech', {}).get('text') + self.assertEqual('You told us your sign is .', text) + def test_intent_request_without_slots(self): data = { 'version': '1.0', From 561a78bef3c40f23d898c3e428094198ef13e5e0 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 22 Dec 2015 02:19:55 -0800 Subject: [PATCH 2/2] Fix EntityComponent deadlock --- homeassistant/helpers/entity_component.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index ec22181bf5a..4cf44737f90 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -113,12 +113,16 @@ class EntityComponent(object): def _update_entity_states(self, now): """ Update the states of all the entities. """ + with self.lock: + # We copy the entities because new entities might be detected + # during state update causing deadlocks. + entities = list(entity for entity in self.entities.values() + if entity.should_poll) + self.logger.info("Updating %s entities", self.domain) - with self.lock: - for entity in self.entities.values(): - if entity.should_poll: - entity.update_ha_state(True) + for entity in entities: + entity.update_ha_state(True) def _entity_discovered(self, service, info): """ Called when a entity is discovered. """