From c38240673535ba03fec4f404926015a074c689e5 Mon Sep 17 00:00:00 2001 From: jjlawren Date: Sat, 23 Nov 2019 09:16:21 -0600 Subject: [PATCH 1/7] Fix Plex setup race condition v2 (#28943) * Connect websocket when platforms ready, not when HA is ready * Use callbacks from platform setup tasks instead * Convert setup to async * Apply suggestions from code review Co-Authored-By: Martin Hjelmare --- homeassistant/components/plex/__init__.py | 34 +++++++++++++---------- homeassistant/components/plex/const.py | 3 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/plex/__init__.py b/homeassistant/components/plex/__init__.py index 386be56340a..97103230288 100644 --- a/homeassistant/components/plex/__init__.py +++ b/homeassistant/components/plex/__init__.py @@ -1,5 +1,6 @@ """Support to embed Plex.""" import asyncio +import functools import logging import plexapi.exceptions @@ -16,7 +17,6 @@ from homeassistant.const import ( CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL, - EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, ) from homeassistant.helpers import config_validation as cv @@ -37,6 +37,7 @@ from .const import ( DISPATCHERS, DOMAIN as PLEX_DOMAIN, PLATFORMS, + PLATFORMS_COMPLETED, PLEX_MEDIA_PLAYER_OPTIONS, PLEX_SERVER_CONFIG, PLEX_UPDATE_PLATFORMS_SIGNAL, @@ -72,18 +73,21 @@ CONFIG_SCHEMA = vol.Schema({PLEX_DOMAIN: SERVER_CONFIG_SCHEMA}, extra=vol.ALLOW_ _LOGGER = logging.getLogger(__package__) -def setup(hass, config): +async def async_setup(hass, config): """Set up the Plex component.""" - hass.data.setdefault(PLEX_DOMAIN, {SERVERS: {}, DISPATCHERS: {}, WEBSOCKETS: {}}) + hass.data.setdefault( + PLEX_DOMAIN, + {SERVERS: {}, DISPATCHERS: {}, WEBSOCKETS: {}, PLATFORMS_COMPLETED: {}}, + ) plex_config = config.get(PLEX_DOMAIN, {}) if plex_config: - _setup_plex(hass, plex_config) + _async_setup_plex(hass, plex_config) return True -def _setup_plex(hass, config): +def _async_setup_plex(hass, config): """Pass configuration to a config flow.""" server_config = dict(config) if MP_DOMAIN in server_config: @@ -141,11 +145,7 @@ async def async_setup_entry(hass, entry): ) server_id = plex_server.machine_identifier hass.data[PLEX_DOMAIN][SERVERS][server_id] = plex_server - - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.data[PLEX_DOMAIN][PLATFORMS_COMPLETED][server_id] = set() entry.add_update_listener(async_options_updated) @@ -167,19 +167,25 @@ async def async_setup_entry(hass, entry): ) hass.data[PLEX_DOMAIN][WEBSOCKETS][server_id] = websocket - async def async_start_websocket_session(_): - await websocket.listen() + def start_websocket_session(platform, _): + hass.data[PLEX_DOMAIN][PLATFORMS_COMPLETED][server_id].add(platform) + if hass.data[PLEX_DOMAIN][PLATFORMS_COMPLETED][server_id] == PLATFORMS: + hass.loop.create_task(websocket.listen()) def close_websocket_session(_): websocket.close() - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_start_websocket_session) - unsub = hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, close_websocket_session ) hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub) + for platform in PLATFORMS: + task = hass.async_create_task( + hass.config_entries.async_forward_entry_setup(entry, platform) + ) + task.add_done_callback(functools.partial(start_websocket_session, platform)) + return True diff --git a/homeassistant/components/plex/const.py b/homeassistant/components/plex/const.py index d3c79e60bc4..ad62bade1fd 100644 --- a/homeassistant/components/plex/const.py +++ b/homeassistant/components/plex/const.py @@ -9,7 +9,8 @@ DEFAULT_SSL = False DEFAULT_VERIFY_SSL = True DISPATCHERS = "dispatchers" -PLATFORMS = ["media_player", "sensor"] +PLATFORMS = frozenset(["media_player", "sensor"]) +PLATFORMS_COMPLETED = "platforms_completed" SERVERS = "servers" WEBSOCKETS = "websockets" From 2e85e3662f06c22324bc28d35bae9b2f25a751ef Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 22 Nov 2019 15:32:05 +0100 Subject: [PATCH 2/7] Fix ikea lights on deconz (#28949) * Fix ikea lights on deconz * check for None * Use cleaner code style --- homeassistant/components/deconz/light.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index bf4b05089a8..eda2041b923 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -152,6 +152,8 @@ class DeconzLight(DeconzDevice, Light): if ATTR_TRANSITION in kwargs: data["transitiontime"] = int(kwargs[ATTR_TRANSITION] * 10) + elif "IKEA" in (self._device.manufacturer or ""): + data["transitiontime"] = 0 if ATTR_FLASH in kwargs: if kwargs[ATTR_FLASH] == FLASH_SHORT: From 481f71107bff1dd94897f34e41a34c8e9f73691a Mon Sep 17 00:00:00 2001 From: cgtobi Date: Sat, 23 Nov 2019 11:00:26 +0100 Subject: [PATCH 3/7] Fix manual config (#28956) --- homeassistant/components/netatmo/sensor.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/netatmo/sensor.py b/homeassistant/components/netatmo/sensor.py index fa7aedae739..1ae076c6560 100644 --- a/homeassistant/components/netatmo/sensor.py +++ b/homeassistant/components/netatmo/sensor.py @@ -547,13 +547,18 @@ class NetatmoData: self.data = {} self.station_data = self.data_class(self.auth) self.station = station + self.station_id = None + if station: + station_data = self.station_data.stationByName(self.station) + if station_data: + self.station_id = station_data.get("_id") self._next_update = time() self._update_in_progress = threading.Lock() def get_module_infos(self): """Return all modules available on the API as a dict.""" - if self.station is not None: - return self.station_data.getModules(station=self.station) + if self.station_id is not None: + return self.station_data.getModules(station_id=self.station_id) return self.station_data.getModules() def update(self): @@ -579,7 +584,7 @@ class NetatmoData: return data = self.station_data.lastData( - station=self.station, exclude=3600, byId=True + station=self.station_id, exclude=3600, byId=True ) if not data: self._next_update = time() + NETATMO_UPDATE_INTERVAL From a56f7f5d7556cfb16d9c6b4f83ccd7717244785e Mon Sep 17 00:00:00 2001 From: shred86 <32663154+shred86@users.noreply.github.com> Date: Sat, 23 Nov 2019 03:29:54 -0800 Subject: [PATCH 4/7] Fix temp not being reported properly (#28973) --- homeassistant/components/abode/sensor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/abode/sensor.py b/homeassistant/components/abode/sensor.py index d84bfe52441..573df6d49b4 100644 --- a/homeassistant/components/abode/sensor.py +++ b/homeassistant/components/abode/sensor.py @@ -72,19 +72,19 @@ class AbodeSensor(AbodeDevice): @property def state(self): """Return the state of the sensor.""" - if self._sensor_type == "temp": + if self._sensor_type == CONST.TEMP_STATUS_KEY: return self._device.temp - if self._sensor_type == "humidity": + if self._sensor_type == CONST.HUMI_STATUS_KEY: return self._device.humidity - if self._sensor_type == "lux": + if self._sensor_type == CONST.LUX_STATUS_KEY: return self._device.lux @property def unit_of_measurement(self): """Return the units of measurement.""" - if self._sensor_type == "temp": + if self._sensor_type == CONST.TEMP_STATUS_KEY: return self._device.temp_unit - if self._sensor_type == "humidity": + if self._sensor_type == CONST.HUMI_STATUS_KEY: return self._device.humidity_unit - if self._sensor_type == "lux": + if self._sensor_type == CONST.LUX_STATUS_KEY: return self._device.lux_unit From 2af1ba749260d96fec50e9e1e7c6f290bae0c81c Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 23 Nov 2019 22:12:56 +0100 Subject: [PATCH 5/7] Updated frontend to 20191119.6 (#28996) --- homeassistant/components/frontend/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/frontend/manifest.json b/homeassistant/components/frontend/manifest.json index 41728bc1664..b196239dfb1 100644 --- a/homeassistant/components/frontend/manifest.json +++ b/homeassistant/components/frontend/manifest.json @@ -3,7 +3,7 @@ "name": "Home Assistant Frontend", "documentation": "https://www.home-assistant.io/integrations/frontend", "requirements": [ - "home-assistant-frontend==20191119.5" + "home-assistant-frontend==20191119.6" ], "dependencies": [ "api", diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 1c4aaa1191f..07ebfdec4f9 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -11,7 +11,7 @@ contextvars==2.4;python_version<"3.7" cryptography==2.8 distro==1.4.0 hass-nabucasa==0.29 -home-assistant-frontend==20191119.5 +home-assistant-frontend==20191119.6 importlib-metadata==0.23 jinja2>=2.10.3 netdisco==2.6.0 diff --git a/requirements_all.txt b/requirements_all.txt index 651c089a4fd..e8307161c09 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -655,7 +655,7 @@ hole==0.5.0 holidays==0.9.11 # homeassistant.components.frontend -home-assistant-frontend==20191119.5 +home-assistant-frontend==20191119.6 # homeassistant.components.zwave homeassistant-pyozw==0.1.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8fc004f3363..2aa46e28f7a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -222,7 +222,7 @@ hole==0.5.0 holidays==0.9.11 # homeassistant.components.frontend -home-assistant-frontend==20191119.5 +home-assistant-frontend==20191119.6 # homeassistant.components.zwave homeassistant-pyozw==0.1.4 From b10d42e33023a24dc51e4b610f5f4f55b1cacdd7 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 25 Nov 2019 04:57:18 +0100 Subject: [PATCH 6/7] Alexa gracefully handle climate devices without presets (#29010) --- homeassistant/components/alexa/capabilities.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 7d74bb3f8cd..49b5c5141b6 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -752,10 +752,11 @@ class AlexaThermostatController(AlexaCapability): supported_modes.append(thermostat_mode) preset_modes = self.entity.attributes.get(climate.ATTR_PRESET_MODES) - for mode in preset_modes: - thermostat_mode = API_THERMOSTAT_PRESETS.get(mode) - if thermostat_mode: - supported_modes.append(thermostat_mode) + if preset_modes: + for mode in preset_modes: + thermostat_mode = API_THERMOSTAT_PRESETS.get(mode) + if thermostat_mode: + supported_modes.append(thermostat_mode) # Return False for supportsScheduling until supported with event listener in handler. configuration = {"supportsScheduling": False} From 8a467bbf5c4bee5938b2b2a6b4a2c135440aafd2 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 24 Nov 2019 19:57:50 -0800 Subject: [PATCH 7/7] Bumped version to 0.102.2 --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index 3520260481b..8b62d011fda 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -1,7 +1,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 102 -PATCH_VERSION = "1" +PATCH_VERSION = "2" __short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION) __version__ = "{}.{}".format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 6, 1)