initial api

This commit is contained in:
Ari Sosnovsky committed 2021-11-09 21:38:17 -05:00
1 parent 899d78fba5
commit e87c41f496
16 files changed
+458 -2

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
from sqlalchemy import create_engine, text
from urllib.parse import urlparse
class HassDatabase:
def __init__(self, db_url: str) -> None:
self.url = urlparse(db_url)
self.entities = None
try:
self.engine = create_engine(db_url)
except Exception as exc:
if isinstance(exc, ImportError):
raise RuntimeError(
"The right dependency to connect to your database is "
"missing. Please make sure that it is installed."
) from exc
raise
@property
def db_type(self):
return self.url.scheme.split("+")[0]