diff --git a/custom_components/wiser/config_flow.py b/custom_components/wiser/config_flow.py index 2f1b310..d8abb0b 100755 --- a/custom_components/wiser/config_flow.py +++ b/custom_components/wiser/config_flow.py @@ -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 @@ -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} ) @@ -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, @@ -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}", "") @@ -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, } @@ -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, } ), @@ -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 ) @@ -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( diff --git a/custom_components/wiser/coordinator.py b/custom_components/wiser/coordinator.py index fd877f0..7a51459 100644 --- a/custom_components/wiser/coordinator.py +++ b/custom_components/wiser/coordinator.py @@ -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 @@ -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, diff --git a/custom_components/wiser/manifest.json b/custom_components/wiser/manifest.json index 886b552..7a4e66c 100755 --- a/custom_components/wiser/manifest.json +++ b/custom_components/wiser/manifest.json @@ -25,4 +25,4 @@ "name": "wiser*" } ] -} \ No newline at end of file +} diff --git a/custom_components/wiser/strings.json b/custom_components/wiser/strings.json index eb46300..cb87204 100755 --- a/custom_components/wiser/strings.json +++ b/custom_components/wiser/strings.json @@ -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" } }, @@ -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" } } diff --git a/custom_components/wiser/translations/en.json b/custom_components/wiser/translations/en.json index c9b1510..1866ad1 100755 --- a/custom_components/wiser/translations/en.json +++ b/custom_components/wiser/translations/en.json @@ -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" } }, @@ -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" } } @@ -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)", diff --git a/hacs.json b/hacs.json index 0f77b62..38e45f7 100644 --- a/hacs.json +++ b/hacs.json @@ -4,4 +4,4 @@ "render_readme": true, "zip_release": true, "filename": "wiser.zip" -} \ No newline at end of file +}