From 47f07705450f53b8717396da67b51c044e5a2814 Mon Sep 17 00:00:00 2001 From: Chris Browet Date: Thu, 13 May 2021 11:43:45 +0200 Subject: [PATCH] FIX: config flow --- README.md | 6 +++- custom_components/jellyfin/__init__.py | 36 ++++++++++++++++++----- custom_components/jellyfin/config_flow.py | 6 ++-- custom_components/jellyfin/manifest.json | 2 +- custom_components/jellyfin/sensor.py | 2 -- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7a37ece..9cefe1a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ Jellyfin integration for Home Assistant ## Changelog -### 1.0 +### 1.0.1 + +- Config flow fixes + +### 1.0.0 - Initial public release diff --git a/custom_components/jellyfin/__init__.py b/custom_components/jellyfin/__init__.py index 0fd6718..e100e7d 100644 --- a/custom_components/jellyfin/__init__.py +++ b/custom_components/jellyfin/__init__.py @@ -1,4 +1,5 @@ """The jellyfin component.""" +import asyncio import json import logging import time @@ -136,6 +137,8 @@ async def async_setup(hass: HomeAssistant, config: dict): async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): + autolog("<<<") + global UPDATE_UNLISTENER if UPDATE_UNLISTENER: UPDATE_UNLISTENER() @@ -184,10 +187,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): hass.services.async_register( DOMAIN, my_service, async_service_handler, schema=schema) - for component in PLATFORMS: - hass.data[DOMAIN][config.get(CONF_URL)][component] = {} + await _jelly.start() + + for platform in PLATFORMS: + hass.data[DOMAIN][config.get(CONF_URL)][platform] = {} + hass.data[DOMAIN][config.get(CONF_URL)][platform]["entities"] = [] hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, component) + hass.config_entries.async_forward_entry_setup(config_entry, platform) ) async_dispatcher_send(hass, SIGNAL_STATE_UPDATED) @@ -198,12 +204,26 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_jellyfin) - await _jelly.start() - return True +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry): + _LOGGER.info("Unloading jellyfin") -async def _update_listener(hass, config_entry): + unload_ok = all( + await asyncio.gather( + *[ + hass.config_entries.async_forward_entry_unload(config_entry, component) + for component in PLATFORMS + ] + ) + ) + + _jelly: JellyfinClientManager = hass.data[DOMAIN][config_entry.data.get(CONF_URL)]["manager"] + await _jelly.stop() + + return unload_ok + +async def _update_listener(hass: HomeAssistant, config_entry): """Update listener.""" _LOGGER.debug("reload triggered") await hass.config_entries.async_reload(config_entry.entry_id) @@ -644,10 +664,10 @@ class JellyfinClientManager(object): await self.update_data() async def stop(self): - autolog(">>>") + autolog("<<<") - await self.hass.async_add_executor_job(self.jf_client.stop) self.is_stopping = True + await self.hass.async_add_executor_job(self.jf_client.stop) @util.Throttle(MIN_TIME_BETWEEN_UPDATES) async def update_data (self): diff --git a/custom_components/jellyfin/config_flow.py b/custom_components/jellyfin/config_flow.py index 8108bbd..36c5ac0 100644 --- a/custom_components/jellyfin/config_flow.py +++ b/custom_components/jellyfin/config_flow.py @@ -120,9 +120,9 @@ class JellyfinOptionsFlowHandler(config_entries.OptionsFlow): self._url = config_entry.data[CONF_URL] if CONF_URL in config_entry.data else None self._username = config_entry.data[CONF_USERNAME] if CONF_USERNAME in config_entry.data else None self._password = config_entry.data[CONF_PASSWORD] if CONF_PASSWORD in config_entry.data else None - self._verify_ssl = config_entry.data[CONF_VERIFY_SSL] if CONF_VERIFY_SSL in config_entry.options else DEFAULT_VERIFY_SSL - self._generate_upcoming = config_entry.data[CONF_GENERATE_UPCOMING] if CONF_GENERATE_UPCOMING in config_entry.options else False - self._generate_yamc = config_entry.data[CONF_GENERATE_YAMC] if CONF_GENERATE_YAMC in config_entry.options else False + self._verify_ssl = config_entry.data[CONF_VERIFY_SSL] if CONF_VERIFY_SSL in config_entry.data else DEFAULT_VERIFY_SSL + self._generate_upcoming = config_entry.data[CONF_GENERATE_UPCOMING] if CONF_GENERATE_UPCOMING in config_entry.data else False + self._generate_yamc = config_entry.data[CONF_GENERATE_YAMC] if CONF_GENERATE_YAMC in config_entry.data else False async def async_step_init(self, user_input=None): """Manage the options.""" diff --git a/custom_components/jellyfin/manifest.json b/custom_components/jellyfin/manifest.json index 19027d5..c980ff7 100644 --- a/custom_components/jellyfin/manifest.json +++ b/custom_components/jellyfin/manifest.json @@ -1,7 +1,7 @@ { "domain": "jellyfin", "name": "Jellyfin", - "version": "1.0", + "version": "1.0.1", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/emby", "requirements": ["jellyfin-apiclient-python==1.7.2"], diff --git a/custom_components/jellyfin/sensor.py b/custom_components/jellyfin/sensor.py index 5362f79..26473d1 100644 --- a/custom_components/jellyfin/sensor.py +++ b/custom_components/jellyfin/sensor.py @@ -24,8 +24,6 @@ _LOGGER = logging.getLogger(__name__) async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entities): _jelly: JellyfinClientManager = hass.data[DOMAIN][config_entry.data.get(CONF_URL)]["manager"] - hass.data[DOMAIN][_jelly.host][PLATFORM]["entities"] = [] - async_add_entities([JellyfinSensor(_jelly)], True)