Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Split into proxy and library #6

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions custom_components/hass_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Custom integration to add a tiny proxy to Home Assistant.
Custom integration to add a small web proxy to Home Assistant.

For more details about this integration, please refer to
https://github.com/dermotduffy/hass-proxy
Expand All @@ -17,8 +17,7 @@

from .data import HASSProxyData


from .proxy import async_setup as proxy_async_setup
from .proxy import async_setup as async_proxy_setup

PLATFORMS: list[Platform] = []

Expand All @@ -34,7 +33,7 @@ async def async_setup_entry(
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))

proxy_async_setup(hass)
await async_proxy_setup(hass)

return True

Expand All @@ -54,6 +53,4 @@ async def async_reload_entry(
) -> None:
"""Reload config entry."""
LOGGER.info("HASSPROXY Reloading entry %s", entry.entry_id)

await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)
await hass.config_entries.async_reload(entry.entry_id)
71 changes: 50 additions & 21 deletions custom_components/hass_proxy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,56 @@
from homeassistant.core import callback
from homeassistant.helpers import selector

from .const import CONF_URLS, DOMAIN

# SSL Validate
# URLs?
from .const import (
CONF_DYNAMIC_URLS,
CONF_SSL_CIPHER_INSECURE,
CONF_SSL_CIPHER_INTERMEDIATE,
CONF_SSL_CIPHER_MODERN,
CONF_SSL_CIPHER_PYTHON_DEFAULT,
CONF_SSL_CIPHERS,
CONF_SSL_VERIFICATION,
CONF_URL_PATTERNS,
DEFAULT_OPTIONS,
DOMAIN,
)

OPTIONS_SCHEMA = vol.Schema(
{
vol.Optional(
CONF_URL_PATTERNS,
): selector.TextSelector(
selector.TextSelectorConfig(
type=selector.TextSelectorType.TEXT,
multiple=True,
),
),
vol.Optional(
CONF_SSL_VERIFICATION,
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
vol.Optional(
CONF_SSL_CIPHERS,
): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[
CONF_SSL_CIPHER_PYTHON_DEFAULT,
CONF_SSL_CIPHER_MODERN,
CONF_SSL_CIPHER_INTERMEDIATE,
CONF_SSL_CIPHER_INSECURE,
],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key=CONF_SSL_CIPHERS,
)
),
vol.Optional(
CONF_DYNAMIC_URLS,
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
},
)


class HASSProxyFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg,misc]
"""Config flow for HASS Proxy."""

VERSION = 1

@staticmethod
@callback # type: ignore[misc]
def async_get_options_flow(
Expand All @@ -34,14 +73,14 @@ async def async_step_user(
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")

return self.async_create_entry(title="HASS Proxy", data=user_input or {})
return self.async_create_entry(
title="HASS Proxy", data=user_input or {}, options=DEFAULT_OPTIONS
)


class HASSProxyOptionsFlowHandler(config_entries.OptionsFlow):
"""Options flow for Blueprint."""

VERSION = 1

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize an options flow."""
self._config_entry = config_entry
Expand All @@ -58,17 +97,7 @@ async def async_step_init(

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Required(
CONF_URLS,
default=(user_input or {}).get(CONF_URLS, vol.UNDEFINED),
): selector.TextSelector(
selector.TextSelectorConfig(
type=selector.TextSelectorType.TEXT,
multiline=True,
),
),
},
data_schema=self.add_suggested_values_to_schema(
OPTIONS_SCHEMA, self._config_entry.options
),
)
21 changes: 19 additions & 2 deletions custom_components/hass_proxy/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
"""Constants for hass_proxy."""

from logging import Logger, getLogger
from typing import Final

DOMAIN = "hass_proxy"
from homeassistant.util.ssl import SSLCipherList

CONF_URLS = "urls"
DOMAIN: Final = "hass_proxy"

LOGGER: Logger = getLogger(__package__)

CONF_SSL_VERIFICATION: Final = "ssl_verification"
CONF_SSL_CIPHERS: Final = "ssl_ciphers"
CONF_SSL_CIPHER_INSECURE: Final = SSLCipherList.INSECURE
CONF_SSL_CIPHER_MODERN: Final = SSLCipherList.MODERN
CONF_SSL_CIPHER_INTERMEDIATE: Final = SSLCipherList.INTERMEDIATE
CONF_SSL_CIPHER_PYTHON_DEFAULT: Final = SSLCipherList.PYTHON_DEFAULT

CONF_DYNAMIC_URLS: Final = "dynamic_urls"
CONF_URL_PATTERNS: Final = "url_patterns"

DEFAULT_OPTIONS: dict[str, str | bool | list[str]] = {
CONF_SSL_VERIFICATION: True,
CONF_DYNAMIC_URLS: True,
CONF_SSL_CIPHERS: CONF_SSL_CIPHER_PYTHON_DEFAULT,
}
9 changes: 3 additions & 6 deletions custom_components/hass_proxy/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"domain": "hass_proxy",
"name": "Home Assistant Proxy",
"codeowners": [
"@dermotduffy"
],
"codeowners": ["@dermotduffy"],
"config_flow": true,
"dependencies": [
"http"
],
"dependencies": ["http"],
"documentation": "https://github.com/dermotduffy/hass-proxy",
"iot_class": "local_push",
"issue_tracker": "https://github.com/dermotduffy/hass-proxy/issues",
"requirements": ["urlmatch==1.0.1"],
"version": "0.0.0"
}
Loading