mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-11-19 02:23:42 -05:00
Add additional features
This commit is contained in:
@@ -83,6 +83,7 @@ class OasisMini:
|
||||
_access_token: str | None = None
|
||||
_mac_address: str | None = None
|
||||
_ip_address: str | None = None
|
||||
_playlist: dict[int, dict[str, str]] = {}
|
||||
_serial_number: str | None = None
|
||||
_software_version: str | None = None
|
||||
_track: dict | None = None
|
||||
@@ -326,11 +327,18 @@ class OasisMini:
|
||||
"""Get cloud track info."""
|
||||
return await self._async_cloud_request("GET", f"api/track/{track_id}")
|
||||
|
||||
async def async_cloud_get_tracks(self, tracks: list[int]) -> dict:
|
||||
async def async_cloud_get_tracks(
|
||||
self, tracks: list[int] | None = None
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Get tracks info from the cloud"""
|
||||
return await self._async_cloud_request(
|
||||
"GET", "api/track", params={"ids[]": tracks}
|
||||
response = await self._async_cloud_request(
|
||||
"GET", "api/track", params={"ids[]": tracks or []}
|
||||
)
|
||||
track_details = response.get("data", [])
|
||||
while next_page_url := response.get("next_page_url"):
|
||||
response = await self._async_cloud_request("GET", next_page_url)
|
||||
track_details += response.get("data", [])
|
||||
return track_details
|
||||
|
||||
async def async_cloud_get_latest_software_details(self) -> dict[str, int | str]:
|
||||
"""Get the latest software details from the cloud."""
|
||||
@@ -344,9 +352,21 @@ class OasisMini:
|
||||
self._track = await self.async_cloud_get_track_info(self.track_id)
|
||||
return self._track
|
||||
|
||||
async def async_get_playlist_details(self) -> dict:
|
||||
async def async_get_playlist_details(self) -> dict[int, dict[str, str]]:
|
||||
"""Get playlist info."""
|
||||
return await self.async_cloud_get_tracks(self.playlist)
|
||||
if set(self.playlist).difference(self._playlist.keys()):
|
||||
tracks = await self.async_cloud_get_tracks(self.playlist)
|
||||
self._playlist = {
|
||||
track["id"]: {
|
||||
"name": track["name"],
|
||||
"author": ((track.get("author") or {}).get("person") or {}).get(
|
||||
"name", "Oasis Mini"
|
||||
),
|
||||
"image": track["image"],
|
||||
}
|
||||
for track in tracks
|
||||
}
|
||||
return self._playlist
|
||||
|
||||
async def _async_cloud_request(self, method: str, url: str, **kwargs: Any) -> Any:
|
||||
"""Perform a cloud request."""
|
||||
|
||||
@@ -833,5 +833,90 @@
|
||||
"name": "Horse",
|
||||
"author": "Otávio Bittencourt",
|
||||
"image": "2024/07/9fec8716ce98fdbf0c02db14b47b0d66.svg"
|
||||
},
|
||||
"513": {
|
||||
"name": "Clover Flower",
|
||||
"author": "Riley P",
|
||||
"image": "2024/06/b7de1c0518e5ce9cbdd8f3dd6d995e3a.svg"
|
||||
},
|
||||
"537": {
|
||||
"name": "Full moon",
|
||||
"author": "001547.d33e09ec63fb4259a31a494ad194e028.0314",
|
||||
"image": "2024/07/3b06cb1bd961c01bd2411515549d907e.svg"
|
||||
},
|
||||
"531": {
|
||||
"name": "Ghost",
|
||||
"author": "Stephen Murphy",
|
||||
"image": "2024/07/106d0bed641489cc5b2ee371dcfdebfa.svg"
|
||||
},
|
||||
"509": {
|
||||
"name": "Heart loop",
|
||||
"author": "000653.17c9b352828247bd858234a2a114f79b.1358",
|
||||
"image": "2024/06/985c1c16fe0ce704b17229a8c7e795f5.svg"
|
||||
},
|
||||
"535": {
|
||||
"name": "Hubcap",
|
||||
"author": "001547.d33e09ec63fb4259a31a494ad194e028.0314",
|
||||
"image": "2024/07/565216e030c9fa2a474c4f57366a5cc3.svg"
|
||||
},
|
||||
"538": {
|
||||
"name": "Noise cell",
|
||||
"author": "001547.d33e09ec63fb4259a31a494ad194e028.0314",
|
||||
"image": "2024/07/b60bebf49043ef7969a722d826e88bf5.svg"
|
||||
},
|
||||
"559": {
|
||||
"name": "Polymath",
|
||||
"author": "Codie Johnston",
|
||||
"image": "2024/07/7a5fd9826476071567967fc17ec6cb12.svg"
|
||||
},
|
||||
"1264": {
|
||||
"name": "Raccoon",
|
||||
"author": "Otávio Bittencourt",
|
||||
"image": "2024/07/5ff0bd18649b029e16ac32f3b96f9715.svg"
|
||||
},
|
||||
"551": {
|
||||
"name": "snowflake",
|
||||
"author": "christina",
|
||||
"image": "2024/07/77ae32407d7d2563110b1ee4607f6b7e.svg"
|
||||
},
|
||||
"553": {
|
||||
"name": "spheres",
|
||||
"author": "max",
|
||||
"image": "2024/07/7a292d6cb204fbe4fc4a56ef8e4e9228.svg"
|
||||
},
|
||||
"544": {
|
||||
"name": "Star round",
|
||||
"author": "Codie Johnston",
|
||||
"image": "2024/07/5e05532a764a109b090abc06f217f62e.svg"
|
||||
},
|
||||
"517": {
|
||||
"name": "Starburst",
|
||||
"author": "001547.d33e09ec63fb4259a31a494ad194e028.0314",
|
||||
"image": "2024/06/ec2c03a42db75c33ddf677c6ac52e7b3.svg"
|
||||
},
|
||||
"1137": {
|
||||
"name": "Tiger",
|
||||
"author": "Otávio Bittencourt",
|
||||
"image": "2024/07/02da0d000c200fb8cab3f1d38a90e077.svg"
|
||||
},
|
||||
"528": {
|
||||
"name": "Tight spiral in to out",
|
||||
"author": "Codie Johnston",
|
||||
"image": "2024/06/82360f9b4c9dc169bceb99a1b4a3a13c.svg"
|
||||
},
|
||||
"527": {
|
||||
"name": "Tight spiral out to in",
|
||||
"author": "Codie Johnston",
|
||||
"image": "2024/06/eef9f4aa33ca80e3f09e4c4661c6c80e.svg"
|
||||
},
|
||||
"519": {
|
||||
"name": "Web",
|
||||
"author": "000653.17c9b352828247bd858234a2a114f79b.1358",
|
||||
"image": "2024/06/9c05e1e19cb5ecf6e156e44a8a8829e5.svg"
|
||||
},
|
||||
"536": {
|
||||
"name": "Yin yang",
|
||||
"author": "001547.d33e09ec63fb4259a31a494ad194e028.0314",
|
||||
"image": "2024/07/36fe669628c5e4dfd6d33a263196a750.svg"
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@ def draw_svg(track: dict, progress: int, model_id: str) -> str | None:
|
||||
if progress is not None:
|
||||
paths = svg_content.split("L")
|
||||
total = track.get("reduced_svg_content", {}).get(model_id, len(paths))
|
||||
percent = (100 * progress) / total
|
||||
progress = math.floor((percent / 100) * len(paths))
|
||||
percent = min((100 * progress) / total, 100)
|
||||
progress = math.floor((percent / 100) * (len(paths) - 1))
|
||||
|
||||
svg = Element(
|
||||
"svg",
|
||||
|
||||
Reference in New Issue
Block a user