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

Use integration manifest for service documentation URL #9960

Merged
merged 4 commits into from
Sep 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/components/ha-service-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import {
HassServiceTarget,
} from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property, state, query } from "lit/decorators";
import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../common/dom/fire_event";
import { computeDomain } from "../common/entity/compute_domain";
import { computeObjectId } from "../common/entity/compute_object_id";
import {
fetchIntegrationManifest,
IntegrationManifest,
} from "../data/integration";
import { Selector } from "../data/selector";
import { PolymerChangedEvent } from "../polymer-types";
import { HomeAssistant } from "../types";
import { documentationUrl } from "../util/documentation-url";
import "./ha-checkbox";
import "./ha-selector/ha-selector";
import "./ha-service-picker";
Expand Down Expand Up @@ -53,6 +56,8 @@ export class HaServiceControl extends LitElement {

@state() private _checkedKeys = new Set();

@state() private _manifest?: IntegrationManifest;

@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;

protected updated(changedProperties: PropertyValues<this>) {
Expand All @@ -72,6 +77,19 @@ export class HaServiceControl extends LitElement {
this.hass.services
);

// Fetch the manifest if we have a service selected and the service domain changed.
// If no service is selected, clear the manifest.
if (this.value?.service) {
if (
!oldValue?.service ||
computeDomain(this.value.service) !== computeDomain(oldValue.service)
) {
this._fetchManifest(computeDomain(this.value?.service));
}
} else {
this._manifest = undefined;
}

if (
serviceData &&
"target" in serviceData &&
Expand Down Expand Up @@ -177,12 +195,9 @@ export class HaServiceControl extends LitElement {
></ha-service-picker>
<div class="description">
<p>${serviceData?.description}</p>
${this.value?.service
${this._manifest
? html` <a
href="${documentationUrl(
this.hass,
"/integrations/" + computeDomain(this.value?.service)
)}"
href="${this._manifest.documentation}"
title="${this.hass.localize(
"ui.components.service-control.integration_doc"
)}"
Expand Down Expand Up @@ -387,6 +402,15 @@ export class HaServiceControl extends LitElement {
});
}

private async _fetchManifest(integration: string) {
this._manifest = undefined;
try {
this._manifest = await fetchIntegrationManifest(this.hass, integration);
} catch (err) {
// Ignore if loading manifest fails. Probably bad JSON in manifest
spacegaier marked this conversation as resolved.
Show resolved Hide resolved
}
}

static get styles(): CSSResultGroup {
return css`
ha-settings-row {
Expand Down