diff --git a/src/panels/config/person/dialog-person-detail.ts b/src/panels/config/person/dialog-person-detail.ts index 54d3af044b..defc96144b 100644 --- a/src/panels/config/person/dialog-person-detail.ts +++ b/src/panels/config/person/dialog-person-detail.ts @@ -9,9 +9,9 @@ import { import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable"; import "@polymer/paper-input/paper-input"; import "@material/mwc-button"; +import memoizeOne from "memoize-one"; import "../../../components/dialog/ha-paper-dialog"; - import "../../../components/entity/ha-entities-picker"; import "../../../components/user/ha-user-picker"; import { PersonDetailDialogParams } from "./show-dialog-person-detail"; @@ -29,6 +29,13 @@ class DialogPersonDetail extends LitElement { @property() private _params?: PersonDetailDialogParams; @property() private _submitting: boolean = false; + private _deviceTrackersAvailable = memoizeOne((hass) => { + return Object.keys(hass.states).some( + (entityId) => + entityId.substr(0, entityId.indexOf(".")) === "device_tracker" + ); + }); + public async showDialog(params: PersonDetailDialogParams): Promise { this._params = params; this._error = undefined; @@ -87,23 +94,55 @@ class DialogPersonDetail extends LitElement { .users=${this._params.users} @value-changed=${this._userChanged} > -

- ${this.hass.localize( - "ui.panel.config.person.detail.device_tracker_intro" - )} -

- + ${this._deviceTrackersAvailable(this.hass) + ? html` +

+ ${this.hass.localize( + "ui.panel.config.person.detail.device_tracker_intro" + )} +

+ + + ` + : html` +

+ ${this.hass!.localize( + "ui.panel.config.person.detail.no_device_tracker_available_intro" + )} +

+ + `}
@@ -131,6 +170,10 @@ class DialogPersonDetail extends LitElement { `; } + private _closeDialog() { + this._params = undefined; + } + private _nameChanged(ev: PolymerChangedEvent) { this._error = undefined; this._name = ev.detail.value; diff --git a/src/translations/en.json b/src/translations/en.json index 9b2d7f0b7b..d18a2448ea 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1148,6 +1148,9 @@ "name_error_msg": "Name is required", "linked_user": "Linked User", "device_tracker_intro": "Select the devices that belong to this person.", + "no_device_tracker_available_intro": "When you have devices that indicate the presence of a person, you will be able to assign them to a person here. You can add your first device by adding a presence-detection integration from the integrations page.", + "link_presence_detection_integrations": "Presence Detection Integrations", + "link_integrations_page": "Integrations page", "device_tracker_picked": "Track Device", "device_tracker_pick": "Pick device to track", "delete": "Delete",