Skip to content

Commit 1f774a5

Browse files
committed
Add config_entry title to all log messages.
This makes it easier to identify which heat pump the log message relates to.
1 parent 2d439b8 commit 1f774a5

4 files changed

Lines changed: 36 additions & 23 deletions

File tree

custom_components/mitsubishi/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
121121
return True
122122

123123
except Exception as ex:
124-
_LOGGER.exception("Failed to set up Mitsubishi Air Conditioner: %s", ex)
124+
_LOGGER.exception("[%s] Failed to set up Mitsubishi Air Conditioner: %s",
125+
entry.title,
126+
ex)
125127
raise ConfigEntryNotReady from ex
126128

127129

@@ -139,14 +141,16 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
139141
# This prevents the AC from being stuck with stale remote temperature data
140142
if coordinator.remote_temp_mode:
141143
try:
142-
_LOGGER.info("Switching AC to internal temperature sensor during unload")
144+
_LOGGER.info("[%s] Switching AC to internal temperature sensor during unload",
145+
entry.title)
143146
await hass.async_add_executor_job(
144147
coordinator.controller.set_current_temperature, None
145148
)
146149
except Exception:
147150
_LOGGER.warning(
148-
"Failed to switch AC to internal sensor during unload, "
149-
"AC may continue using last remote temperature"
151+
"[%s] Failed to switch AC to internal sensor during unload, "
152+
"AC may continue using last remote temperature",
153+
entry.title,
150154
)
151155

152156
# Close API connection
@@ -158,7 +162,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
158162
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
159163
"""Migrate old entry."""
160164
_LOGGER.debug(
161-
"Migrating configuration from version %s.%s",
165+
"[%s] Migrating configuration from version %s.%s",
166+
config_entry.title,
162167
config_entry.version,
163168
)
164169

custom_components/mitsubishi/coordinator.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def __init__(
4848

4949
# Log the loaded state for debugging persistence issues
5050
_LOGGER.info(
51-
"Coordinator initialized: remote_temp_mode=%s (from options: %s)",
51+
"Coordinator for `%s` initialized: remote_temp_mode=%s (from options: %s)",
52+
self.config_entry.title,
5253
self._remote_temp_mode,
5354
dict(config_entry.options),
5455
)
@@ -59,7 +60,7 @@ async def set_remote_temp_mode(self, enabled: bool) -> None:
5960
When disabling remote mode, this also tells the AC to use its internal sensor.
6061
"""
6162
self._remote_temp_mode = enabled
62-
_LOGGER.info("Remote temperature mode set to: %s", enabled)
63+
_LOGGER.info("[%s] Remote temperature mode set to: %s", self.config_entry.title, enabled)
6364

6465
# When disabling remote mode, tell the AC to use internal sensor
6566
if not enabled:
@@ -93,18 +94,19 @@ async def get_unit_info(self) -> dict:
9394

9495
async def _async_update_data(self) -> ParsedDeviceState:
9596
"""Update data via library."""
96-
_LOGGER.debug("Coordinator fetching device status")
97+
_LOGGER.debug("[%s] Coordinator fetching device status", self.config_entry.title)
9798

9899
# Only process remote temperature if experimental features are enabled
99100
if self.experimental_features_enabled:
100101
# On first update after startup, restore the persisted mode to the AC
101102
if not self._startup_mode_applied:
102103
self._startup_mode_applied = True
103104
if self._remote_temp_mode:
104-
_LOGGER.info("Restoring remote temperature mode from persisted state")
105+
_LOGGER.info("[%s] Restoring remote temperature mode from persisted state",
106+
self.config_entry.title)
105107
await self._send_remote_temperature()
106108
else:
107-
_LOGGER.debug("Starting with internal temperature mode")
109+
_LOGGER.debug("[%s] Starting with internal temperature mode", self.config_entry.title)
108110
elif self._remote_temp_mode:
109111
# Regular update - send remote temperature if enabled
110112
await self._send_remote_temperature()
@@ -131,8 +133,9 @@ async def _send_remote_temperature(self) -> None:
131133

132134
if not external_entity_id:
133135
_LOGGER.warning(
134-
"Remote temperature mode enabled but no external entity configured, "
135-
"falling back to internal sensor"
136+
"[%s] Remote temperature mode enabled but no external entity configured, "
137+
"falling back to internal sensor",
138+
self.config_entry.title,
136139
)
137140
await self.set_remote_temp_mode(False)
138141
return
@@ -141,8 +144,9 @@ async def _send_remote_temperature(self) -> None:
141144

142145
if state is None:
143146
_LOGGER.warning(
144-
"External temperature entity %s not found, "
147+
"[%s External temperature entity %s not found, "
145148
"temporarily using internal sensor (will retry)",
149+
self.config_entry.title,
146150
external_entity_id,
147151
)
148152
# Tell AC to use internal sensor temporarily, but don't disable remote mode
@@ -152,8 +156,9 @@ async def _send_remote_temperature(self) -> None:
152156

153157
if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
154158
_LOGGER.warning(
155-
"External temperature entity %s is %s, "
159+
"[%s] External temperature entity %s is %s, "
156160
"temporarily using internal sensor (will retry)",
161+
self.config_entry.title,
157162
external_entity_id,
158163
state.state,
159164
)
@@ -165,7 +170,8 @@ async def _send_remote_temperature(self) -> None:
165170
try:
166171
temperature = float(state.state)
167172
_LOGGER.debug(
168-
"Sending remote temperature %.1f from %s to AC",
173+
"[%s] Sending remote temperature %.1f from %s to AC",
174+
self.config_entry.title,
169175
temperature,
170176
external_entity_id,
171177
)
@@ -174,8 +180,9 @@ async def _send_remote_temperature(self) -> None:
174180
)
175181
except (ValueError, TypeError) as e:
176182
_LOGGER.error(
177-
"Invalid temperature value '%s' from %s: %s, "
183+
"[%s] Invalid temperature value '%s' from %s: %s, "
178184
"temporarily using internal sensor (will retry)",
185+
self.config_entry.title,
179186
state.state,
180187
external_entity_id,
181188
e,

custom_components/mitsubishi/entity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,31 @@ async def _execute_command_with_refresh(
7878
bool: True if command was successful, False otherwise
7979
"""
8080
try:
81-
_LOGGER.debug(f"Executing command: {command_name}")
81+
_LOGGER.debug(f"[{self._config_entry.title}] Executing command: {command_name}")
8282

8383
# Execute the command
8484
success = await self.hass.async_add_executor_job(lambda: command_func(*args, **kwargs))
8585

8686
if success:
87-
_LOGGER.debug(f"Command '{command_name}' sent successfully")
87+
_LOGGER.debug(f"[{self._config_entry.title}] Command '{command_name}' sent successfully")
8888

8989
# Based on timing tests, the device needs ~1.5-2 seconds to process
9090
# commands and reflect changes in its status. The command response
9191
# contains the OLD state, not the new state.
9292

9393
# Wait for the device to process the command
94-
_LOGGER.debug(f"Waiting for device to process {command_name}...")
94+
_LOGGER.debug(f"[{self._config_entry.title}] Waiting for device to process {command_name}...")
9595
await asyncio.sleep(self.coordinator.controller.wait_time_after_command)
9696

9797
# Now fetch fresh data from the device
9898
await self.coordinator.async_request_refresh()
99-
_LOGGER.debug(f"Coordinator refreshed after {command_name}")
99+
_LOGGER.debug(f"[{self._config_entry.title}] Coordinator refreshed after {command_name}")
100100

101101
return True
102102
else:
103-
_LOGGER.warning(f"Failed to execute {command_name}")
103+
_LOGGER.warning(f"[{self._config_entry.title}] Failed to execute {command_name}")
104104
return False
105105

106106
except Exception as e:
107-
_LOGGER.error(f"Error executing {command_name}: {e}")
107+
_LOGGER.error(f"[{self._config_entry.title}] Error executing {command_name}: {e}")
108108
return False

custom_components/mitsubishi/sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async def async_setup_entry(
3030
"""Set up Mitsubishi sensors."""
3131
coordinator = hass.data[DOMAIN][config_entry.entry_id]
3232
_LOGGER.debug(
33-
"Setting up Mitsubishi sensors with coordinator data available: %s",
33+
"[%s] Setting up Mitsubishi sensors with coordinator data available: %s",
34+
config_entry.title,
3435
coordinator.data is not None,
3536
)
3637

0 commit comments

Comments
 (0)