FIX: config flow

This commit is contained in:
Chris Browet 2021-05-13 11:43:45 +02:00
parent 32290197a8
commit 47f0770545
5 changed files with 37 additions and 15 deletions

View file

@ -4,7 +4,11 @@ Jellyfin integration for Home Assistant
## Changelog
### 1.0
### 1.0.1
- Config flow fixes
### 1.0.0
- Initial public release

View file

@ -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):

View file

@ -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."""

View file

@ -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"],

View file

@ -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)