core/homeassistant/components/dlna_dmr/config_flow.py

496 lines
18 KiB
Python
Raw Normal View History

Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
"""Config flow for DLNA DMR."""
from __future__ import annotations
from collections.abc import Callable
import logging
from pprint import pformat
from typing import Any, Mapping, Optional, cast
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
from urllib.parse import urlparse
from async_upnp_client.client import UpnpError
from async_upnp_client.profiles.dlna import DmrDevice
from async_upnp_client.profiles.profile import find_device_of_type
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import ssdp
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_HOST,
CONF_NAME,
CONF_TYPE,
CONF_URL,
)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import IntegrationError
import homeassistant.helpers.config_validation as cv
from .const import (
CONF_CALLBACK_URL_OVERRIDE,
CONF_LISTEN_PORT,
CONF_POLL_AVAILABILITY,
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
DEFAULT_NAME,
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
DOMAIN,
)
from .data import get_domain_data
LOGGER = logging.getLogger(__name__)
FlowInput = Optional[Mapping[str, Any]]
class ConnectError(IntegrationError):
"""Error occurred when trying to connect to a device."""
class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a DLNA DMR config flow.
The Unique Device Name (UDN) of the DMR device is used as the unique_id for
config entries and for entities. This UDN may differ from the root UDN if
the DMR is an embedded device.
"""
VERSION = 1
def __init__(self) -> None:
"""Initialize flow."""
self._discoveries: dict[str, ssdp.SsdpServiceInfo] = {}
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._location: str | None = None
self._udn: str | None = None
self._device_type: str | None = None
self._name: str | None = None
self._options: dict[str, Any] = {}
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
@staticmethod
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> config_entries.OptionsFlow:
"""Define the config flow to handle options."""
return DlnaDmrOptionsFlowHandler(config_entry)
async def async_step_user(self, user_input: FlowInput = None) -> FlowResult:
"""Handle a flow initialized by the user.
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Let user choose from a list of found and unconfigured devices or to
enter an URL manually.
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
"""
LOGGER.debug("async_step_user: user_input: %s", user_input)
if user_input is not None:
2021-10-30 14:33:42 +00:00
if not (host := user_input.get(CONF_HOST)):
# No device chosen, user might want to directly enter an URL
return await self.async_step_manual()
# User has chosen a device, ask for confirmation
discovery = self._discoveries[host]
await self._async_set_info_from_discovery(discovery)
return self._create_entry()
2021-10-31 17:56:25 +00:00
if not (discoveries := await self._async_get_discoveries()):
# Nothing found, maybe the user knows an URL to try
return await self.async_step_manual()
self._discoveries = {
discovery.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
or cast(str, urlparse(discovery.ssdp_location).hostname): discovery
for discovery in discoveries
}
data_schema = vol.Schema(
{vol.Optional(CONF_HOST): vol.In(self._discoveries.keys())}
)
return self.async_show_form(step_id="user", data_schema=data_schema)
async def async_step_manual(self, user_input: FlowInput = None) -> FlowResult:
"""Manual URL entry by the user."""
LOGGER.debug("async_step_manual: user_input: %s", user_input)
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# Device setup manually, assume we don't get SSDP broadcast notifications
self._options[CONF_POLL_AVAILABILITY] = True
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
errors = {}
if user_input is not None:
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._location = user_input[CONF_URL]
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
try:
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
await self._async_connect()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
except ConnectError as err:
errors["base"] = err.args[0]
else:
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
return self._create_entry()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
data_schema = vol.Schema({CONF_URL: str})
return self.async_show_form(
step_id="manual", data_schema=data_schema, errors=errors
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
)
async def async_step_import(self, import_data: FlowInput = None) -> FlowResult:
"""Import a new DLNA DMR device from a config entry.
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
This flow is triggered by `async_setup_platform`. If the device has not
been migrated, and can be connected to, automatically import it. If it
cannot be connected to, prompt the user to turn it on. If it has already
been migrated, do nothing.
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
"""
LOGGER.debug("async_step_import: import_data: %s", import_data)
if not import_data or CONF_URL not in import_data:
LOGGER.debug("Entry not imported: incomplete_config")
return self.async_abort(reason="incomplete_config")
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._location = import_data[CONF_URL]
self._async_abort_entries_match({CONF_URL: self._location})
# Use the location as this config flow's unique ID until UDN is known
await self.async_set_unique_id(self._location)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# Set options from the import_data, except listen_ip which is no longer used
self._options[CONF_LISTEN_PORT] = import_data.get(CONF_LISTEN_PORT)
self._options[CONF_CALLBACK_URL_OVERRIDE] = import_data.get(
CONF_CALLBACK_URL_OVERRIDE
)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# Override device name if it's set in the YAML
self._name = import_data.get(CONF_NAME)
discoveries = await self._async_get_discoveries()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
# Find the device in the list of unconfigured devices
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
for discovery in discoveries:
if discovery.ssdp_location == self._location:
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
# Device found via SSDP, it shouldn't need polling
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._options[CONF_POLL_AVAILABILITY] = False
# Discovery info has everything required to create config entry
await self._async_set_info_from_discovery(discovery)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
LOGGER.debug(
"Entry %s found via SSDP, with UDN %s",
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._location,
self._udn,
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
)
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
return self._create_entry()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# This device will need to be polled
self._options[CONF_POLL_AVAILABILITY] = True
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# Device was not found via SSDP, connect directly for configuration
try:
await self._async_connect()
except ConnectError as err:
# This will require user action
LOGGER.debug("Entry %s not imported yet: %s", self._location, err.args[0])
return await self.async_step_import_turn_on()
LOGGER.debug("Entry %s ready for import", self._location)
return self._create_entry()
async def async_step_import_turn_on(
self, user_input: FlowInput = None
) -> FlowResult:
"""Request the user to turn on the device so that import can finish."""
LOGGER.debug("async_step_import_turn_on: %s", user_input)
self.context["title_placeholders"] = {"name": self._name or self._location}
errors = {}
if user_input is not None:
try:
await self._async_connect()
except ConnectError as err:
errors["base"] = err.args[0]
else:
return self._create_entry()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._set_confirm_only()
return self.async_show_form(step_id="import_turn_on", errors=errors)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
"""Handle a flow initialized by SSDP discovery."""
LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info))
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
await self._async_set_info_from_discovery(discovery_info)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
if _is_ignored_device(discovery_info):
return self.async_abort(reason="alternative_integration")
# Abort if the device doesn't support all services required for a DmrDevice.
# Use the discovery_info instead of DmrDevice.is_profile_device to avoid
# contacting the device again.
discovery_service_list = discovery_info.upnp.get(ssdp.ATTR_UPNP_SERVICE_LIST)
if not discovery_service_list:
return self.async_abort(reason="not_dmr")
discovery_service_ids = {
service.get("serviceId")
for service in discovery_service_list.get("service") or []
}
if not DmrDevice.SERVICE_IDS.issubset(discovery_service_ids):
return self.async_abort(reason="not_dmr")
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
# Abort if a migration flow for the device's location is in progress
for progress in self._async_in_progress(include_uninitialized=True):
if progress["context"].get("unique_id") == self._location:
LOGGER.debug(
"Aborting SSDP setup because migration for %s is in progress",
self._location,
)
return self.async_abort(reason="already_in_progress")
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
2021-11-23 22:22:34 +00:00
# Abort if another config entry has the same location, in case the
# device doesn't have a static and unique UDN (breaking the UPnP spec).
self._async_abort_entries_match({CONF_URL: self._location})
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self.context["title_placeholders"] = {"name": self._name}
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
return await self.async_step_confirm()
async def async_step_unignore(self, user_input: Mapping[str, Any]) -> FlowResult:
"""Rediscover previously ignored devices by their unique_id."""
LOGGER.debug("async_step_unignore: user_input: %s", user_input)
self._udn = user_input["unique_id"]
assert self._udn
await self.async_set_unique_id(self._udn)
# Find a discovery matching the unignored unique_id for a DMR device
for dev_type in DmrDevice.DEVICE_TYPES:
discovery = await ssdp.async_get_discovery_info_by_udn_st(
self.hass, self._udn, dev_type
)
if discovery:
break
else:
return self.async_abort(reason="discovery_error")
await self._async_set_info_from_discovery(discovery, abort_if_configured=False)
self.context["title_placeholders"] = {"name": self._name}
return await self.async_step_confirm()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
async def async_step_confirm(self, user_input: FlowInput = None) -> FlowResult:
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
"""Allow the user to confirm adding the device."""
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
LOGGER.debug("async_step_confirm: %s", user_input)
if user_input is not None:
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
return self._create_entry()
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
self._set_confirm_only()
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
return self.async_show_form(step_id="confirm")
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
async def _async_connect(self) -> None:
"""Connect to a device to confirm it works and gather extra information.
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
Updates this flow's unique ID to the device UDN if not already done.
Raises ConnectError if something goes wrong.
"""
LOGGER.debug("_async_connect: location: %s", self._location)
assert self._location, "self._location has not been set before connect"
domain_data = get_domain_data(self.hass)
try:
device = await domain_data.upnp_factory.async_create_device(self._location)
except UpnpError as err:
raise ConnectError("cannot_connect") from err
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
if not DmrDevice.is_profile_device(device):
raise ConnectError("not_dmr")
device = find_device_of_type(device, DmrDevice.DEVICE_TYPES)
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
if not self._udn:
self._udn = device.udn
await self.async_set_unique_id(self._udn)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
# Abort if already configured, but update the last-known location
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._abort_if_unique_id_configured(
updates={CONF_URL: self._location}, reload_on_update=False
)
if not self._device_type:
self._device_type = device.device_type
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
if not self._name:
self._name = device.name
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
def _create_entry(self) -> FlowResult:
"""Create a config entry, assuming all required information is now known."""
LOGGER.debug(
"_async_create_entry: location: %s, UDN: %s", self._location, self._udn
)
assert self._location
assert self._udn
assert self._device_type
title = self._name or urlparse(self._location).hostname or DEFAULT_NAME
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
data = {
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
CONF_URL: self._location,
CONF_DEVICE_ID: self._udn,
CONF_TYPE: self._device_type,
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
}
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
return self.async_create_entry(title=title, data=data, options=self._options)
async def _async_set_info_from_discovery(
self, discovery_info: ssdp.SsdpServiceInfo, abort_if_configured: bool = True
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
) -> None:
"""Set information required for a config entry from the SSDP discovery."""
LOGGER.debug(
"_async_set_info_from_discovery: location: %s, UDN: %s",
discovery_info.ssdp_location,
discovery_info.ssdp_udn,
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
)
if not self._location:
self._location = discovery_info.ssdp_location
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
assert isinstance(self._location, str)
self._udn = discovery_info.ssdp_udn
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
await self.async_set_unique_id(self._udn)
if abort_if_configured:
# Abort if already configured, but update the last-known location
self._abort_if_unique_id_configured(
updates={CONF_URL: self._location}, reload_on_update=False
)
self._device_type = discovery_info.ssdp_nt or discovery_info.ssdp_st
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
self._name = (
discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
Improve dlna_dmr code quality (#56886) * Listen for config updates from DlnaDmrEntity.async_added_to_hass Use `Entity.async_on_remove` for dealing with callback cancellation, instead of re-inventing the wheel with `_remove_ssdp_callbacks`. * Use async_write_ha_state within async methods * Import YAML config from async_setup_platform * Import flow prompts user when device is uncontactable during migration When config flow is able to contact a device, or when it has information from SSDP, it will create config entries without error. If the device is uncontactable at this point then it will appear as unavailable in HA until it is turned on again. When import flow cannot migrate an entry because it needs to contact the device and can't, it will notify the user with a config flow form. * Don't del unused parameters, HA pylint doesn't care * Remove unused imports from tests * Abort config flow at earliest opportunity * Return async_abort instead of raising AbortFlow * Consolidate config entry test cleanup into a single function * fixup! Consolidate config entry test cleanup into a single function Revert "Consolidate config entry test cleanup into a single function" This reverts commit 8220da7263e346a37c3e1a219dc374c4a43c7df5. * Check resource acquisition/release in specific tests * fixup! Check resource acquisition/release in specific tests * Remove unused network dependency from manifest * _on_event runs in async context * Call async_write_ha_state directly (not via shedule_update) Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 20:14:00 +00:00
or urlparse(self._location).hostname
or DEFAULT_NAME
)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
async def _async_get_discoveries(self) -> list[ssdp.SsdpServiceInfo]:
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
"""Get list of unconfigured DLNA devices discovered by SSDP."""
LOGGER.debug("_get_discoveries")
# Get all compatible devices from ssdp's cache
discoveries: list[ssdp.SsdpServiceInfo] = []
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
for udn_st in DmrDevice.DEVICE_TYPES:
st_discoveries = await ssdp.async_get_discovery_info_by_st(
self.hass, udn_st
)
discoveries.extend(st_discoveries)
# Filter out devices already configured
current_unique_ids = {
entry.unique_id
for entry in self._async_current_entries(include_ignore=False)
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
}
discoveries = [
disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
]
return discoveries
class DlnaDmrOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle a DLNA DMR options flow.
Configures the single instance and updates the existing config entry.
"""
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize."""
self.config_entry = config_entry
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage the options."""
errors: dict[str, str] = {}
# Don't modify existing (read-only) options -- copy and update instead
options = dict(self.config_entry.options)
if user_input is not None:
LOGGER.debug("user_input: %s", user_input)
listen_port = user_input.get(CONF_LISTEN_PORT) or None
callback_url_override = user_input.get(CONF_CALLBACK_URL_OVERRIDE) or None
try:
# Cannot use cv.url validation in the schema itself so apply
# extra validation here
if callback_url_override:
cv.url(callback_url_override)
except vol.Invalid:
errors["base"] = "invalid_url"
options[CONF_LISTEN_PORT] = listen_port
options[CONF_CALLBACK_URL_OVERRIDE] = callback_url_override
options[CONF_POLL_AVAILABILITY] = user_input[CONF_POLL_AVAILABILITY]
# Save if there's no errors, else fall through and show the form again
if not errors:
return self.async_create_entry(title="", data=options)
fields = {}
def _add_with_suggestion(key: str, validator: Callable) -> None:
"""Add a field to with a suggested, not default, value."""
2021-10-22 09:31:17 +00:00
if (suggested_value := options.get(key)) is None:
Config-flow for DLNA-DMR integration (#55267) * Modernize dlna_dmr component: configflow, test, types * Support config-flow with ssdp discovery * Add unit tests * Enforce strict typing * Gracefully handle network devices (dis)appearing * Fix Aiohttp mock response headers type to match actual response class * Fixes from code review * Fixes from code review * Import device config in flow if unavailable at hass start * Support SSDP advertisements * Ignore bad BOOTID, fix ssdp:byebye handling * Only listen for events on interface connected to device * Release all listeners when entities are removed * Warn about deprecated dlna_dmr configuration * Use sublogger for dlna_dmr.config_flow for easier filtering * Tests for dlna_dmr.data module * Rewrite DMR tests for HA style * Fix DMR strings: "Digital Media *Renderer*" * Update DMR entity state and device info when changed * Replace deprecated async_upnp_client State with TransportState * supported_features are dynamic, based on current device state * Cleanup fully when subscription fails * Log warnings when device connection fails unexpectedly * Set PARALLEL_UPDATES to unlimited * Fix spelling * Fixes from code review * Simplify has & can checks to just can, which includes has * Treat transitioning state as playing (not idle) to reduce UI jerking * Test if device is usable * Handle ssdp:update messages properly * Fix _remove_ssdp_callbacks being shared by all DlnaDmrEntity instances * Fix tests for transitioning state * Mock DmrDevice.is_profile_device (added to support embedded devices) * Use ST & NT SSDP headers to find DMR devices, not deviceType The deviceType is extracted from the device's description XML, and will not be what we want when dealing with embedded devices. * Use UDN from SSDP headers, not device description, as unique_id The SSDP headers have the UDN of the embedded device that we're interested in, whereas the device description (`ATTR_UPNP_UDN`) field will always be for the root device. * Fix DMR string English localization * Test config flow with UDN from SSDP headers * Bump async-upnp-client==0.22.1, fix flake8 error * fix test for remapping * DMR HA Device connections based on root and embedded UDN * DmrDevice's UpnpDevice is now named profile_device * Use device type from SSDP headers, not device description * Mark dlna_dmr constants as Final * Use embedded device UDN and type for unique ID when connected via URL * More informative connection error messages * Also match SSDP messages on NT headers The NT header is to ssdp:alive messages what ST is to M-SEARCH responses. * Bump async-upnp-client==0.22.2 * fix merge * Bump async-upnp-client==0.22.3 Co-authored-by: Steven Looman <steven.looman@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-27 20:47:01 +00:00
fields[vol.Optional(key)] = validator
else:
fields[
vol.Optional(key, description={"suggested_value": suggested_value})
] = validator
# listen_port can be blank or 0 for "bind any free port"
_add_with_suggestion(CONF_LISTEN_PORT, cv.port)
_add_with_suggestion(CONF_CALLBACK_URL_OVERRIDE, str)
fields[
vol.Required(
CONF_POLL_AVAILABILITY,
default=options.get(CONF_POLL_AVAILABILITY, False),
)
] = bool
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(fields),
errors=errors,
)
def _is_ignored_device(discovery_info: ssdp.SsdpServiceInfo) -> bool:
"""Return True if this device should be ignored for discovery.
These devices are supported better by other integrations, so don't bug
the user about them. The user can add them if desired by via the user config
flow, which will list all discovered but unconfigured devices.
"""
# Did the discovery trigger more than just this flow?
if len(discovery_info.x_homeassistant_matching_domains) > 1:
LOGGER.debug(
"Ignoring device supported by multiple integrations: %s",
discovery_info.x_homeassistant_matching_domains,
)
return True
# Is the root device not a DMR?
if (
discovery_info.upnp.get(ssdp.ATTR_UPNP_DEVICE_TYPE)
not in DmrDevice.DEVICE_TYPES
):
return True
# Special cases for devices with other discovery methods (e.g. mDNS), or
# that advertise multiple unrelated (sent in separate discovery packets)
# UPnP devices.
manufacturer = discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER, "").lower()
model = discovery_info.upnp.get(ssdp.ATTR_UPNP_MODEL_NAME, "").lower()
if manufacturer.startswith("xbmc") or model == "kodi":
# kodi
return True
2021-11-23 22:22:34 +00:00
if "philips" in manufacturer and "tv" in model:
# philips_js
# These TVs don't have a stable UDN, so also get discovered as a new
# device every time they are turned on.
return True
if manufacturer.startswith("samsung") and "tv" in model:
# samsungtv
return True
if manufacturer.startswith("lg") and "tv" in model:
# webostv
return True
return False