Skip to content

Commit

Permalink
Add websocket mode option in flow
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed Jan 13, 2024
1 parent 9dd948d commit b650757
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions custom_components/heatzy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator.unsub()

return unload_ok


async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry):
"""Reload if change option."""
await hass.config_entries.async_reload(entry.entry_id)
32 changes: 31 additions & 1 deletion custom_components/heatzy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_create_clientsession

from .const import DOMAIN
from .const import CONF_WEBSOCKET, DOMAIN

DATA_SCHEMA = vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
Expand All @@ -29,6 +30,12 @@ class HeatzyFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get option flow."""
return OptionsFlowHandler(config_entry)

async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
errors = {}
Expand Down Expand Up @@ -56,3 +63,26 @@ async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)


class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle option."""

def __init__(self, config_entry):
"""Initialize the options flow."""
self.config_entry = config_entry

async def async_step_init(self, user_input=None):
"""Handle a flow initialized by the user."""
options_schema = vol.Schema(
{
vol.Required(
CONF_WEBSOCKET,
default=self.config_entry.options.get(CONF_WEBSOCKET, True),
): bool
},
)
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

return self.async_show_form(step_id="init", data_schema=options_schema)
1 change: 1 addition & 0 deletions custom_components/heatzy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CONF_VERSION = "wifi_soft_version"
CUR_TEMP_H = "cur_tempH"
CUR_TEMP_L = "cur_tempL"
CONF_WEBSOCKET = "websocket_feature"
DEBOUNCE_COOLDOWN = 10
DOMAIN = "heatzy"
ECO_TEMP_H = "eco_tempH"
Expand Down
9 changes: 9 additions & 0 deletions custom_components/heatzy/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
}
},
"options": {
"step": {
"init": {
"data": {
"websocket_feature": "Enable websocket feature"
}
}
}
}
}
9 changes: 9 additions & 0 deletions custom_components/heatzy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
"abort": {
"already_configured": "Your account is already configured."
}
},
"options": {
"step": {
"init": {
"data": {
"websocket_feature": "Enable websocket feature"
}
}
}
}
}
9 changes: 9 additions & 0 deletions custom_components/heatzy/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
"abort": {
"already_configured": "Votre compte est déjà enregistré."
}
},
"options": {
"step": {
"init": {
"data": {
"websocket_feature": "Activer le mode websocket"
}
}
}
}
}

0 comments on commit b650757

Please sign in to comment.