Remove port from Elgato configuration flow (#132961)

This commit is contained in:
Franck Nijhof 2024-12-11 20:48:55 +01:00 committed by GitHub
parent 833557fad5
commit 73e68971e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 10 additions and 27 deletions

View File

@ -9,7 +9,7 @@ import voluptuous as vol
from homeassistant.components import onboarding, zeroconf from homeassistant.components import onboarding, zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT from homeassistant.const import CONF_HOST, CONF_MAC
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -34,7 +34,6 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
return self._async_show_setup_form() return self._async_show_setup_form()
self.host = user_input[CONF_HOST] self.host = user_input[CONF_HOST]
self.port = user_input[CONF_PORT]
try: try:
await self._get_elgato_serial_number(raise_on_progress=False) await self._get_elgato_serial_number(raise_on_progress=False)
@ -49,7 +48,6 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle zeroconf discovery.""" """Handle zeroconf discovery."""
self.host = discovery_info.host self.host = discovery_info.host
self.mac = discovery_info.properties.get("id") self.mac = discovery_info.properties.get("id")
self.port = discovery_info.port or 9123
try: try:
await self._get_elgato_serial_number() await self._get_elgato_serial_number()
@ -81,7 +79,6 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
data_schema=vol.Schema( data_schema=vol.Schema(
{ {
vol.Required(CONF_HOST): str, vol.Required(CONF_HOST): str,
vol.Optional(CONF_PORT, default=9123): int,
} }
), ),
errors=errors or {}, errors=errors or {},
@ -93,7 +90,6 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
title=self.serial_number, title=self.serial_number,
data={ data={
CONF_HOST: self.host, CONF_HOST: self.host,
CONF_PORT: self.port,
CONF_MAC: self.mac, CONF_MAC: self.mac,
}, },
) )
@ -103,7 +99,6 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
session = async_get_clientsession(self.hass) session = async_get_clientsession(self.hass)
elgato = Elgato( elgato = Elgato(
host=self.host, host=self.host,
port=self.port,
session=session, session=session,
) )
info = await elgato.info() info = await elgato.info()
@ -113,7 +108,7 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
info.serial_number, raise_on_progress=raise_on_progress info.serial_number, raise_on_progress=raise_on_progress
) )
self._abort_if_unique_id_configured( self._abort_if_unique_id_configured(
updates={CONF_HOST: self.host, CONF_PORT: self.port, CONF_MAC: self.mac} updates={CONF_HOST: self.host, CONF_MAC: self.mac}
) )
self.serial_number = info.serial_number self.serial_number = info.serial_number

View File

@ -5,7 +5,7 @@ from dataclasses import dataclass
from elgato import BatteryInfo, Elgato, ElgatoConnectionError, Info, Settings, State from elgato import BatteryInfo, Elgato, ElgatoConnectionError, Info, Settings, State
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -34,7 +34,6 @@ class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
self.config_entry = entry self.config_entry = entry
self.client = Elgato( self.client = Elgato(
entry.data[CONF_HOST], entry.data[CONF_HOST],
port=entry.data[CONF_PORT],
session=async_get_clientsession(hass), session=async_get_clientsession(hass),
) )
super().__init__( super().__init__(

View File

@ -5,10 +5,7 @@ rules:
brands: done brands: done
common-modules: done common-modules: done
config-flow-test-coverage: done config-flow-test-coverage: done
config-flow: config-flow: done
status: todo
comment: |
The data_description for port is missing.
dependency-transparency: done dependency-transparency: done
docs-actions: done docs-actions: done
docs-high-level-description: done docs-high-level-description: done

View File

@ -5,8 +5,7 @@
"user": { "user": {
"description": "Set up your Elgato Light to integrate with Home Assistant.", "description": "Set up your Elgato Light to integrate with Home Assistant.",
"data": { "data": {
"host": "[%key:common::config_flow::data::host%]", "host": "[%key:common::config_flow::data::host%]"
"port": "[%key:common::config_flow::data::port%]"
}, },
"data_description": { "data_description": {
"host": "The hostname or IP address of your Elgato device." "host": "The hostname or IP address of your Elgato device."

View File

@ -7,7 +7,7 @@ from elgato import BatteryInfo, ElgatoNoBatteryError, Info, Settings, State
import pytest import pytest
from homeassistant.components.elgato.const import DOMAIN from homeassistant.components.elgato.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT from homeassistant.const import CONF_HOST, CONF_MAC
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, get_fixture_path, load_fixture from tests.common import MockConfigEntry, get_fixture_path, load_fixture
@ -35,7 +35,6 @@ def mock_config_entry() -> MockConfigEntry:
data={ data={
CONF_HOST: "127.0.0.1", CONF_HOST: "127.0.0.1",
CONF_MAC: "AA:BB:CC:DD:EE:FF", CONF_MAC: "AA:BB:CC:DD:EE:FF",
CONF_PORT: 9123,
}, },
unique_id="CN11A1A00001", unique_id="CN11A1A00001",
) )

View File

@ -8,7 +8,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': None, 'mac': None,
'port': 9123,
}), }),
'description': None, 'description': None,
'description_placeholders': None, 'description_placeholders': None,
@ -21,7 +20,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': None, 'mac': None,
'port': 9123,
}), }),
'disabled_by': None, 'disabled_by': None,
'discovery_keys': dict({ 'discovery_keys': dict({
@ -53,7 +51,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': 'AA:BB:CC:DD:EE:FF', 'mac': 'AA:BB:CC:DD:EE:FF',
'port': 9123,
}), }),
'description': None, 'description': None,
'description_placeholders': None, 'description_placeholders': None,
@ -66,7 +63,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': 'AA:BB:CC:DD:EE:FF', 'mac': 'AA:BB:CC:DD:EE:FF',
'port': 9123,
}), }),
'disabled_by': None, 'disabled_by': None,
'discovery_keys': dict({ 'discovery_keys': dict({
@ -97,7 +93,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': 'AA:BB:CC:DD:EE:FF', 'mac': 'AA:BB:CC:DD:EE:FF',
'port': 9123,
}), }),
'description': None, 'description': None,
'description_placeholders': None, 'description_placeholders': None,
@ -110,7 +105,6 @@
'data': dict({ 'data': dict({
'host': '127.0.0.1', 'host': '127.0.0.1',
'mac': 'AA:BB:CC:DD:EE:FF', 'mac': 'AA:BB:CC:DD:EE:FF',
'port': 9123,
}), }),
'disabled_by': None, 'disabled_by': None,
'discovery_keys': dict({ 'discovery_keys': dict({

View File

@ -10,7 +10,7 @@ from syrupy.assertion import SnapshotAssertion
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.elgato.const import DOMAIN from homeassistant.components.elgato.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SOURCE from homeassistant.const import CONF_HOST, CONF_SOURCE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -33,7 +33,7 @@ async def test_full_user_flow_implementation(
assert result.get("step_id") == "user" assert result.get("step_id") == "user"
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "127.0.0.1", CONF_PORT: 9123} result["flow_id"], user_input={CONF_HOST: "127.0.0.1"}
) )
assert result2.get("type") is FlowResultType.CREATE_ENTRY assert result2.get("type") is FlowResultType.CREATE_ENTRY
@ -94,7 +94,7 @@ async def test_connection_error(
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 9123}, data={CONF_HOST: "127.0.0.1"},
) )
assert result.get("type") is FlowResultType.FORM assert result.get("type") is FlowResultType.FORM
@ -135,7 +135,7 @@ async def test_user_device_exists_abort(
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 9123}, data={CONF_HOST: "127.0.0.1"},
) )
assert result.get("type") is FlowResultType.ABORT assert result.get("type") is FlowResultType.ABORT