-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_db.py
More file actions
28 lines (23 loc) · 1.02 KB
/
inspect_db.py
File metadata and controls
28 lines (23 loc) · 1.02 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
from sqlalchemy import create_engine, Column, Integer, String, Boolean
from sqlalchemy.orm import sessionmaker, declarative_base
Base = declarative_base()
class Sensor(Base):
__tablename__ = "sensors"
id = Column(Integer, primary_key=True, index=True)
unique_id = Column(String, unique=True, index=True)
name = Column(String)
type = Column(String)
is_hidden = Column(Boolean, default=False)
# Connect to the database
SQLALCHEMY_DATABASE_URL = "sqlite:///./backend/matter_logger.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()
# Query sensors
sensors = db.query(Sensor).all()
print(f"Found {len(sensors)} sensors:")
for s in sensors:
print(f"ID: {s.id}, Name: '{s.name}', UniqueID: '{s.unique_id}', Hidden: {s.is_hidden}")
# Check for demo sensors specifically
demo_sensors = db.query(Sensor).filter(Sensor.unique_id.like("demo-%")).all()
print(f"\nFound {len(demo_sensors)} demo sensors via LIKE 'demo-%'")