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: Adding option to reconfigure integration #29

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions custom_components/cloudweatherproxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The Wunderground Receiver integration."""

import logging
from aiocloudweather import CloudWeatherListener
from aiocloudweather.proxy import DataSink

Expand All @@ -12,6 +13,8 @@

PLATFORMS: list[Platform] = [Platform.SENSOR]

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Cloud Weather Proxy from a config entry."""
Expand All @@ -21,6 +24,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
proxies += [DataSink.WEATHERCLOUD] if entry.data[CONF_WEATHERCLOUD_PROXY] else []

dns_servers = entry.data[CONF_DNS_SERVERS]

_LOGGER.debug("Setting up Cloud Weather Proxy with %s and %s",
proxies, dns_servers)
cloudweather = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
CloudWeatherListener(proxy_sinks=proxies,
dns_servers=dns_servers.split(","))
Expand Down
43 changes: 42 additions & 1 deletion custom_components/cloudweatherproxy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

from __future__ import annotations

import logging
from typing import Any

import voluptuous as vol

from aiocloudweather import CloudWeatherListener
from aiocloudweather.proxy import DataSink


from yarl import URL

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, ConfigEntry
# from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.network import get_url

from .const import CONF_WUNDERGROUND_PROXY, CONF_WEATHERCLOUD_PROXY, CONF_DNS_SERVERS, DOMAIN

_LOGGER = logging.getLogger(__name__)


class CloudWeatherProxyConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow for the Cloud Weather Proxy."""
Expand Down Expand Up @@ -56,3 +62,38 @@ async def async_step_user(
),
errors=errors,
)

async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None):
"""Add reconfigure step to allow to reconfigure a config entry."""

config_entry: ConfigEntry = (
self.hass.config_entries.async_get_entry(
self.context.get("entry_id"))
)
listener: CloudWeatherListener = self.hass.data[DOMAIN][config_entry.entry_id]
current_proxy_settings = listener.get_active_proxies()
current_dns_servers = listener.get_dns_servers()
_LOGGER.debug("Current configuration: %s and proxies %s",
current_proxy_settings, current_dns_servers)

if user_input is not None:
_LOGGER.debug(
"Reconfiguring Cloud Weather Proxy with %s", user_input)
await listener.update_config(
proxy_sinks=[
DataSink.WUNDERGROUND if user_input[CONF_WUNDERGROUND_PROXY] else None,
DataSink.WEATHERCLOUD if user_input[CONF_WEATHERCLOUD_PROXY] else None,
],
dns_servers=user_input[CONF_DNS_SERVERS].split(","),
)

return self.async_show_form(
step_id="reconfigure",
data_schema=vol.Schema(
{
vol.Required(CONF_WUNDERGROUND_PROXY, default=(DataSink.WUNDERGROUND in current_proxy_settings)): bool,
vol.Required(CONF_WEATHERCLOUD_PROXY, default=(DataSink.WEATHERCLOUD in current_proxy_settings)): bool,
vol.Optional(CONF_DNS_SERVERS, default=current_dns_servers): str,
}
),
)
4 changes: 2 additions & 2 deletions custom_components/cloudweatherproxy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/lhw/cloudweatherproxy/issues",
"requirements": [
"aiocloudweather==2024.7.1"
"aiocloudweather==2024.9.2"
],
"version": "2024.7.2"
"version": "2024.9.0"
}
13 changes: 12 additions & 1 deletion custom_components/cloudweatherproxy/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
"config": {
"step": {
"user": {
"description": "Select desired proxy options.",
"description": "All data forwarded to Home Assistant is processed. Optionally you can forward the data to their intended data sink. Please select for which services you want to enable this feature",
"data": {
"weatherunderground_proxy": "Proxy Weather Underground",
"weathercloud_proxy": "Proxy Weathercloud",
"dns_servers": "DNS Servers"
},
"data_description": {
"dns_servers": "DNS Servers used for looking up the actual IPs of the domains. Can be a comma separated list of IPs."
}
},
"reconfigure": {
"description": "All data forwarded to Home Assistant is processed. Optionally you can forward the data to their intended data sink. Please select for which services you want to enable this feature",
"data": {
"weatherunderground_proxy": "Proxy Weather Underground",
"weathercloud_proxy": "Proxy Weathercloud",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pip>=24.1,<25.0
ruff==0.6.*
colorlog==6.8.*
homeassistant==2024.5.5
aiocloudweather==2024.7.1
homeassistant==2024.9.1
aiocloudweather==2024.9.2