Beispiel #1
0
def setup_view(hass: HomeAssistant):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    path_to_file = "{}/home-assistant-neerslag-card/neerslag-card.js".format(dir_path)
    should_cache = False

    hass.http.register_static_path(FRONTEND_SCRIPT_URL , str(path_to_file), should_cache)
    add_extra_js_url(hass, FRONTEND_SCRIPT_URL, es5=False)
Beispiel #2
0
def setup_view(hass: HomeAssistant):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    path_to_file = "{}/home-assistant-neerslag-card/neerslag-card.js".format(
        dir_path)
    should_cache = False

    timestamp = str(time.time())
    frontend_script_url_with_parameter = FRONTEND_SCRIPT_URL + "?cache=" + timestamp

    hass.http.register_static_path(FRONTEND_SCRIPT_URL, str(path_to_file),
                                   should_cache)
    add_extra_js_url(hass, frontend_script_url_with_parameter, es5=False)
Beispiel #3
0
async def async_setup(hass, config):
    hass.http.register_static_path(LOADER_URL, hass.config.path(LOADER_PATH),
                                   True)
    add_extra_js_url(hass, LOADER_URL)

    for iset in ["brands", "regular", "solid"]:
        hass.http.register_static_path(
            ICONS_URL + "/" + iset, hass.config.path(ICONS_PATH + "/" + iset),
            True)
    hass.http.register_static_path(CUSTOM_ICONS_URL,
                                   hass.config.path(CUSTOM_ICONS_PATH), True)

    return True
Beispiel #4
0
async def init_resource(hass: HomeAssistantType, 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}?{ver}"

    for item in resources.async_items():
        if not item['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
Beispiel #5
0
async def init_resource(hass: HomeAssistantType, url: 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()

    for item in resources.async_items():
        if item['url'] == url:
            return False

    if isinstance(resources, ResourceStorageCollection):
        _LOGGER.debug(f"Add new lovelace resource: {url}")
        await resources.async_create_item({'res_type': 'module', 'url': url})
    else:
        _LOGGER.debug(f"Add extra JS module: {url}")
        add_extra_js_url(hass, f"{url}?{random.random()}")

    return True
Beispiel #6
0
async def async_setup(hass: HomeAssistantType, config: ConfigType):
    # check and download file if needed
    filepath = hass.config.path(utils.get_binary_name(BINARY_VERSION))
    if not os.path.isfile(filepath):
        for file in os.listdir(hass.config.config_dir):
            if file.startswith('rtsp2webrtc_'):
                _LOGGER.debug(f"Remove old binary: {file}")
                os.remove(hass.config.path(file))

        url = utils.get_binary_url(BINARY_VERSION)
        _LOGGER.debug(f"Download new binary: {url}")

        session = async_get_clientsession(hass)
        r = await session.get(url)
        raw = await r.read()
        open(filepath, 'wb').write(raw)
        os.chmod(filepath, 744)

    Server.filepath = filepath

    # serve lovelace card
    url_path = '/webrtc/webrtc-camera.js'
    path = hass.config.path('custom_components/webrtc/www/webrtc-camera.js')
    hass.http.register_static_path(url_path, path, cache_headers=False)

    # remove lovelace card from previous version
    await utils.delete_resource(hass, url_path)

    # register lovelace card
    add_extra_js_url(hass, f"{url_path}?{random.random()}")

    # component uses websocket, but some users can use REST API for integrate
    # WebRTC to their software
    websocket_api.async_register_command(hass, websocket_webrtc_stream)
    hass.http.register_view(WebRTCStreamView)

    return True
Beispiel #7
0
def load_plugins(hass, name):
    add_extra_js_url(hass, "/dwains_dashboard/js/dwains-dashboard.js")

    #Cards by others
    add_extra_js_url(hass,
                     "/dwains_dashboard/cards/button-card/button-card.js")
    add_extra_js_url(
        hass, "/dwains_dashboard/cards/light-entity-card/light-entity-card.js")
    #Cards by dwains
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-header-card/dwains-header-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-heading-card/dwains-heading-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-wrapper-card/dwains-wrapper-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-flexbox-card/dwains-flexbox-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-hash-switch-card/dwains-hash-switch-card.js"
    )
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-weather-card/dwains-weather-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-notification-card/dwains-notification-card.js"
    )
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-collapse-card/dwains-collapse-card.js")
    add_extra_js_url(
        hass, "/dwains_dashboard/cards/dwains-cover-card/dwains-cover-card.js")
    add_extra_js_url(
        hass,
        "/dwains_dashboard/cards/dwains-auto-entities-card/dwains-auto-entities-card.js"
    )

    hass.http.register_static_path(
        "/dwains_dashboard/js",
        hass.config.path(f"custom_components/{name}/js"), True)
    hass.http.register_static_path(
        "/dwains_dashboard/cards",
        hass.config.path(f"custom_components/{name}/cards"), True)
Beispiel #8
0
def load_plugins(hass, name):
    add_extra_js_url(hass, "/dwains_dashboard/js/dwains-dashboard.js?version="+VERSION)

    hass.http.register_static_path("/dwains_dashboard/js", hass.config.path(f"custom_components/{name}/js"), True)