Replace util.get_local_ip in favor of components.network.async_get_source_ip() - part 3 (#53424)

This commit is contained in:
Simone Chemelli 2021-07-27 21:19:29 +02:00 committed by GitHub
parent f3bf0fdb09
commit 5a6be2370b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -1,7 +1,9 @@
"""Support for Roku API emulation."""
import voluptuous as vol
from homeassistant import config_entries, util
from homeassistant import config_entries
from homeassistant.components.network import async_get_source_ip
from homeassistant.components.network.const import PUBLIC_TARGET_IP
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv
@ -71,7 +73,9 @@ async def async_setup_entry(hass, config_entry):
name = config[CONF_NAME]
listen_port = config[CONF_LISTEN_PORT]
host_ip = config.get(CONF_HOST_IP) or util.get_local_ip()
host_ip = config.get(CONF_HOST_IP) or await async_get_source_ip(
hass, PUBLIC_TARGET_IP
)
advertise_ip = config.get(CONF_ADVERTISE_IP)
advertise_port = config.get(CONF_ADVERTISE_PORT)
upnp_bind_multicast = config.get(CONF_UPNP_BIND_MULTICAST)

View File

@ -4,6 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/emulated_roku",
"requirements": ["emulated_roku==0.2.1"],
"dependencies": ["network"],
"codeowners": [],
"iot_class": "local_push"
}

View File

@ -93,7 +93,11 @@ async def test_setup_entry_successful(hass):
async def test_unload_entry(hass):
"""Test being able to unload an entry."""
entry = Mock()
entry.data = {"name": "Emulated Roku Test", "listen_port": 8060}
entry.data = {
"name": "Emulated Roku Test",
"listen_port": 8060,
emulated_roku.CONF_HOST_IP: "1.2.3.5",
}
with patch(
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",