1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00
ha-core/homeassistant/components/braviatv/__init__.py
Maciej Bieniek 58bff0a183
Reload braviatv entry after options update (#34576)
* Reload entry after options update

* Undo update listener when unloading
2020-04-29 09:27:45 -05:00

61 lines
1.5 KiB
Python

"""The Bravia TV component."""
import asyncio
from bravia_tv import BraviaRC
from homeassistant.const import CONF_HOST, CONF_MAC
from .const import BRAVIARC, DOMAIN, UNDO_UPDATE_LISTENER
PLATFORMS = ["media_player"]
async def async_setup(hass, config):
"""Set up the Bravia TV component."""
return True
async def async_setup_entry(hass, config_entry):
"""Set up a config entry."""
host = config_entry.data[CONF_HOST]
mac = config_entry.data[CONF_MAC]
undo_listener = config_entry.add_update_listener(update_listener)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config_entry.entry_id] = {
BRAVIARC: BraviaRC(host, mac),
UNDO_UPDATE_LISTENER: undo_listener,
}
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, component)
)
return True
async def async_unload_entry(hass, config_entry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, component)
for component in PLATFORMS
]
)
)
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
if unload_ok:
hass.data[DOMAIN].pop(config_entry.entry_id)
return unload_ok
async def update_listener(hass, config_entry):
"""Handle options update."""
await hass.config_entries.async_reload(config_entry.entry_id)