mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use runtime_data in denonavr (#136424)
This commit is contained in:
parent
20e936c7b9
commit
c2fe7230b5
@ -24,20 +24,18 @@ from .const import (
|
|||||||
DEFAULT_USE_TELNET,
|
DEFAULT_USE_TELNET,
|
||||||
DEFAULT_ZONE2,
|
DEFAULT_ZONE2,
|
||||||
DEFAULT_ZONE3,
|
DEFAULT_ZONE3,
|
||||||
DOMAIN,
|
|
||||||
)
|
)
|
||||||
from .receiver import ConnectDenonAVR
|
from .receiver import ConnectDenonAVR
|
||||||
|
|
||||||
CONF_RECEIVER = "receiver"
|
|
||||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type DenonavrConfigEntry = ConfigEntry[DenonAVR]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: DenonavrConfigEntry) -> bool:
|
||||||
"""Set up the denonavr components from a config entry."""
|
"""Set up the denonavr components from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
|
|
||||||
# Connect to receiver
|
# Connect to receiver
|
||||||
connect_denonavr = ConnectDenonAVR(
|
connect_denonavr = ConnectDenonAVR(
|
||||||
entry.data[CONF_HOST],
|
entry.data[CONF_HOST],
|
||||||
@ -57,9 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = {
|
entry.runtime_data = receiver
|
||||||
CONF_RECEIVER: receiver,
|
|
||||||
}
|
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
use_telnet = entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET)
|
use_telnet = entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET)
|
||||||
@ -77,14 +73,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: DenonavrConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, PLATFORMS
|
config_entry, PLATFORMS
|
||||||
)
|
)
|
||||||
|
|
||||||
if config_entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET):
|
if config_entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET):
|
||||||
receiver: DenonAVR = hass.data[DOMAIN][config_entry.entry_id][CONF_RECEIVER]
|
receiver = config_entry.runtime_data
|
||||||
await receiver.async_telnet_disconnect()
|
await receiver.async_telnet_disconnect()
|
||||||
|
|
||||||
# Remove zone2 and zone3 entities if needed
|
# Remove zone2 and zone3 entities if needed
|
||||||
@ -101,12 +99,11 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
entity_registry.async_remove(entry.entity_id)
|
entity_registry.async_remove(entry.entity_id)
|
||||||
_LOGGER.debug("Removing zone3 from DenonAvr")
|
_LOGGER.debug("Removing zone3 from DenonAvr")
|
||||||
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
async def update_listener(
|
||||||
|
hass: HomeAssistant, config_entry: DenonavrConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Handle options update."""
|
"""Handle options update."""
|
||||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||||
|
@ -10,12 +10,7 @@ import denonavr
|
|||||||
from denonavr.exceptions import AvrNetworkError, AvrTimoutError
|
from denonavr.exceptions import AvrNetworkError, AvrTimoutError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
||||||
ConfigEntry,
|
|
||||||
ConfigFlow,
|
|
||||||
ConfigFlowResult,
|
|
||||||
OptionsFlow,
|
|
||||||
)
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_MODEL, CONF_TYPE
|
from homeassistant.const import CONF_HOST, CONF_MODEL, CONF_TYPE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
@ -27,6 +22,7 @@ from homeassistant.helpers.service_info.ssdp import (
|
|||||||
SsdpServiceInfo,
|
SsdpServiceInfo,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from . import DenonavrConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MANUFACTURER,
|
CONF_MANUFACTURER,
|
||||||
CONF_SERIAL_NUMBER,
|
CONF_SERIAL_NUMBER,
|
||||||
@ -118,7 +114,7 @@ class DenonAvrFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(
|
def async_get_options_flow(
|
||||||
config_entry: ConfigEntry,
|
config_entry: DenonavrConfigEntry,
|
||||||
) -> OptionsFlowHandler:
|
) -> OptionsFlowHandler:
|
||||||
"""Get the options flow."""
|
"""Get the options flow."""
|
||||||
return OptionsFlowHandler()
|
return OptionsFlowHandler()
|
||||||
|
@ -35,14 +35,13 @@ from homeassistant.components.media_player import (
|
|||||||
MediaPlayerState,
|
MediaPlayerState,
|
||||||
MediaType,
|
MediaType,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_COMMAND, CONF_HOST, CONF_MODEL, CONF_TYPE
|
from homeassistant.const import ATTR_COMMAND, CONF_HOST, CONF_MODEL, CONF_TYPE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import CONF_RECEIVER
|
from . import DenonavrConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MANUFACTURER,
|
CONF_MANUFACTURER,
|
||||||
CONF_SERIAL_NUMBER,
|
CONF_SERIAL_NUMBER,
|
||||||
@ -109,13 +108,12 @@ DENON_STATE_MAPPING = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: DenonavrConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the DenonAVR receiver from a config entry."""
|
"""Set up the DenonAVR receiver from a config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
receiver = config_entry.runtime_data
|
||||||
receiver = data[CONF_RECEIVER]
|
|
||||||
update_audyssey = config_entry.options.get(
|
update_audyssey = config_entry.options.get(
|
||||||
CONF_UPDATE_AUDYSSEY, DEFAULT_UPDATE_AUDYSSEY
|
CONF_UPDATE_AUDYSSEY, DEFAULT_UPDATE_AUDYSSEY
|
||||||
)
|
)
|
||||||
@ -252,7 +250,7 @@ class DenonDevice(MediaPlayerEntity):
|
|||||||
self,
|
self,
|
||||||
receiver: DenonAVR,
|
receiver: DenonAVR,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
config_entry: ConfigEntry,
|
config_entry: DenonavrConfigEntry,
|
||||||
update_audyssey: bool,
|
update_audyssey: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user