35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Simple backup check"""
|
|
import urllib.request
|
|
import json
|
|
|
|
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI4NmM2ZGNlMTY2MWU0M2U5YjQ2MDI3MjMxYjE0NDFlMyIsImlhdCI6MTc2NzE3ODUyNiwiZXhwIjoyMDgyNTM4NTI2fQ.E8eShOsejwDYglixpgM_d_JYBlB1OVNhN7cHPnPiLOs"
|
|
HA_URL = "http://192.168.68.25:8123"
|
|
|
|
url = f"{HA_URL}/api/states"
|
|
req = urllib.request.Request(url)
|
|
req.add_header("Authorization", f"Bearer {TOKEN}")
|
|
|
|
try:
|
|
with urllib.request.urlopen(req) as response:
|
|
states = json.loads(response.read().decode())
|
|
backup_entities = [e for e in states if 'backup' in e['entity_id'].lower()]
|
|
|
|
print("Backup Information:")
|
|
print("="*60)
|
|
for entity in sorted(backup_entities, key=lambda x: x['entity_id']):
|
|
eid = entity['entity_id']
|
|
state = entity.get('state', 'N/A')
|
|
attrs = entity.get('attributes', {})
|
|
name = attrs.get('friendly_name', eid)
|
|
|
|
print(f"\n{name}")
|
|
print(f" Entity: {eid}")
|
|
print(f" State: {state}")
|
|
if attrs:
|
|
for key in ['last_attempted', 'last_successful', 'next_scheduled', 'state']:
|
|
if key in attrs:
|
|
print(f" {key}: {attrs[key]}")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|