Config for ticker and aggregate Calendars
This commit is contained in:
parent
a069fe5078
commit
e804ae68f8
3 changed files with 39 additions and 12 deletions
|
@ -10,21 +10,25 @@ from tomli import loads as toml_loads
|
||||||
from tomli_w import dump as toml_dump
|
from tomli_w import dump as toml_dump
|
||||||
from webdav3.exceptions import RemoteResourceNotFound
|
from webdav3.exceptions import RemoteResourceNotFound
|
||||||
|
|
||||||
|
from ovdashboard_api.dav_common import caldav_list
|
||||||
|
|
||||||
from .dav_file import DavFile
|
from .dav_file import DavFile
|
||||||
|
|
||||||
|
|
||||||
class TickerConfig(BaseModel):
|
class TickerConfig(BaseModel):
|
||||||
"""
|
"""
|
||||||
Sections "[ticker.*]" in "config.txt".
|
Section "[ticker]" in "config.txt".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
separator: str = " +++ "
|
separator: str = " +++ "
|
||||||
comment_marker: str = "#"
|
comment_marker: str = "#"
|
||||||
|
color: str = "primary"
|
||||||
|
speed: int = 30
|
||||||
|
|
||||||
|
|
||||||
class ImageConfig(BaseModel):
|
class ImageConfig(BaseModel):
|
||||||
"""
|
"""
|
||||||
Sections "[image.*]" in "config.txt".
|
Sections "[image*]" in "config.txt".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mode: str = "RGB"
|
mode: str = "RGB"
|
||||||
|
@ -34,6 +38,15 @@ class ImageConfig(BaseModel):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AggregateCalendarConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Sections "[[aggregate]]" in "config.txt".
|
||||||
|
"""
|
||||||
|
|
||||||
|
name: str = "All Events"
|
||||||
|
calendars: list[str]
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
"""
|
"""
|
||||||
Main representation of "config.txt".
|
Main representation of "config.txt".
|
||||||
|
@ -41,6 +54,7 @@ class Config(BaseModel):
|
||||||
|
|
||||||
ticker: TickerConfig = TickerConfig()
|
ticker: TickerConfig = TickerConfig()
|
||||||
image: ImageConfig = ImageConfig()
|
image: ImageConfig = ImageConfig()
|
||||||
|
aggregate: list[AggregateCalendarConfig] = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get(cls) -> "Config":
|
async def get(cls) -> "Config":
|
||||||
|
@ -56,10 +70,14 @@ class Config(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
except RemoteResourceNotFound:
|
except RemoteResourceNotFound:
|
||||||
buffer = BytesIO()
|
cfg = cls()
|
||||||
toml_dump(cls().dict(), buffer)
|
cfg.aggregate.append(
|
||||||
buffer.seek(0)
|
AggregateCalendarConfig(calendars=await caldav_list()),
|
||||||
|
)
|
||||||
|
|
||||||
|
buffer = BytesIO()
|
||||||
|
toml_dump(cfg.dict(), buffer)
|
||||||
|
buffer.seek(0)
|
||||||
await dav_file.dump(buffer.read())
|
await dav_file.dump(buffer.read())
|
||||||
|
|
||||||
return cls()
|
return cfg
|
||||||
|
|
|
@ -3,7 +3,7 @@ Definition of WebDAV and CalDAV clients.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import Any
|
from typing import Any, Iterator
|
||||||
|
|
||||||
from caldav import DAVClient as CalDAVclient
|
from caldav import DAVClient as CalDAVclient
|
||||||
from caldav import Principal as CalDAVPrincipal
|
from caldav import Principal as CalDAVPrincipal
|
||||||
|
@ -55,3 +55,15 @@ def caldav_principal() -> CalDAVPrincipal:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return _CALDAV_CLIENT.principal()
|
return _CALDAV_CLIENT.principal()
|
||||||
|
|
||||||
|
|
||||||
|
@run_in_executor
|
||||||
|
def caldav_list() -> Iterator[str]:
|
||||||
|
"""
|
||||||
|
Asynchroneously lists all calendars using the main WebDAV client.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return (
|
||||||
|
cal.name
|
||||||
|
for cal in caldav_principal().calendars()
|
||||||
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from typing import Iterator, Protocol
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
from webdav3.exceptions import RemoteResourceNotFound
|
from webdav3.exceptions import RemoteResourceNotFound
|
||||||
|
|
||||||
from ..dav_common import caldav_principal, webdav_list
|
from ..dav_common import caldav_list, webdav_list
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -71,10 +71,7 @@ class CalendarNameLister:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def __call__(self) -> Iterator[str]:
|
async def __call__(self) -> Iterator[str]:
|
||||||
return (
|
return await caldav_list()
|
||||||
cal.name
|
|
||||||
for cal in caldav_principal().calendars()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
|
Loading…
Reference in a new issue