fixed return values from backend

This commit is contained in:
ari committed 2022-09-02 10:11:38 -04:00
1 parent c461640957
commit 7526b578ba
3 files changed
+20 -14

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ from src.hass_config.loader import HassConfig
def make_automation_router(hass_config: HassConfig) -> APIRouter:
router = APIRouter()
@router.post("/list")
@router.post("/list", response_model_exclude_unset=True, response_model_exclude_none=True)
def list_autos(body: ListParams) -> ListData[ExtenededAutomation]:
automations = AutomationManager(hass_config)
try:
+18 -6
View File
@@ -41,27 +41,39 @@ class BaseAutomation(BaseModel):
condition: list[dict] = []
action: list[dict] = []
def to_primitive(self):
return self.dict(exclude_unset=True, exclude_none=True)
def to_primitive(self, exclude_unset=True, exclude_none=True, **kwrgs):
return BaseModel.dict(self, exclude_unset=exclude_unset, exclude_none=exclude_none, **kwrgs)
def dict(self, **kwrgs):
kwrgs["exclude_unset"] = True
kwrgs["exclude_none"] = True
return self.to_primitive(
**kwrgs,
)
class Automation(BaseAutomation):
tags: dict[str, str] = Field(default_factory=dict)
def to_primitive(self, include_tags: bool = False):
out = super().to_primitive()
def to_primitive(self, include_tags: bool = False, **kwrgs):
out = super().to_primitive(**kwrgs)
if not include_tags and out.get("tags", None) is not None:
del out["tags"]
if include_tags and out.get("tags", None) is None:
out["tags"] = {}
return out
def dict(self, **kwrgs):
return BaseAutomation.dict(self, **kwrgs, include_tags=True)
class ExtenededAutomation(Automation):
source_file: str
source_file_type: Literal["list", "obj", "inline"]
configuration_key: ConfigurationKey
def to_primitive(self, include_tags: bool = False):
out = super().to_primitive(include_tags=include_tags)
def to_primitive(self, include_tags: bool = False, **kwrgs):
out = super().to_primitive(include_tags=include_tags, **kwrgs)
del out["source_file"]
del out["source_file_type"]
del out["configuration_key"]
+1 -7
View File
@@ -34,15 +34,9 @@ export const makeRemoteAPI = (baseURL: string): API => ({
return response;
} catch (err) {
console.error(err);
let error = String(err);
if (err instanceof Error) {
error += ` ${err.stack}`;
}
return {
ok: false,
error,
error: `Server error: ${method} ${path}`,
};
}
},