added support for home assistant postgres database and convenience function to get state of entity

This commit is contained in:
Brian Bjarke Jensen
2026-01-24 19:48:13 +01:00
parent aaa724164c
commit d59f7d2e2d
20 changed files with 504 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
"""SQLAlchemy model for the 'statistics' table in the Home Assistant PostgreSQL database."""
from sqlalchemy import Column, BigInteger, TIMESTAMP, Float, ForeignKey
from .base import Base
class Statistics(Base):
"""SQLAlchemy model for the 'statistics' table."""
__tablename__ = "statistics"
__table_args__ = {"schema": "public"}
id = Column(BigInteger, primary_key=True, autoincrement=True)
created = Column(TIMESTAMP(timezone=True), nullable=True)
created_ts = Column(Float, nullable=True)
metadata_id = Column(
BigInteger, ForeignKey("public.statistics_meta.id", ondelete="CASCADE"), nullable=True
)
start = Column(TIMESTAMP(timezone=True), nullable=True)
start_ts = Column(Float, nullable=True)
mean = Column(Float, nullable=True)
mean_weight = Column(Float, nullable=True)
min = Column(Float, nullable=True)
max = Column(Float, nullable=True)
last_reset = Column(TIMESTAMP(timezone=True), nullable=True)
last_reset_ts = Column(Float, nullable=True)
state = Column(Float, nullable=True)
sum = Column(Float, nullable=True)