Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed path issue in init script #7

Merged
merged 8 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions custom_components/simple_sticky_note/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from homeassistant.helpers.typing import ConfigType
from homeassistant.const import Platform
from homeassistant.helpers import config_validation as cv

from .const import DOMAIN

PLATFORMS: list[Platform] = [Platform.SENSOR]
Expand All @@ -12,27 +11,32 @@

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Simple Sticky Note component."""
# This registers your JavaScript file to be served by Home Assistant
# Register the static path for your JavaScript file
hass.http.register_static_path(
f"/custom_components/{DOMAIN}/js/sticky_note_card.js",
hass.config.path(f"custom_components/{DOMAIN}/js/sticky_note_card.js"),
True
)

# Register as a Lovelace resource
hass.components.frontend.add_resources([f"/local/custom_components/{DOMAIN}/js/sticky_note_card.js"])
# Add the resource to Lovelace
resource_url = f"/custom_components/{DOMAIN}/js/sticky_note_card.js"
if not any(resource["url"] == resource_url for resource in hass.data["lovelace"]["resources"].async_items()):
await hass.data["lovelace"]["resources"].async_create_item({"res_type": "module", "url": resource_url})

return True

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Simple Sticky Note from a config entry."""
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = entry.data

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
4 changes: 2 additions & 2 deletions custom_components/simple_sticky_note/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"name": "Simple Sticky Note",
"codeowners": ["@biofects"],
"config_flow": true,
"dependencies": [],
"dependencies": ["frontend", "lovelace"],
"documentation": "https://github.com/biofects/simple_sticky_note",
"iot_class": "local_push",
"issue_tracker": "https://github.com/biofects/simple_sticky_note/issues",
"requirements": [],
"version": "1.3.1"
"version": "1.3.6"
}
Loading