mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move dlna_dmr imports at top-level (#29082)
This commit is contained in:
parent
5015993f30
commit
844eb6b8ef
@ -6,9 +6,12 @@ import logging
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from async_upnp_client import UpnpFactory
|
||||||
|
from async_upnp_client.aiohttp import AiohttpNotifyServer, AiohttpSessionRequester
|
||||||
|
from async_upnp_client.profiles.dlna import DeviceState, DmrDevice
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA
|
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerDevice
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_TYPE_CHANNEL,
|
MEDIA_TYPE_CHANNEL,
|
||||||
MEDIA_TYPE_EPISODE,
|
MEDIA_TYPE_EPISODE,
|
||||||
@ -40,10 +43,10 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
import homeassistant.util.dt as dt_util
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
from homeassistant.util import get_local_ip
|
from homeassistant.util import get_local_ip
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -121,8 +124,6 @@ async def async_start_event_handler(
|
|||||||
return hass_data["event_handler"]
|
return hass_data["event_handler"]
|
||||||
|
|
||||||
# start event handler
|
# start event handler
|
||||||
from async_upnp_client.aiohttp import AiohttpNotifyServer
|
|
||||||
|
|
||||||
server = AiohttpNotifyServer(
|
server = AiohttpNotifyServer(
|
||||||
requester,
|
requester,
|
||||||
listen_port=server_port,
|
listen_port=server_port,
|
||||||
@ -163,8 +164,6 @@ async def async_setup_platform(
|
|||||||
hass.data[DLNA_DMR_DATA]["lock"] = asyncio.Lock()
|
hass.data[DLNA_DMR_DATA]["lock"] = asyncio.Lock()
|
||||||
|
|
||||||
# build upnp/aiohttp requester
|
# build upnp/aiohttp requester
|
||||||
from async_upnp_client.aiohttp import AiohttpSessionRequester
|
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
requester = AiohttpSessionRequester(session, True)
|
requester = AiohttpSessionRequester(session, True)
|
||||||
|
|
||||||
@ -180,8 +179,6 @@ async def async_setup_platform(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# create upnp device
|
# create upnp device
|
||||||
from async_upnp_client import UpnpFactory
|
|
||||||
|
|
||||||
factory = UpnpFactory(requester, disable_state_variable_validation=True)
|
factory = UpnpFactory(requester, disable_state_variable_validation=True)
|
||||||
try:
|
try:
|
||||||
upnp_device = await factory.async_create_device(url)
|
upnp_device = await factory.async_create_device(url)
|
||||||
@ -189,8 +186,6 @@ async def async_setup_platform(
|
|||||||
raise PlatformNotReady()
|
raise PlatformNotReady()
|
||||||
|
|
||||||
# wrap with DmrDevice
|
# wrap with DmrDevice
|
||||||
from async_upnp_client.profiles.dlna import DmrDevice
|
|
||||||
|
|
||||||
dlna_device = DmrDevice(upnp_device, event_handler)
|
dlna_device = DmrDevice(upnp_device, event_handler)
|
||||||
|
|
||||||
# create our own device
|
# create our own device
|
||||||
@ -361,8 +356,6 @@ class DlnaDmrDevice(MediaPlayerDevice):
|
|||||||
await self._device.async_wait_for_can_play()
|
await self._device.async_wait_for_can_play()
|
||||||
|
|
||||||
# If already playing, no need to call Play
|
# If already playing, no need to call Play
|
||||||
from async_upnp_client.profiles.dlna import DeviceState
|
|
||||||
|
|
||||||
if self._device.state == DeviceState.PLAYING:
|
if self._device.state == DeviceState.PLAYING:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -403,8 +396,6 @@ class DlnaDmrDevice(MediaPlayerDevice):
|
|||||||
if not self._available:
|
if not self._available:
|
||||||
return STATE_OFF
|
return STATE_OFF
|
||||||
|
|
||||||
from async_upnp_client.profiles.dlna import DeviceState
|
|
||||||
|
|
||||||
if self._device.state is None:
|
if self._device.state is None:
|
||||||
return STATE_ON
|
return STATE_ON
|
||||||
if self._device.state == DeviceState.PLAYING:
|
if self._device.state == DeviceState.PLAYING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user