Skip to content

Commit 35535c0

Browse files
Address Copilot review feedback
- Use TEMP_SOURCE_INTERNAL/REMOTE constants instead of hardcoded strings - Call set_remote_temp_mode() in fallback scenarios to persist state changes - Clear remote_temp_mode when experimental features are disabled - Update constants to use title case for UI display
1 parent cb029fe commit 35535c0

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

custom_components/mitsubishi/config_flow.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,17 @@ async def _async_save_options(self, external_temp_entity: str | None) -> Any:
296296
new_options: dict[str, Any] = {
297297
CONF_EXPERIMENTAL_FEATURES: self._experimental_features,
298298
}
299-
if self._experimental_features and external_temp_entity:
300-
new_options[CONF_EXTERNAL_TEMP_ENTITY] = external_temp_entity
301-
# Preserve remote_temp_mode from existing options
302-
if CONF_REMOTE_TEMP_MODE in self.config_entry.options:
303-
new_options[CONF_REMOTE_TEMP_MODE] = self.config_entry.options[CONF_REMOTE_TEMP_MODE]
299+
if self._experimental_features:
300+
# Only preserve experimental settings when experimental features are enabled
301+
if external_temp_entity:
302+
new_options[CONF_EXTERNAL_TEMP_ENTITY] = external_temp_entity
303+
# Preserve remote_temp_mode from existing options
304+
if CONF_REMOTE_TEMP_MODE in self.config_entry.options:
305+
new_options[CONF_REMOTE_TEMP_MODE] = self.config_entry.options[
306+
CONF_REMOTE_TEMP_MODE
307+
]
308+
# When experimental features are disabled, don't preserve remote_temp_mode
309+
# This ensures a clean state when the feature is turned off
304310

305311
return self.async_create_entry(title="", data=new_options)
306312

custom_components/mitsubishi/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
CONF_REMOTE_TEMP_MODE = "remote_temp_mode"
2323

2424
# Temperature Source Modes
25-
TEMP_SOURCE_INTERNAL = "internal"
26-
TEMP_SOURCE_REMOTE = "remote"
25+
TEMP_SOURCE_INTERNAL = "Internal"
26+
TEMP_SOURCE_REMOTE = "Remote"

custom_components/mitsubishi/coordinator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def _send_remote_temperature(self) -> None:
115115
"falling back to internal sensor"
116116
)
117117
await self.hass.async_add_executor_job(self.controller.set_current_temperature, None)
118-
self._remote_temp_mode = False
118+
self.set_remote_temp_mode(False)
119119
return
120120

121121
state = self.hass.states.get(external_entity_id)
@@ -126,7 +126,7 @@ async def _send_remote_temperature(self) -> None:
126126
external_entity_id,
127127
)
128128
await self.hass.async_add_executor_job(self.controller.set_current_temperature, None)
129-
self._remote_temp_mode = False
129+
self.set_remote_temp_mode(False)
130130
return
131131

132132
if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
@@ -136,7 +136,7 @@ async def _send_remote_temperature(self) -> None:
136136
state.state,
137137
)
138138
await self.hass.async_add_executor_job(self.controller.set_current_temperature, None)
139-
self._remote_temp_mode = False
139+
self.set_remote_temp_mode(False)
140140
return
141141

142142
try:
@@ -157,4 +157,4 @@ async def _send_remote_temperature(self) -> None:
157157
e,
158158
)
159159
await self.hass.async_add_executor_job(self.controller.set_current_temperature, None)
160-
self._remote_temp_mode = False
160+
self.set_remote_temp_mode(False)

custom_components/mitsubishi/select.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
CONF_EXPERIMENTAL_FEATURES,
1616
CONF_EXTERNAL_TEMP_ENTITY,
1717
DOMAIN,
18+
TEMP_SOURCE_INTERNAL,
19+
TEMP_SOURCE_REMOTE,
1820
)
1921
from .coordinator import MitsubishiDataUpdateCoordinator
2022
from .entity import MitsubishiEntity
@@ -82,7 +84,7 @@ class MitsubishiTemperatureSourceSelect(MitsubishiEntity, SelectEntity):
8284

8385
_attr_name = "Temperature Source"
8486
_attr_icon = "mdi:thermometer"
85-
_attr_options = ["Internal", "Remote"]
87+
_attr_options = [TEMP_SOURCE_INTERNAL, TEMP_SOURCE_REMOTE]
8688

8789
def __init__(
8890
self,
@@ -96,11 +98,11 @@ def __init__(
9698
@property
9799
def current_option(self) -> str | None:
98100
"""Return the current temperature source mode."""
99-
return "Remote" if self.coordinator.remote_temp_mode else "Internal"
101+
return TEMP_SOURCE_REMOTE if self.coordinator.remote_temp_mode else TEMP_SOURCE_INTERNAL
100102

101103
async def async_select_option(self, option: str) -> None:
102104
"""Set the temperature source mode."""
103-
if option == "Internal":
105+
if option == TEMP_SOURCE_INTERNAL:
104106
# Switch to internal sensor
105107
self.coordinator.set_remote_temp_mode(False)
106108
await self.hass.async_add_executor_job(

0 commit comments

Comments
 (0)