Skip to content

Commit cb029fe

Browse files
Add experimental features to initial config flow
- Add experimental_features toggle to initial setup (not just options) - Add two-step flow: connection settings → experimental config - Add translations/ directory with en.json for proper HA translations - Both config and options flows now support experimental features
1 parent db5413b commit cb029fe

3 files changed

Lines changed: 141 additions & 3 deletions

File tree

custom_components/mitsubishi/config_flow.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): vol.All(
4141
vol.Coerce(int), vol.Range(min=10, max=300)
4242
),
43+
vol.Optional(CONF_EXPERIMENTAL_FEATURES, default=False): bool,
4344
}
4445
)
4546

@@ -84,6 +85,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
8485
VERSION = 1
8586
MINOR_VERSION = 1
8687

88+
def __init__(self) -> None:
89+
"""Initialize the config flow."""
90+
self._connection_data: dict[str, Any] = {}
91+
self._experimental_features: bool = False
92+
self._device_info: dict[str, Any] = {}
93+
8794
@staticmethod
8895
def async_get_options_flow(
8996
config_entry: config_entries.ConfigEntry,
@@ -99,6 +106,9 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Any
99106
if user_input is not None:
100107
_LOGGER.debug("Processing user input for config flow")
101108
try:
109+
# Extract experimental features flag
110+
self._experimental_features = user_input.pop(CONF_EXPERIMENTAL_FEATURES, False)
111+
102112
_LOGGER.debug("Calling validate_input")
103113
info = await validate_input(self.hass, user_input)
104114
_LOGGER.debug("Validation successful, info: %s", info)
@@ -107,8 +117,16 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Any
107117
await self.async_set_unique_id(info["unique_id"])
108118
self._abort_if_unique_id_configured()
109119

110-
_LOGGER.debug("Creating config entry")
111-
return self.async_create_entry(title=info["title"], data=user_input)
120+
# Store for later
121+
self._connection_data = user_input
122+
self._device_info = info
123+
124+
# If experimental features enabled, go to step 2
125+
if self._experimental_features:
126+
return await self.async_step_experimental()
127+
128+
# Otherwise, create entry directly
129+
return self._create_entry(external_temp_entity=None)
112130

113131
except CannotConnect:
114132
_LOGGER.error("Cannot connect to device")
@@ -127,6 +145,41 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Any
127145
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
128146
)
129147

148+
async def async_step_experimental(self, user_input: dict[str, Any] | None = None) -> Any:
149+
"""Step 2: Configure experimental features (external temperature sensor)."""
150+
if user_input is not None:
151+
external_temp_entity = user_input.get(CONF_EXTERNAL_TEMP_ENTITY)
152+
return self._create_entry(external_temp_entity=external_temp_entity)
153+
154+
experimental_schema = vol.Schema(
155+
{
156+
vol.Optional(CONF_EXTERNAL_TEMP_ENTITY): selector.EntitySelector(
157+
selector.EntitySelectorConfig(
158+
domain=["sensor", "input_number", "number"],
159+
)
160+
),
161+
}
162+
)
163+
164+
return self.async_show_form(step_id="experimental", data_schema=experimental_schema)
165+
166+
def _create_entry(self, external_temp_entity: str | None) -> Any:
167+
"""Create the config entry with options."""
168+
_LOGGER.debug("Creating config entry")
169+
170+
# Build options
171+
options: dict[str, Any] = {
172+
CONF_EXPERIMENTAL_FEATURES: self._experimental_features,
173+
}
174+
if self._experimental_features and external_temp_entity:
175+
options[CONF_EXTERNAL_TEMP_ENTITY] = external_temp_entity
176+
177+
return self.async_create_entry(
178+
title=self._device_info["title"],
179+
data=self._connection_data,
180+
options=options,
181+
)
182+
130183

131184
class OptionsFlowHandler(config_entries.OptionsFlow):
132185
"""Handle options flow for the Mitsubishi integration."""

custom_components/mitsubishi/strings.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@
1010
"admin_username": "Admin Username (default: admin)",
1111
"admin_password": "Admin Password (default: me1debug@0567)",
1212
"scan_interval": "Update Interval (seconds, 10-300)",
13-
"enable_capability_detection": "Enable capability detection"
13+
"experimental_features": "Enable experimental features"
14+
},
15+
"data_description": {
16+
"experimental_features": "Enable experimental features like remote temperature sensor support. These features may change or be removed in future versions."
17+
}
18+
},
19+
"experimental": {
20+
"title": "Experimental Features Configuration",
21+
"description": "⚠️ WARNING: The remote temperature feature should NOT be used for critical heating/cooling needs. If your Home Assistant server goes offline, your external sensor becomes unavailable, or provides invalid readings, the AC will NOT automatically revert to its internal sensor. You must manually switch back to Internal mode.",
22+
"data": {
23+
"external_temperature_entity": "External Temperature Sensor"
24+
},
25+
"data_description": {
26+
"external_temperature_entity": "Select a temperature sensor to use as the room temperature when Remote mode is selected. Leave empty to only use the internal sensor. The AC must receive regular temperature updates - if updates stop, the AC continues using the last received value indefinitely."
1427
}
1528
}
1629
},
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"config": {
3+
"step": {
4+
"user": {
5+
"title": "Mitsubishi Air Conditioner",
6+
"description": "Configure your Mitsubishi MAC-577IF-2E air conditioner. The encryption key defaults to 'unregistered' which works for most devices. Only change this if your device uses a custom key.",
7+
"data": {
8+
"host": "IP Address",
9+
"encryption_key": "Encryption Key (default: unregistered)",
10+
"admin_username": "Admin Username (default: admin)",
11+
"admin_password": "Admin Password (default: me1debug@0567)",
12+
"scan_interval": "Update Interval (seconds, 10-300)",
13+
"experimental_features": "Enable experimental features"
14+
},
15+
"data_description": {
16+
"experimental_features": "Enable experimental features like remote temperature sensor support. These features may change or be removed in future versions."
17+
}
18+
},
19+
"experimental": {
20+
"title": "Experimental Features Configuration",
21+
"description": "⚠️ WARNING: The remote temperature feature should NOT be used for critical heating/cooling needs. If your Home Assistant server goes offline, your external sensor becomes unavailable, or provides invalid readings, the AC will NOT automatically revert to its internal sensor. You must manually switch back to Internal mode.",
22+
"data": {
23+
"external_temperature_entity": "External Temperature Sensor"
24+
},
25+
"data_description": {
26+
"external_temperature_entity": "Select a temperature sensor to use as the room temperature when Remote mode is selected. Leave empty to only use the internal sensor. The AC must receive regular temperature updates - if updates stop, the AC continues using the last received value indefinitely."
27+
}
28+
}
29+
},
30+
"error": {
31+
"cannot_connect": "Failed to connect to the air conditioner. Please check the IP address, encryption key, and ensure the device is accessible on your network.",
32+
"unknown": "Unexpected error occurred. Please try again."
33+
},
34+
"abort": {
35+
"already_configured": "Device is already configured"
36+
}
37+
},
38+
"options": {
39+
"step": {
40+
"init": {
41+
"title": "Reconfigure Mitsubishi Air Conditioner",
42+
"description": "Update the configuration settings for your Mitsubishi AC. Changes will be applied after validation and the integration will be reloaded.",
43+
"data": {
44+
"host": "IP Address",
45+
"encryption_key": "Encryption Key (default: unregistered)",
46+
"admin_username": "Admin Username (default: admin)",
47+
"admin_password": "Admin Password (default: me1debug@0567)",
48+
"scan_interval": "Update Interval (seconds, 10-300)",
49+
"enable_capability_detection": "Enable capability detection",
50+
"experimental_features": "Enable experimental features"
51+
},
52+
"data_description": {
53+
"experimental_features": "Enable experimental features like remote temperature sensor support. These features may change or be removed in future versions."
54+
}
55+
},
56+
"experimental": {
57+
"title": "Experimental Features Configuration",
58+
"description": "⚠️ WARNING: The remote temperature feature should NOT be used for critical heating/cooling needs. If your Home Assistant server goes offline, your external sensor becomes unavailable, or provides invalid readings, the AC will NOT automatically revert to its internal sensor. You must manually switch back to Internal mode.",
59+
"data": {
60+
"external_temperature_entity": "External Temperature Sensor"
61+
},
62+
"data_description": {
63+
"external_temperature_entity": "Select a temperature sensor to use as the room temperature when Remote mode is selected. Leave empty to only use the internal sensor. The AC must receive regular temperature updates - if updates stop, the AC continues using the last received value indefinitely."
64+
}
65+
}
66+
},
67+
"error": {
68+
"cannot_connect": "Failed to connect to the air conditioner. Please check the IP address, encryption key, and ensure the device is accessible on your network.",
69+
"unknown": "Unexpected error occurred. Please try again."
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)