Add support for accessing Squeezebox over over https (#95088)
* Supports access to squeezebox server behind https reverse proxy * Update squeezebox test * Update homeassistant/components/squeezebox/config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/squeezebox/config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update squeezebox unit tests based on code review * Migration unit test * Run black on suggestions accepted in code review * Apply suggestions from code review Instead of upgrading squeezebox config, just assume a default of https=False. Co-authored-by: Erik Montnemery <erik@montnemery.com> * Update test_init.py Remove migrate entry test since we are no longer migrating * Delete tests/components/squeezebox/test_init.py Remove unused test --------- Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
a10f580815
commit
45f7ffb34c
8 changed files with 33 additions and 11 deletions
|
@ -15,7 +15,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
from homeassistant.helpers.device_registry import format_mac
|
||||
from homeassistant.helpers.entity_registry import async_get
|
||||
|
||||
from .const import DEFAULT_PORT, DOMAIN
|
||||
from .const import CONF_HTTPS, DEFAULT_PORT, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -49,9 +49,15 @@ def _base_schema(discovery_info=None):
|
|||
)
|
||||
else:
|
||||
base_schema.update({vol.Required(CONF_PORT, default=DEFAULT_PORT): int})
|
||||
|
||||
base_schema.update(
|
||||
{vol.Optional(CONF_USERNAME): str, vol.Optional(CONF_PASSWORD): str}
|
||||
{
|
||||
vol.Optional(CONF_USERNAME): str,
|
||||
vol.Optional(CONF_PASSWORD): str,
|
||||
vol.Optional(CONF_HTTPS, default=False): bool,
|
||||
}
|
||||
)
|
||||
|
||||
return vol.Schema(base_schema)
|
||||
|
||||
|
||||
|
@ -105,6 +111,7 @@ class SqueezeboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
data[CONF_PORT],
|
||||
data.get(CONF_USERNAME),
|
||||
data.get(CONF_PASSWORD),
|
||||
https=data[CONF_HTTPS],
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -6,3 +6,4 @@ PLAYER_DISCOVERY_UNSUB = "player_discovery_unsub"
|
|||
DISCOVERY_TASK = "discovery_task"
|
||||
DEFAULT_PORT = 9000
|
||||
SQUEEZEBOX_SOURCE_STRINGS = ("source:", "wavin:", "spotify:")
|
||||
CONF_HTTPS = "https"
|
||||
|
|
|
@ -12,5 +12,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/squeezebox",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["pysqueezebox"],
|
||||
"requirements": ["pysqueezebox==0.6.3"]
|
||||
"requirements": ["pysqueezebox==0.7.1"]
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ from .browse_media import (
|
|||
media_source_content_filter,
|
||||
)
|
||||
from .const import (
|
||||
CONF_HTTPS,
|
||||
DISCOVERY_TASK,
|
||||
DOMAIN,
|
||||
KNOWN_PLAYERS,
|
||||
|
@ -126,6 +127,7 @@ async def async_setup_entry(
|
|||
password = config.get(CONF_PASSWORD)
|
||||
host = config[CONF_HOST]
|
||||
port = config[CONF_PORT]
|
||||
https = config.get(CONF_HTTPS, False)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN].setdefault(config_entry.entry_id, {})
|
||||
|
@ -134,7 +136,7 @@ async def async_setup_entry(
|
|||
|
||||
session = async_get_clientsession(hass)
|
||||
_LOGGER.debug("Creating LMS object for %s", host)
|
||||
lms = Server(session, host, port, username, password)
|
||||
lms = Server(session, host, port, username, password, https=https)
|
||||
|
||||
async def _discovery(now=None):
|
||||
"""Discover squeezebox players by polling server."""
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
"host": "[%key:common::config_flow::data::host%]",
|
||||
"port": "[%key:common::config_flow::data::port%]",
|
||||
"username": "[%key:common::config_flow::data::username%]",
|
||||
"password": "[%key:common::config_flow::data::password%]"
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"https": "Connect over https (requires reverse proxy)"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -2098,7 +2098,7 @@ pysoma==0.0.12
|
|||
pyspcwebgw==0.7.0
|
||||
|
||||
# homeassistant.components.squeezebox
|
||||
pysqueezebox==0.6.3
|
||||
pysqueezebox==0.7.1
|
||||
|
||||
# homeassistant.components.stiebel_eltron
|
||||
pystiebeleltron==0.0.1.dev2
|
||||
|
|
|
@ -1597,7 +1597,7 @@ pysoma==0.0.12
|
|||
pyspcwebgw==0.7.0
|
||||
|
||||
# homeassistant.components.squeezebox
|
||||
pysqueezebox==0.6.3
|
||||
pysqueezebox==0.7.1
|
||||
|
||||
# homeassistant.components.switchbee
|
||||
pyswitchbee==1.8.0
|
||||
|
|
|
@ -6,7 +6,7 @@ from pysqueezebox import Server
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.components.squeezebox.const import DOMAIN
|
||||
from homeassistant.components.squeezebox.const import CONF_HTTPS, DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
@ -59,7 +59,13 @@ async def test_user_form(hass: HomeAssistant) -> None:
|
|||
# test the edit step
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: HOST, CONF_PORT: PORT, CONF_USERNAME: "", CONF_PASSWORD: ""},
|
||||
{
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_USERNAME: "",
|
||||
CONF_PASSWORD: "",
|
||||
CONF_HTTPS: False,
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
|
@ -68,6 +74,7 @@ async def test_user_form(hass: HomeAssistant) -> None:
|
|||
CONF_PORT: PORT,
|
||||
CONF_USERNAME: "",
|
||||
CONF_PASSWORD: "",
|
||||
CONF_HTTPS: False,
|
||||
}
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
@ -107,7 +114,11 @@ async def test_user_form_duplicate(hass: HomeAssistant) -> None:
|
|||
"homeassistant.components.squeezebox.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=UUID)
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=UUID,
|
||||
data={CONF_HOST: HOST, CONF_PORT: PORT, CONF_HTTPS: False},
|
||||
)
|
||||
await hass.config_entries.async_add(entry)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
|
@ -186,7 +197,7 @@ async def test_discovery_no_uuid(hass: HomeAssistant) -> None:
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={CONF_HOST: HOST, CONF_PORT: PORT},
|
||||
data={CONF_HOST: HOST, CONF_PORT: PORT, CONF_HTTPS: False},
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "edit"
|
||||
|
|
Loading…
Add table
Reference in a new issue