-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathtest_latitude_error.py
More file actions
60 lines (51 loc) · 1.84 KB
/
test_latitude_error.py
File metadata and controls
60 lines (51 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Simple test to reproduce the latitude error.
"""
import asyncio
import os
import sys
from unittest.mock import AsyncMock, MagicMock
# Add the custom components to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'custom_components'))
try:
from smart_irrigation import SmartIrrigationCoordinator
print("Successfully imported SmartIrrigationCoordinator")
# Create a mock hass instance
mock_hass = MagicMock()
mock_hass.config.as_dict.return_value = {
"latitude": 45.0,
"longitude": -122.0,
"elevation": 100
}
mock_hass.config.units.is_metric = True
mock_hass.data = {"smart_irrigation": {"use_weather_service": False}}
# Create a mock entry
mock_entry = MagicMock()
mock_entry.unique_id = "test_entry"
# Create a mock store
mock_store = MagicMock()
mock_store.get_config.return_value = {
"autocalcenabled": False,
"autoupdateenabled": False,
"autoclearenabled": False,
"starteventfiredtoday": False
}
# Create coordinator - this should trigger the AttributeError
print("Creating coordinator...")
coordinator = SmartIrrigationCoordinator(mock_hass, None, mock_entry, mock_store)
print("Coordinator created successfully!")
# Try to call the method that would fail
print("Testing _generate_monthly_climate_data...")
monthly_data = coordinator._generate_monthly_climate_data()
print(f"Generated {len(monthly_data)} months of data")
except AttributeError as e:
print(f"AttributeError caught: {e}")
if "_latitude" in str(e):
print("This is the expected latitude error!")
else:
print("This is a different AttributeError")
except Exception as e:
print(f"Other error: {type(e).__name__}: {e}")
import traceback
traceback.print_exc()