Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions homeassistant/components/braviatv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from homeassistant.const import CONF_HOST, CONF_MAC

from .const import DOMAIN
from .const import BRAVIARC, DOMAIN, UNDO_UPDATE_LISTENER

PLATFORMS = ["media_player"]

Expand All @@ -20,8 +20,13 @@ async def async_setup_entry(hass, 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(host, mac)
hass.data[DOMAIN][config_entry.entry_id] = {
BRAVIARC: BraviaRC(host, mac),
UNDO_UPDATE_LISTENER: undo_listener,
}

for component in PLATFORMS:
hass.async_create_task(
Expand All @@ -41,7 +46,15 @@ async def async_unload_entry(hass, config_entry):
]
)
)

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)
3 changes: 2 additions & 1 deletion homeassistant/components/braviatv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ATTR_CID,
ATTR_MAC,
ATTR_MODEL,
BRAVIARC,
CLIENTID_PREFIX,
CONF_IGNORED_SOURCES,
DOMAIN,
Expand Down Expand Up @@ -152,7 +153,7 @@ def __init__(self, config_entry):

async def async_step_init(self, user_input=None):
"""Manage the options."""
self.braviarc = self.hass.data[DOMAIN][self.config_entry.entry_id]
self.braviarc = self.hass.data[DOMAIN][self.config_entry.entry_id][BRAVIARC]
if not self.braviarc.is_connected():
await self.hass.async_add_executor_job(
self.braviarc.connect, self.pin, CLIENTID_PREFIX, NICKNAME,
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/braviatv/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

CONF_IGNORED_SOURCES = "ignored_sources"

BRAVIARC = "braviarc"
BRAVIA_CONFIG_FILE = "bravia.conf"
CLIENTID_PREFIX = "HomeAssistant"
DEFAULT_NAME = f"{ATTR_MANUFACTURER} Bravia TV"
DOMAIN = "braviatv"
NICKNAME = "Home Assistant"
UNDO_UPDATE_LISTENER = "undo_update_listener"
3 changes: 2 additions & 1 deletion homeassistant/components/braviatv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .const import (
ATTR_MANUFACTURER,
BRAVIA_CONFIG_FILE,
BRAVIARC,
CLIENTID_PREFIX,
CONF_IGNORED_SOURCES,
DEFAULT_NAME,
Expand Down Expand Up @@ -103,7 +104,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"model": config_entry.title,
}

braviarc = hass.data[DOMAIN][config_entry.entry_id]
braviarc = hass.data[DOMAIN][config_entry.entry_id][BRAVIARC]

ignored_sources = config_entry.options.get(CONF_IGNORED_SOURCES, [])

Expand Down