mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Small improvements to ESPHome setup (#143204)
This commit is contained in:
parent
b487c12ab1
commit
e07c29caad
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from aioesphomeapi import APIClient
|
from aioesphomeapi import APIClient
|
||||||
|
|
||||||
from homeassistant.components import ffmpeg, zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.bluetooth import async_remove_scanner
|
from homeassistant.components.bluetooth import async_remove_scanner
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -17,13 +17,10 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers.issue_registry import async_delete_issue
|
from homeassistant.helpers.issue_registry import async_delete_issue
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import CONF_BLUETOOTH_MAC_ADDRESS, CONF_NOISE_PSK, DATA_FFMPEG_PROXY, DOMAIN
|
from . import dashboard, ffmpeg_proxy
|
||||||
from .dashboard import async_setup as async_setup_dashboard
|
from .const import CONF_BLUETOOTH_MAC_ADDRESS, CONF_NOISE_PSK, DOMAIN
|
||||||
from .domain_data import DomainData
|
from .domain_data import DomainData
|
||||||
|
|
||||||
# Import config flow so that it's added to the registry
|
|
||||||
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
||||||
from .ffmpeg_proxy import FFmpegProxyData, FFmpegProxyView
|
|
||||||
from .manager import DEVICE_CONFLICT_ISSUE_FORMAT, ESPHomeManager, cleanup_instance
|
from .manager import DEVICE_CONFLICT_ISSUE_FORMAT, ESPHomeManager, cleanup_instance
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
@ -33,12 +30,8 @@ CLIENT_INFO = f"Home Assistant {ha_version}"
|
|||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the esphome component."""
|
"""Set up the esphome component."""
|
||||||
proxy_data = hass.data[DATA_FFMPEG_PROXY] = FFmpegProxyData()
|
ffmpeg_proxy.async_setup(hass)
|
||||||
|
await dashboard.async_setup(hass)
|
||||||
await async_setup_dashboard(hass)
|
|
||||||
hass.http.register_view(
|
|
||||||
FFmpegProxyView(ffmpeg.get_ffmpeg_manager(hass), proxy_data)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,5 +22,3 @@ PROJECT_URLS = {
|
|||||||
# ESPHome always uses .0 for the changelog URL
|
# ESPHome always uses .0 for the changelog URL
|
||||||
STABLE_BLE_URL_VERSION = f"{STABLE_BLE_VERSION.major}.{STABLE_BLE_VERSION.minor}.0"
|
STABLE_BLE_URL_VERSION = f"{STABLE_BLE_VERSION.major}.{STABLE_BLE_VERSION.minor}.0"
|
||||||
DEFAULT_URL = f"https://esphome.io/changelog/{STABLE_BLE_URL_VERSION}.html"
|
DEFAULT_URL = f"https://esphome.io/changelog/{STABLE_BLE_URL_VERSION}.html"
|
||||||
|
|
||||||
DATA_FFMPEG_PROXY = f"{DOMAIN}.ffmpeg_proxy"
|
|
||||||
|
@ -11,17 +11,20 @@ from typing import Final
|
|||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiohttp.abc import AbstractStreamWriter, BaseRequest
|
from aiohttp.abc import AbstractStreamWriter, BaseRequest
|
||||||
|
|
||||||
|
from homeassistant.components import ffmpeg
|
||||||
from homeassistant.components.ffmpeg import FFmpegManager
|
from homeassistant.components.ffmpeg import FFmpegManager
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
from .const import DATA_FFMPEG_PROXY
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
_MAX_CONVERSIONS_PER_DEVICE: Final[int] = 2
|
_MAX_CONVERSIONS_PER_DEVICE: Final[int] = 2
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
def async_create_proxy_url(
|
def async_create_proxy_url(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_id: str,
|
device_id: str,
|
||||||
@ -32,7 +35,7 @@ def async_create_proxy_url(
|
|||||||
width: int | None = None,
|
width: int | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Create a use proxy URL that automatically converts the media."""
|
"""Create a use proxy URL that automatically converts the media."""
|
||||||
data: FFmpegProxyData = hass.data[DATA_FFMPEG_PROXY]
|
data = hass.data[DATA_FFMPEG_PROXY]
|
||||||
return data.async_create_proxy_url(
|
return data.async_create_proxy_url(
|
||||||
device_id, media_url, media_format, rate, channels, width
|
device_id, media_url, media_format, rate, channels, width
|
||||||
)
|
)
|
||||||
@ -313,3 +316,16 @@ class FFmpegProxyView(HomeAssistantView):
|
|||||||
assert writer is not None
|
assert writer is not None
|
||||||
await resp.transcode(request, writer)
|
await resp.transcode(request, writer)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
DATA_FFMPEG_PROXY: HassKey[FFmpegProxyData] = HassKey(f"{DOMAIN}.ffmpeg_proxy")
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_setup(hass: HomeAssistant) -> None:
|
||||||
|
"""Set up the ffmpeg proxy."""
|
||||||
|
proxy_data = FFmpegProxyData()
|
||||||
|
hass.data[DATA_FFMPEG_PROXY] = proxy_data
|
||||||
|
hass.http.register_view(
|
||||||
|
FFmpegProxyView(ffmpeg.get_ffmpeg_manager(hass), proxy_data)
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user