Skip to content

Commit af4dfba

Browse files
author
lexorius
committed
v2.5
1 parent e85dc2f commit af4dfba

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

  • custom_components/alternative_time/calendars

custom_components/alternative_time/calendars/nato.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""NATO Time formats implementation - Version 2.5."""
1+
"""NATO Time formats implementation - Version 2.5 DEBUG."""
22
from __future__ import annotations
33

44
from datetime import datetime
@@ -160,24 +160,38 @@ def __init__(self, base_name: str, hass: HomeAssistant, config_entry: ConfigEntr
160160
# Get translated name from metadata
161161
calendar_name = self._translate('name', 'NATO Time')
162162

163+
# DEBUG: Log all received parameters
164+
_LOGGER.warning(f"NATO DEBUG - Initialization started")
165+
_LOGGER.warning(f"NATO DEBUG - base_name: {base_name}")
166+
_LOGGER.warning(f"NATO DEBUG - config_entry exists: {config_entry is not None}")
167+
_LOGGER.warning(f"NATO DEBUG - plugin_options: {plugin_options}")
168+
169+
if config_entry:
170+
_LOGGER.warning(f"NATO DEBUG - config_entry.data keys: {config_entry.data.keys()}")
171+
_LOGGER.warning(f"NATO DEBUG - Full config_entry.data: {config_entry.data}")
172+
if "plugin_options" in config_entry.data:
173+
_LOGGER.warning(f"NATO DEBUG - plugin_options from config_entry: {config_entry.data.get('plugin_options')}")
174+
163175
# Load configuration options - try multiple sources
164176
options = {}
165177

166178
# Method 1: Direct plugin_options parameter
167179
if plugin_options:
168180
options = plugin_options
169-
_LOGGER.debug(f"NATO: Using direct plugin_options: {options}")
181+
_LOGGER.warning(f"NATO DEBUG - Using direct plugin_options: {options}")
170182
# Method 2: From config_entry
171183
elif config_entry and config_entry.data:
172-
options = config_entry.data.get("plugin_options", {}).get("nato", {})
173-
_LOGGER.debug(f"NATO: Using config_entry plugin_options: {options}")
184+
all_plugin_options = config_entry.data.get("plugin_options", {})
185+
_LOGGER.warning(f"NATO DEBUG - All plugin_options from config: {all_plugin_options}")
186+
options = all_plugin_options.get("nato", {})
187+
_LOGGER.warning(f"NATO DEBUG - NATO specific options: {options}")
174188

175189
# Configuration options with defaults
176190
self._format_type = options.get("format_type", "basic")
177191
self._show_zone_name = options.get("show_zone_name", False)
178192
self._use_local_zone = options.get("use_local_zone", True)
179193

180-
_LOGGER.info(f"NATO sensor initialized with format_type: {self._format_type}, show_zone: {self._show_zone_name}, local_zone: {self._use_local_zone}")
194+
_LOGGER.warning(f"NATO DEBUG - Final settings: format_type={self._format_type}, show_zone={self._show_zone_name}, local_zone={self._use_local_zone}")
181195

182196
# Adjust name based on format type
183197
format_suffix = {
@@ -201,7 +215,7 @@ def __init__(self, base_name: str, hass: HomeAssistant, config_entry: ConfigEntr
201215
# NATO data
202216
self._nato_data = CALENDAR_INFO["nato_data"]
203217

204-
_LOGGER.debug(f"Initialized NATO Time sensor ({self._format_type}): {self._attr_name}")
218+
_LOGGER.warning(f"NATO DEBUG - Sensor initialized: name={self._attr_name}, format={self._format_type}")
205219

206220
@property
207221
def state(self):
@@ -269,13 +283,16 @@ def _get_timezone_info(self, earth_time: datetime) -> tuple:
269283
def _calculate_nato_time(self, earth_time: datetime) -> Dict[str, Any]:
270284
"""Calculate NATO Time based on selected format."""
271285

286+
_LOGGER.debug(f"NATO DEBUG - Calculating time with format: {self._format_type}")
287+
272288
if self._format_type == "basic":
273289
return self._calculate_basic_format(earth_time)
274290
elif self._format_type == "zone":
275291
return self._calculate_zone_format(earth_time)
276292
elif self._format_type == "rescue":
277293
return self._calculate_rescue_format(earth_time)
278294
else:
295+
_LOGGER.warning(f"NATO DEBUG - Unknown format type: {self._format_type}, using basic")
279296
return self._calculate_basic_format(earth_time)
280297

281298
def _calculate_basic_format(self, earth_time: datetime) -> Dict[str, Any]:
@@ -341,6 +358,8 @@ def _calculate_zone_format(self, earth_time: datetime) -> Dict[str, Any]:
341358
def _calculate_rescue_format(self, earth_time: datetime) -> Dict[str, Any]:
342359
"""Calculate German rescue service format (DD HHMM MONAT YY)."""
343360

361+
_LOGGER.debug(f"NATO DEBUG - Calculating rescue format")
362+
344363
# Get German month abbreviation
345364
month = self._nato_data["german_months"][earth_time.month]
346365

@@ -371,6 +390,8 @@ def _calculate_rescue_format(self, earth_time: datetime) -> Dict[str, Any]:
371390
"full_display": display
372391
}
373392

393+
_LOGGER.debug(f"NATO DEBUG - Rescue format result: {display}")
394+
374395
return result
375396

376397
def update(self) -> None:
@@ -381,4 +402,4 @@ def update(self) -> None:
381402
# Set state to formatted NATO time
382403
self._state = self._nato_time["full_display"]
383404

384-
_LOGGER.debug(f"Updated NATO Time to {self._state}")
405+
_LOGGER.debug(f"NATO DEBUG - Updated to: {self._state} (format: {self._format_type})")

0 commit comments

Comments
 (0)