mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add basic type hints to cast (#62746)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
54d1e20948
commit
4d8c9fc1ab
@ -3,10 +3,11 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import home_assistant_cast
|
||||
from .const import DOMAIN
|
||||
@ -19,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Cast component."""
|
||||
if (conf := config.get(DOMAIN)) is not None:
|
||||
media_player_config_validated = []
|
||||
@ -36,7 +37,7 @@ async def async_setup(hass, config):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=media_player_config_validated,
|
||||
)
|
||||
)
|
||||
@ -44,15 +45,13 @@ async def async_setup(hass, config):
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Cast from a config entry."""
|
||||
await home_assistant_cast.async_setup_ha_cast(hass, entry)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_remove_entry(hass, entry):
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Remove Home Assistant Cast user."""
|
||||
await home_assistant_cast.async_remove_user(hass, entry)
|
||||
|
@ -4,6 +4,7 @@ import threading
|
||||
|
||||
import pychromecast
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
@ -39,14 +40,14 @@ def discover_chromecast(
|
||||
dispatcher_send(hass, SIGNAL_CAST_DISCOVERED, info)
|
||||
|
||||
|
||||
def _remove_chromecast(hass: HomeAssistant, info: ChromecastInfo):
|
||||
def _remove_chromecast(hass: HomeAssistant, info: ChromecastInfo) -> None:
|
||||
# Removed chromecast
|
||||
_LOGGER.debug("Removed chromecast %s", info)
|
||||
|
||||
dispatcher_send(hass, SIGNAL_CAST_REMOVED, info)
|
||||
|
||||
|
||||
def setup_internal_discovery(hass: HomeAssistant, config_entry) -> None:
|
||||
def setup_internal_discovery(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""Set up the pychromecast internal discovery."""
|
||||
if INTERNAL_DISCOVERY_RUNNING_KEY not in hass.data:
|
||||
hass.data[INTERNAL_DISCOVERY_RUNNING_KEY] = threading.Lock()
|
||||
@ -95,7 +96,7 @@ def setup_internal_discovery(hass: HomeAssistant, config_entry) -> None:
|
||||
config_entry.add_update_listener(config_entry_updated)
|
||||
|
||||
|
||||
async def config_entry_updated(hass, config_entry):
|
||||
async def config_entry_updated(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""Handle config entry being updated."""
|
||||
browser = hass.data[CAST_BROWSER_KEY]
|
||||
browser.host_browser.update_hosts(config_entry.data.get(CONF_KNOWN_HOSTS))
|
||||
|
@ -45,6 +45,7 @@ from homeassistant.components.media_player.const import (
|
||||
)
|
||||
from homeassistant.components.plex.const import PLEX_URI_SCHEME
|
||||
from homeassistant.components.plex.services import lookup_plex_media
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CAST_APP_ID_HOMEASSISTANT_LOVELACE,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
@ -57,6 +58,7 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.logging import async_create_catching_coro
|
||||
@ -121,7 +123,11 @@ def _async_create_cast_device(hass: HomeAssistant, info: ChromecastInfo):
|
||||
return CastDevice(info)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Cast from a config entry."""
|
||||
hass.data.setdefault(ADDED_CAST_DEVICES_KEY, set())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user