Skip to content

Commit

Permalink
Add support for accessing Squeezebox over over https (#95088)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Dec 8, 2023
1 parent a10f580 commit 45f7ffb
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
11 changes: 9 additions & 2 deletions homeassistant/components/squeezebox/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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__)

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -105,6 +111,7 @@ async def _validate_input(self, data):
data[CONF_PORT],
data.get(CONF_USERNAME),
data.get(CONF_PASSWORD),
https=data[CONF_HTTPS],
)

try:
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/squeezebox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
DISCOVERY_TASK = "discovery_task"
DEFAULT_PORT = 9000
SQUEEZEBOX_SOURCE_STRINGS = ("source:", "wavin:", "spotify:")
CONF_HTTPS = "https"
2 changes: 1 addition & 1 deletion homeassistant/components/squeezebox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
4 changes: 3 additions & 1 deletion homeassistant/components/squeezebox/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
media_source_content_filter,
)
from .const import (
CONF_HTTPS,
DISCOVERY_TASK,
DOMAIN,
KNOWN_PLAYERS,
Expand Down Expand Up @@ -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, {})
Expand All @@ -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."""
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/squeezebox/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions tests/components/squeezebox/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 45f7ffb

Please sign in to comment.