#!/usr/bin/env python3
"""
Test Pushover notifications immediately
"""

import requests
import json
from datetime import datetime

# Pushover credentials
PUSHOVER_APP_TOKEN = "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"  # Replace with your actual app token
PUSHOVER_USER_KEY = "u1v2w3x4y5z6a7b8c9d0e1f2g3h4i5j6"  # Replace with your actual user key
SECOND_USER_KEY = "us5sg9aqb2i7iqbjmmocr7p2df1ymp"

def send_pushover_notification(user_key, app_token, message):
    """Send Pushover notification"""
    url = "https://api.pushover.net/1/messages.json"
    
    data = {
        "token": app_token,
        "user": user_key,
        "message": message,
        "title": "⚡ Solar Monitor Test",
        "sound": "cosmic",
        "priority": 0
    }
    
    try:
        response = requests.post(url, data=data)
        if response.status_code == 200:
            print(f"✅ Pushover notification sent successfully to user {user_key}")
            return True
        else:
            print(f"❌ Pushover API error: {response.status_code} - {response.text}")
            return False
    except Exception as e:
        print(f"❌ Error sending notification: {e}")
        return False

def main():
    print("🧪 Testing Pushover notifications...")
    print(f"⏰ Current time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    
    # Test message
    message = f"""🧪 TEST NOTIFICATION

🔋 Current Power: 2.5 kW
📊 E Today: 12.3 kWh
📈 E Yesterday: 15.7 kWh
📅 E This Month: 234.5 kWh

⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
🎯 This is a test notification from Solar Monitor plugin!"""

    print(f"📤 Sending test message to primary user...")
    success1 = send_pushover_notification(PUSHOVER_USER_KEY, PUSHOVER_APP_TOKEN, message)
    
    print(f"📤 Sending test message to second user...")
    success2 = send_pushover_notification(SECOND_USER_KEY, PUSHOVER_APP_TOKEN, message)
    
    if success1 and success2:
        print("🎉 All test notifications sent successfully!")
    else:
        print("⚠️ Some notifications failed. Check credentials and network.")

if __name__ == "__main__":
    main() 