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

Use non-standard port for Hub (e.g., through NAT) #430

Merged
merged 12 commits into from
Mar 2, 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
14 changes: 12 additions & 2 deletions custom_components/wiser/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from homeassistant import config_entries, exceptions
from homeassistant.components import zeroconf
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_NAME, CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.selector import selector, SelectSelectorMode
Expand Down Expand Up @@ -46,7 +46,7 @@
_LOGGER = logging.getLogger(__name__)

DATA_SCHEMA = vol.Schema(
{vol.Required(CONF_HOST): str, vol.Required(CONF_PASSWORD): str}
{vol.Required(CONF_HOST): str, vol.Optional(CONF_PORT, default=80): int, vol.Required(CONF_PASSWORD): str}
)


Expand All @@ -57,6 +57,7 @@ async def validate_input(hass: HomeAssistant, data):
"""
wiserhub = WiserAPI(
host=data[CONF_HOST],
port=data[CONF_PORT],
secret=data[CONF_PASSWORD],
session=async_get_clientsession(hass),
extra_config_file=hass.config.config_dir + CUSTOM_DATA_STORE,
Expand Down Expand Up @@ -140,6 +141,7 @@ async def async_step_zeroconf(
if not discovery_info.name.startswith("WiserHeat"):
return self.async_abort(reason="not_wiser_hub")
host = discovery_info.host
port = discovery_info.port
zctype = discovery_info.type
name = discovery_info.name.replace(f".{zctype}", "")

Expand All @@ -151,6 +153,7 @@ async def async_step_zeroconf(
self.discovery_info.update(
{
CONF_HOST: host,
CONF_PORT: port,
CONF_HOSTNAME: discovery_info.hostname.replace(".local.", ".local"),
CONF_NAME: name,
}
Expand Down Expand Up @@ -192,12 +195,16 @@ async def async_step_zeroconf_confirm(
"name": self.discovery_info[CONF_NAME],
"hostname": self.discovery_info[CONF_HOSTNAME],
"ip_address": self.discovery_info[CONF_HOST],
"port": self.discovery_info[CONF_PORT],
},
data_schema=vol.Schema(
{
vol.Required(
CONF_HOST, default=self.discovery_info[CONF_HOST]
): str,
vol.Optional(
CONF_PORT, default=self.discovery_info[CONF_PORT]
): int,
vol.Required(CONF_PASSWORD): str,
}
),
Expand Down Expand Up @@ -250,10 +257,12 @@ async def async_step_main_params(self, user_input=None):
if user_input[CONF_HOST]:
data = {
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
CONF_PASSWORD: self.config_entry.data[CONF_PASSWORD],
CONF_NAME: self.config_entry.data[CONF_NAME],
}
user_input.pop(CONF_HOST)
user_input.pop(CONF_PORT)
self.hass.config_entries.async_update_entry(
self.config_entry, data=data
)
Expand All @@ -262,6 +271,7 @@ async def async_step_main_params(self, user_input=None):

data_schema = {
vol.Required(CONF_HOST, default=self.config_entry.data[CONF_HOST]): str,
vol.Optional(CONF_PORT, default=self.config_entry.data[CONF_PORT]): str,
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
Expand Down
3 changes: 2 additions & 1 deletion custom_components/wiser/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
Expand Down Expand Up @@ -111,6 +111,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:

self.wiserhub = WiserAPI(
host=config_entry.data[CONF_HOST],
port=config_entry.data[CONF_PORT],
secret=str(config_entry.data[CONF_PASSWORD]).strip(),
extra_config_file=hass.config.config_dir + CUSTOM_DATA_STORE,
enable_automations=self.enable_automations_passive_mode,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/wiser/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"name": "wiser*"
}
]
}
}
2 changes: 2 additions & 0 deletions custom_components/wiser/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"description": "Please enter the ip address and secret key obtained from the hub.",
"data": {
"host": "IP Address or Hostname",
"port": "Port number",
"password": "Secret Key"
}
},
Expand All @@ -15,6 +16,7 @@
"description": "Please enter the secret key obtained from the hub.",
"data": {
"host": "IP Address or Hostname",
"port": "Port number",
"password": "Secret Key"
}
}
Expand Down
3 changes: 3 additions & 0 deletions custom_components/wiser/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"description": "Please enter the ip address and secret key obtained from the hub.",
"data": {
"host": "IP Address or Hostname",
"port": "Port number",
"password": "Secret Key"
}
},
Expand All @@ -15,6 +16,7 @@
"description": "Please enter the secret key obtained from the hub - {name}. \n Hostname: {hostname} \n IP Address: {ip_address}",
"data": {
"host": "IP Address or Hostname",
"port": "Port number",
"password": "Secret Key"
}
}
Expand Down Expand Up @@ -45,6 +47,7 @@
"description": "Main Parameters",
"data": {
"host": "IP Address or Hostname",
"port": "Port number",
"scan_interval": "Scan Interval (secs)",
"heating_boost_temp": "Default Heating Boost Temperature (°C)",
"heating_boost_time": "Default Heating Boost Duration (mins)",
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"render_readme": true,
"zip_release": true,
"filename": "wiser.zip"
}
}