From afa48c54e99c4112f56dfb17e9604f1abeb88552 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 8 Dec 2018 08:45:03 +0100 Subject: [PATCH 01/12] Don't avoid async_schedule_update_ha_state by returning false (#19102) --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 550bdaac172..becbfe38163 100644 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -423,9 +423,7 @@ class XiaomiButton(XiaomiBinarySensor): }) self._last_action = click_type - if value in ['long_click_press', 'long_click_release']: - return True - return False + return True class XiaomiCube(XiaomiBinarySensor): From 14d90b548414b6438dffe13958b57cdb5165cfe3 Mon Sep 17 00:00:00 2001 From: damarco Date: Thu, 13 Dec 2018 23:08:35 +0100 Subject: [PATCH 02/12] Always add friendly name attribute to ZHA entities (#19141) * Always add friendly name attribute * Only change device_info name --- homeassistant/components/zha/entities/entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/zha/entities/entity.py b/homeassistant/components/zha/entities/entity.py index da8f615a665..25b98255048 100644 --- a/homeassistant/components/zha/entities/entity.py +++ b/homeassistant/components/zha/entities/entity.py @@ -100,6 +100,6 @@ class ZhaEntity(entity.Entity): 'identifiers': {(DOMAIN, ieee)}, 'manufacturer': self._endpoint.manufacturer, 'model': self._endpoint.model, - 'name': self._device_state_attributes['friendly_name'], + 'name': self._device_state_attributes.get('friendly_name', ieee), 'via_hub': (DOMAIN, self.hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID]), } From 4231775e0492759897b1f1212d0ab58cc3a377ee Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 11 Dec 2018 17:05:49 +0100 Subject: [PATCH 03/12] Fail if new entity_id is in hass.states --- homeassistant/components/config/entity_registry.py | 2 +- homeassistant/helpers/entity_registry.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index 1ede76d0fd8..15eed32a8cd 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -88,7 +88,7 @@ async def websocket_get_entity(hass, connection, msg): @async_response async def websocket_update_entity(hass, connection, msg): - """Handle get camera thumbnail websocket command. + """Handle update entity websocket command. Async friendly. """ diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 57c8bcf0af8..fdd9f178321 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -171,7 +171,9 @@ class EntityRegistry: changes['device_id'] = device_id if new_entity_id is not _UNDEF and new_entity_id != old.entity_id: - if self.async_is_registered(new_entity_id): + if (self.async_is_registered(new_entity_id) or new_entity_id in + self.hass.states.async_entity_ids( + split_entity_id(entity_id)[0])): raise ValueError('Entity is already registered') if not valid_entity_id(new_entity_id): From b7b55f941c83b667e775d33266505410853d9749 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 11 Dec 2018 20:20:57 +0100 Subject: [PATCH 04/12] Move check to websocket --- homeassistant/components/config/entity_registry.py | 7 ++++++- homeassistant/helpers/entity_registry.py | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index 15eed32a8cd..13a968dd101 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -1,7 +1,7 @@ """HTTP views to interact with the entity registry.""" import voluptuous as vol -from homeassistant.core import callback +from homeassistant.core import callback, split_entity_id from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.components import websocket_api from homeassistant.components.websocket_api.const import ERR_NOT_FOUND @@ -106,6 +106,11 @@ async def websocket_update_entity(hass, connection, msg): if 'new_entity_id' in msg: changes['new_entity_id'] = msg['new_entity_id'] + if (msg['new_entity_id'] in hass.states.async_entity_ids( + split_entity_id(msg['new_entity_id'])[0])): + connection.send_message(websocket_api.error_message( + msg['id'], ERR_NOT_FOUND, 'Entity is already registered')) + return try: if changes: diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index fdd9f178321..57c8bcf0af8 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -171,9 +171,7 @@ class EntityRegistry: changes['device_id'] = device_id if new_entity_id is not _UNDEF and new_entity_id != old.entity_id: - if (self.async_is_registered(new_entity_id) or new_entity_id in - self.hass.states.async_entity_ids( - split_entity_id(entity_id)[0])): + if self.async_is_registered(new_entity_id): raise ValueError('Entity is already registered') if not valid_entity_id(new_entity_id): From bead08840e4ab5eedf51d2e639a024a670d91a7f Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 12 Dec 2018 16:30:42 +0100 Subject: [PATCH 05/12] Review comments --- homeassistant/components/config/entity_registry.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index 13a968dd101..71833a2e42d 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -1,7 +1,7 @@ """HTTP views to interact with the entity registry.""" import voluptuous as vol -from homeassistant.core import callback, split_entity_id +from homeassistant.core import callback from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.components import websocket_api from homeassistant.components.websocket_api.const import ERR_NOT_FOUND @@ -106,10 +106,9 @@ async def websocket_update_entity(hass, connection, msg): if 'new_entity_id' in msg: changes['new_entity_id'] = msg['new_entity_id'] - if (msg['new_entity_id'] in hass.states.async_entity_ids( - split_entity_id(msg['new_entity_id'])[0])): + if hass.states.get(msg['new_entity_id']) is not None: connection.send_message(websocket_api.error_message( - msg['id'], ERR_NOT_FOUND, 'Entity is already registered')) + msg['id'], 'invalid_info', 'Entity is already registered')) return try: From 37096a2b65bb054a610b469d54c5557e8bc0b41d Mon Sep 17 00:00:00 2001 From: kennedyshead Date: Wed, 12 Dec 2018 20:24:44 +0100 Subject: [PATCH 06/12] Bump aioasuswrt (#19229) * bump aioasuswrt version * run gen_requirements --- homeassistant/components/asuswrt.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/asuswrt.py b/homeassistant/components/asuswrt.py index 719e857c751..959d39038e2 100644 --- a/homeassistant/components/asuswrt.py +++ b/homeassistant/components/asuswrt.py @@ -14,7 +14,7 @@ from homeassistant.const import ( from homeassistant.helpers import config_validation as cv from homeassistant.helpers.discovery import async_load_platform -REQUIREMENTS = ['aioasuswrt==1.1.13'] +REQUIREMENTS = ['aioasuswrt==1.1.15'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index ee749157a7a..d1c3f266e01 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -87,7 +87,7 @@ abodepy==0.14.0 afsapi==0.0.4 # homeassistant.components.asuswrt -aioasuswrt==1.1.13 +aioasuswrt==1.1.15 # homeassistant.components.device_tracker.automatic aioautomatic==0.6.5 From 16c03012272dfedad38c2a8d691419122a8b7626 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Fri, 14 Dec 2018 10:25:02 +0100 Subject: [PATCH 07/12] Add automation and script events to logbook filter events (#19253) * Add automation and script events to logbook filter events * Update logbook.py * Update logbook.py * Update logbook tests * Update test_logbook.py * Update test_logbook.py * Update test_logbook.py * Update test_logbook.py --- homeassistant/components/logbook.py | 8 ++++++ tests/components/test_logbook.py | 42 ++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index 79ee728ddd7..0c6608e3572 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -469,6 +469,14 @@ def _exclude_events(events, entities_filter): domain = event.data.get(ATTR_DOMAIN) entity_id = event.data.get(ATTR_ENTITY_ID) + elif event.event_type == EVENT_AUTOMATION_TRIGGERED: + domain = 'automation' + entity_id = event.data.get(ATTR_ENTITY_ID) + + elif event.event_type == EVENT_SCRIPT_STARTED: + domain = 'script' + entity_id = event.data.get(ATTR_ENTITY_ID) + elif event.event_type == EVENT_ALEXA_SMART_HOME: domain = 'alexa' diff --git a/tests/components/test_logbook.py b/tests/components/test_logbook.py index 321a16ae64e..c8ade907dd3 100644 --- a/tests/components/test_logbook.py +++ b/tests/components/test_logbook.py @@ -265,22 +265,50 @@ class TestComponentLogbook(unittest.TestCase): def test_exclude_automation_events(self): """Test if automation entries can be excluded by entity_id.""" name = 'My Automation Rule' - message = 'has been triggered' domain = 'automation' entity_id = 'automation.my_automation_rule' entity_id2 = 'automation.my_automation_rule_2' entity_id2 = 'sensor.blu' - eventA = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, { + eventA = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, { logbook.ATTR_NAME: name, - logbook.ATTR_MESSAGE: message, - logbook.ATTR_DOMAIN: domain, logbook.ATTR_ENTITY_ID: entity_id, }) - eventB = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, { + eventB = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, { + logbook.ATTR_NAME: name, + logbook.ATTR_ENTITY_ID: entity_id2, + }) + + config = logbook.CONFIG_SCHEMA({ + ha.DOMAIN: {}, + logbook.DOMAIN: {logbook.CONF_EXCLUDE: { + logbook.CONF_ENTITIES: [entity_id, ]}}}) + events = logbook._exclude_events( + (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB), + logbook._generate_filter_from_config(config[logbook.DOMAIN])) + entries = list(logbook.humanify(self.hass, events)) + + assert 2 == len(entries) + self.assert_entry( + entries[0], name='Home Assistant', message='stopped', + domain=ha.DOMAIN) + self.assert_entry( + entries[1], name=name, domain=domain, entity_id=entity_id2) + + def test_exclude_script_events(self): + """Test if script start can be excluded by entity_id.""" + name = 'My Script Rule' + domain = 'script' + entity_id = 'script.my_script' + entity_id2 = 'script.my_script_2' + entity_id2 = 'sensor.blu' + + eventA = ha.Event(logbook.EVENT_SCRIPT_STARTED, { + logbook.ATTR_NAME: name, + logbook.ATTR_ENTITY_ID: entity_id, + }) + eventB = ha.Event(logbook.EVENT_SCRIPT_STARTED, { logbook.ATTR_NAME: name, - logbook.ATTR_MESSAGE: message, - logbook.ATTR_DOMAIN: domain, logbook.ATTR_ENTITY_ID: entity_id2, }) From 965e47eb6a459da6173512ae1bfd6bcdfbe5795f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 13 Dec 2018 16:43:59 +0100 Subject: [PATCH 08/12] Fix list (fixes #19235) (#19258) --- homeassistant/components/tts/amazon_polly.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/tts/amazon_polly.py b/homeassistant/components/tts/amazon_polly.py index e3f5b7407cd..1dfb741bb42 100644 --- a/homeassistant/components/tts/amazon_polly.py +++ b/homeassistant/components/tts/amazon_polly.py @@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at https://home-assistant.io/components/tts.amazon_polly/ """ import logging + import voluptuous as vol from homeassistant.components.tts import Provider, PLATFORM_SCHEMA @@ -56,7 +57,7 @@ SUPPORTED_VOICES = [ 'Cristiano', 'Ines', # Portuguese, European 'Carmen', # Romanian 'Maxim', 'Tatyana', # Russian - 'Enrique', 'Conchita', 'Lucia' # Spanish European + 'Enrique', 'Conchita', 'Lucia', # Spanish European 'Mia', # Spanish Mexican 'Miguel', 'Penelope', # Spanish US 'Astrid', # Swedish From baa1801e13d5b1a5efc5ce25b13d0efabe0bac01 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 13 Dec 2018 20:56:48 +0100 Subject: [PATCH 09/12] Fix OwnTracks deadlocking (#19260) * Fix OwnTracks deadlocking * Fix deadlock --- homeassistant/components/owntracks/__init__.py | 2 +- tests/components/device_tracker/test_owntracks.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/owntracks/__init__.py b/homeassistant/components/owntracks/__init__.py index 5e6a99741e8..d0ba27aeddd 100644 --- a/homeassistant/components/owntracks/__init__.py +++ b/homeassistant/components/owntracks/__init__.py @@ -18,7 +18,7 @@ from .config_flow import CONF_SECRET DOMAIN = "owntracks" REQUIREMENTS = ['libnacl==1.6.1'] -DEPENDENCIES = ['device_tracker', 'webhook'] +DEPENDENCIES = ['webhook'] CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy' CONF_WAYPOINT_IMPORT = 'waypoints' diff --git a/tests/components/device_tracker/test_owntracks.py b/tests/components/device_tracker/test_owntracks.py index 6f457f30ed0..68c1f1e8766 100644 --- a/tests/components/device_tracker/test_owntracks.py +++ b/tests/components/device_tracker/test_owntracks.py @@ -277,6 +277,8 @@ def setup_comp(hass): """Initialize components.""" mock_component(hass, 'group') mock_component(hass, 'zone') + hass.loop.run_until_complete(async_setup_component( + hass, 'device_tracker', {})) hass.loop.run_until_complete(async_mock_mqtt_component(hass)) hass.states.async_set( From 8d44b721c668f214fdbffa889895b695b6569f52 Mon Sep 17 00:00:00 2001 From: Eric Nagley Date: Fri, 14 Dec 2018 02:52:29 -0500 Subject: [PATCH 10/12] Fix call to super() (#19279) * home-assistant/home-assistant#19273: fix call to super() * home-assistant/home-assistant#19273: adjust to python3 standards. * home-assistant/home-assistant#19273: remove bad test. --- homeassistant/components/light/lutron.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/lutron.py b/homeassistant/components/light/lutron.py index ee08e532ce7..359ef0114c5 100644 --- a/homeassistant/components/light/lutron.py +++ b/homeassistant/components/light/lutron.py @@ -42,7 +42,7 @@ class LutronLight(LutronDevice, Light): def __init__(self, area_name, lutron_device, controller): """Initialize the light.""" self._prev_brightness = None - super().__init__(self, area_name, lutron_device, controller) + super().__init__(area_name, lutron_device, controller) @property def supported_features(self): @@ -75,8 +75,7 @@ class LutronLight(LutronDevice, Light): @property def device_state_attributes(self): """Return the state attributes.""" - attr = {} - attr['lutron_integration_id'] = self._lutron_device.id + attr = {'lutron_integration_id': self._lutron_device.id} return attr @property From d425aabae3d4c5532185661f362d6fb19408801e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 14 Dec 2018 10:27:45 +0100 Subject: [PATCH 11/12] Bumped version to 0.84.2 --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index 21494691a46..133df0fdf88 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -2,7 +2,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 84 -PATCH_VERSION = '1' +PATCH_VERSION = '2' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 5, 3) From a262d0f9e43300249812d95da643eb43b2406dd0 Mon Sep 17 00:00:00 2001 From: emontnemery Date: Fri, 14 Dec 2018 10:33:37 +0100 Subject: [PATCH 12/12] Fix race in entity_platform.async_add_entities (#19222) --- homeassistant/helpers/entity_platform.py | 3 ++- homeassistant/helpers/entity_registry.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index ece0fbd071a..9c76d244138 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -297,7 +297,8 @@ class EntityPlatform: self.domain, self.platform_name, entity.unique_id, suggested_object_id=suggested_object_id, config_entry_id=config_entry_id, - device_id=device_id) + device_id=device_id, + known_object_ids=self.entities.keys()) if entry.disabled: self.logger.info( diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 57c8bcf0af8..8216681496b 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -117,7 +117,7 @@ class EntityRegistry: @callback def async_get_or_create(self, domain, platform, unique_id, *, suggested_object_id=None, config_entry_id=None, - device_id=None): + device_id=None, known_object_ids=None): """Get entity. Create if it doesn't exist.""" entity_id = self.async_get_entity_id(domain, platform, unique_id) if entity_id: @@ -126,7 +126,8 @@ class EntityRegistry: device_id=device_id) entity_id = self.async_generate_entity_id( - domain, suggested_object_id or '{}_{}'.format(platform, unique_id)) + domain, suggested_object_id or '{}_{}'.format(platform, unique_id), + known_object_ids) entity = RegistryEntry( entity_id=entity_id,