added user profile
This commit is contained in:
1 parent
caad458b48
commit
95ac286b53
7 files changed
+97
-43
No files matched your search
@@ -0,0 +1,23 @@
|
||||
from typing import Literal
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.hass_config import HassConfig
|
||||
from src.yaml_serializer import load_yaml, dump_yaml
|
||||
|
||||
|
||||
class UserProfile(BaseModel):
|
||||
theme: Literal["dark", "light"] = "dark"
|
||||
lang: str = "eng"
|
||||
|
||||
@classmethod
|
||||
def from_hass_config(cls, hass_config: HassConfig):
|
||||
path = hass_config.get_profile_path()
|
||||
if path.exists():
|
||||
with hass_config.get_profile_path().open("r") as fp:
|
||||
return cls(**load_yaml(fp, hass_config.root_path))
|
||||
else:
|
||||
return cls()
|
||||
|
||||
def save(self, hass_config: HassConfig):
|
||||
with hass_config.get_profile_path().open("w") as fp:
|
||||
fp.write(dump_yaml(self.dict(), hass_config.root_path))
|
||||
Reference in new issue
Block a user