generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Utility functions for Linus Dashboard custom components.""" | ||
|
||
import logging | ||
|
||
from homeassistant.components.frontend import add_extra_js_url | ||
from homeassistant.components.lovelace.resources import ResourceStorageCollection | ||
from homeassistant.core import HomeAssistant | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def init_resource(hass: HomeAssistant, url: str, ver: str) -> bool: | ||
""" | ||
Add extra JS module for lovelace mode YAML and new lovelace resource | ||
for mode GUI. It's better to add extra JS for all modes, because it has | ||
random url to avoid problems with the cache. But chromecast don't support | ||
extra JS urls and can't load custom card. | ||
""" | ||
|
||
resources: ResourceStorageCollection = hass.data["lovelace"]["resources"] | ||
# force load storage | ||
await resources.async_get_info() | ||
|
||
url2 = f"{url}?v={ver}" | ||
|
||
for item in resources.async_items(): | ||
if not item.get("url", "").startswith(url): | ||
continue | ||
|
||
# no need to update | ||
if item["url"].endswith(ver): | ||
return False | ||
|
||
_LOGGER.debug(f"Update lovelace resource to: {url2}") | ||
|
||
if isinstance(resources, ResourceStorageCollection): | ||
await resources.async_update_item( | ||
item["id"], {"res_type": "module", "url": url2} | ||
) | ||
else: | ||
# not the best solution, but what else can we do | ||
item["url"] = url2 | ||
|
||
return True | ||
|
||
if isinstance(resources, ResourceStorageCollection): | ||
_LOGGER.debug(f"Add new lovelace resource: {url2}") | ||
await resources.async_create_item({"res_type": "module", "url": url2}) | ||
else: | ||
_LOGGER.debug(f"Add extra JS module: {url2}") | ||
add_extra_js_url(hass, url2) | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "Linus dashboard", | ||
"hide_default_branch": true, | ||
"homeassistant": "2024.6.0", | ||
"homeassistant": "2024.10.0", | ||
"render_readme": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
colorlog==6.8.2 | ||
homeassistant==2024.6.0 | ||
homeassistant==2024.10.2 | ||
pip>=21.3.1 | ||
ruff==0.6.7 |