Fix SetOption verification to handle ON/OFF vs 1/0 responses
- Tasmota returns 'ON'/'OFF' for SetOption queries - Config file uses '1'/'0' for SetOption values - Added normalize_value() to convert both formats to comparable values - Eliminates false verification warnings for correctly applied settings
This commit is contained in:
parent
265fa33497
commit
73acc41145
@ -206,40 +206,50 @@ class ConsoleSettingsManager:
|
|||||||
time.sleep(0.3) # Brief delay between commands
|
time.sleep(0.3) # Brief delay between commands
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _verify_command(self, device_ip: str, device_name: str,
|
def _verify_command(self, device_ip: str, device_name: str,
|
||||||
param_name: str, expected_value: str) -> bool:
|
param_name: str, expected_value: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Verify a command was applied (where possible).
|
Verify a command was applied (where possible).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
device_ip: Device IP address
|
device_ip: Device IP address
|
||||||
device_name: Device name for logging
|
device_name: Device name for logging
|
||||||
param_name: Parameter name
|
param_name: Parameter name
|
||||||
expected_value: Expected value
|
expected_value: Expected value
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if verified or verification not possible
|
bool: True if verified or verification not possible
|
||||||
"""
|
"""
|
||||||
# Only verify certain parameters
|
# Only verify certain parameters
|
||||||
verifiable = ['PowerOnState', 'SetOption']
|
verifiable = ['PowerOnState', 'SetOption']
|
||||||
|
|
||||||
if not any(param_name.startswith(v) for v in verifiable):
|
if not any(param_name.startswith(v) for v in verifiable):
|
||||||
return True # Can't verify, assume success
|
return True # Can't verify, assume success
|
||||||
|
|
||||||
# Get current value
|
# Get current value
|
||||||
result, success = send_tasmota_command(
|
result, success = send_tasmota_command(
|
||||||
device_ip, param_name, timeout=5, logger=self.logger
|
device_ip, param_name, timeout=5, logger=self.logger
|
||||||
)
|
)
|
||||||
|
|
||||||
if not success or not result:
|
if not success or not result:
|
||||||
return True # Can't verify, assume success
|
return True # Can't verify, assume success
|
||||||
|
|
||||||
# Check if value matches
|
# Check if value matches
|
||||||
current_value = result.get(param_name, '')
|
current_value = str(result.get(param_name, ''))
|
||||||
|
expected = str(expected_value)
|
||||||
if str(current_value) == str(expected_value):
|
|
||||||
|
# Normalize values for comparison (Tasmota returns ON/OFF for 1/0)
|
||||||
|
def normalize_value(val: str) -> str:
|
||||||
|
val_lower = val.lower()
|
||||||
|
if val_lower in ['on', '1', 'true']:
|
||||||
|
return '1'
|
||||||
|
elif val_lower in ['off', '0', 'false']:
|
||||||
|
return '0'
|
||||||
|
return val_lower
|
||||||
|
|
||||||
|
if normalize_value(current_value) == normalize_value(expected):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def print_failure_summary(self):
|
def print_failure_summary(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user