From 3f0f3affb6d8e33d4fe7eb7fb226d8fcff63f33d Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 14 Aug 2024 12:38:06 +0200 Subject: [PATCH] Remove deprecated mailbox (#21689) Remove mailbox --- gallery/src/data/demo_states.js | 9 - src/common/const.ts | 2 - src/layouts/partial-panel-resolver.ts | 1 - .../mailbox/ha-dialog-show-audio-message.ts | 153 ---------- src/panels/mailbox/ha-panel-mailbox.ts | 275 ------------------ src/translations/en.json | 7 - 6 files changed, 447 deletions(-) delete mode 100644 src/panels/mailbox/ha-dialog-show-audio-message.ts delete mode 100644 src/panels/mailbox/ha-panel-mailbox.ts diff --git a/gallery/src/data/demo_states.js b/gallery/src/data/demo_states.js index d57cc1a422b0..0351303f9e1e 100644 --- a/gallery/src/data/demo_states.js +++ b/gallery/src/data/demo_states.js @@ -532,15 +532,6 @@ export default { last_changed: "2018-07-19T10:44:46.200946+00:00", last_updated: "2018-07-19T10:44:46.200946+00:00", }, - "mailbox.demomailbox": { - entity_id: "mailbox.demomailbox", - state: "10", - attributes: { - friendly_name: "DemoMailbox", - }, - last_changed: "2018-07-19T10:45:16.555210+00:00", - last_updated: "2018-07-19T10:45:16.555210+00:00", - }, "input_select.living_room_preset": { entity_id: "input_select.living_room_preset", state: "Visitors", diff --git a/src/common/const.ts b/src/common/const.ts index 4f5c4af426fd..bc1f0c99d8c9 100644 --- a/src/common/const.ts +++ b/src/common/const.ts @@ -40,7 +40,6 @@ import { mdiImageFilterFrames, mdiLightbulb, mdiLightningBolt, - mdiMailbox, mdiMapMarkerRadius, mdiMeterGas, mdiMicrophoneMessage, @@ -119,7 +118,6 @@ export const FIXED_DOMAIN_ICONS = { input_text: mdiFormTextbox, lawn_mower: mdiRobotMower, light: mdiLightbulb, - mailbox: mdiMailbox, notify: mdiCommentAlert, number: mdiRayVertex, persistent_notification: mdiBell, diff --git a/src/layouts/partial-panel-resolver.ts b/src/layouts/partial-panel-resolver.ts index 48dce8ccf0ca..5c5611744bb7 100644 --- a/src/layouts/partial-panel-resolver.ts +++ b/src/layouts/partial-panel-resolver.ts @@ -29,7 +29,6 @@ const COMPONENTS = { history: () => import("../panels/history/ha-panel-history"), iframe: () => import("../panels/iframe/ha-panel-iframe"), logbook: () => import("../panels/logbook/ha-panel-logbook"), - mailbox: () => import("../panels/mailbox/ha-panel-mailbox"), map: () => import("../panels/map/ha-panel-map"), my: () => import("../panels/my/ha-panel-my"), profile: () => import("../panels/profile/ha-panel-profile"), diff --git a/src/panels/mailbox/ha-dialog-show-audio-message.ts b/src/panels/mailbox/ha-dialog-show-audio-message.ts deleted file mode 100644 index 56dab6882b40..000000000000 --- a/src/panels/mailbox/ha-dialog-show-audio-message.ts +++ /dev/null @@ -1,153 +0,0 @@ -import "@material/mwc-button"; -import "../../components/ha-dialog"; -import "../../components/ha-circular-progress"; -import "../../components/ha-icon"; -import "../../components/ha-icon-button"; -import { - CSSResultGroup, - LitElement, - TemplateResult, - css, - html, - nothing, -} from "lit"; -import { customElement, property, state } from "lit/decorators"; -import { HomeAssistant } from "../../types"; -import { haStyleDialog } from "../../resources/styles"; - -@customElement("ha-dialog-show-audio-message") -class HaDialogShowAudioMessage extends LitElement { - @property({ attribute: false }) public hass!: HomeAssistant; - - @state() private _currentMessage?: any; - - @state() private _errorMsg?: string; - - @state() private _loading: boolean = false; - - @state() private _opened: boolean = false; - - @state() private _blobUrl?: string; - - protected render(): TemplateResult { - return html` - - ${this._loading - ? html`` - : html`
- - - -
- ${ - this._currentMessage - ? html`
- ${this._currentMessage?.message} -
` - : nothing - } - ${ - this._errorMsg - ? html`
${this._errorMsg}
` - : nothing - } - ${ - this._blobUrl - ? html` ` - : nothing - } - `} -
- `; - } - - showDialog({ hass, message }) { - this.hass = hass; - this._errorMsg = undefined; - this._currentMessage = message; - this._opened = true; - const platform = message.platform; - if (platform.has_media) { - this._loading = true; - const url = `/api/mailbox/media/${platform.name}/${message.sha}`; - this.hass - .fetchWithAuth(url) - .then((response) => { - if (response.ok) { - return response.blob(); - } - return Promise.reject({ - status: response.status, - statusText: response.statusText, - }); - }) - .then((blob) => { - this._loading = false; - this._blobUrl = window.URL.createObjectURL(blob); - }) - .catch((err) => { - this._loading = false; - this._errorMsg = `Error loading audio: ${err.statusText}`; - }); - } else { - this._loading = false; - } - } - - private _openDeleteDialog() { - if (confirm(this.hass.localize("ui.panel.mailbox.delete_prompt"))) { - this._deleteSelected(); - } - } - - private _deleteSelected() { - const msg = this._currentMessage; - this.hass.callApi( - "DELETE", - `mailbox/delete/${msg.platform.name}/${msg.sha}` - ); - this._closeDialog(); - } - - private _closeDialog() { - const mp3 = this.shadowRoot!.querySelector("#mp3")! as any; - mp3.pause(); - this._currentMessage = undefined; - this._errorMsg = undefined; - this._loading = false; - this._opened = false; - } - - static get styles(): CSSResultGroup { - return [ - haStyleDialog, - css` - .error { - color: red; - } - p { - color: var(--secondary-text-color); - } - .icon { - text-align: var(--float-end); - } - `, - ]; - } -} - -declare global { - interface HTMLElementTagNameMap { - "ha-dialog-show-audio-message": HaDialogShowAudioMessage; - } -} diff --git a/src/panels/mailbox/ha-panel-mailbox.ts b/src/panels/mailbox/ha-panel-mailbox.ts deleted file mode 100644 index 250af9a83ab0..000000000000 --- a/src/panels/mailbox/ha-panel-mailbox.ts +++ /dev/null @@ -1,275 +0,0 @@ -import { - CSSResultGroup, - LitElement, - TemplateResult, - css, - html, - nothing, -} from "lit"; -import { customElement, property, state } from "lit/decorators"; -import "@material/mwc-button"; -import { formatDateTime } from "../../common/datetime/format_date_time"; -import "../../components/ha-card"; -import "../../components/ha-menu-button"; -import "../../components/ha-tabs"; -import "@polymer/paper-tabs/paper-tab"; -import { HomeAssistant } from "../../types"; -import { fireEvent } from "../../common/dom/fire_event"; -import { haStyle } from "../../resources/styles"; -import "../../components/ha-top-app-bar-fixed"; -import { formatDuration } from "../../common/datetime/format_duration"; - -let registeredDialog = false; - -interface MailboxMessage { - info: { - origtime: number; - callerid: string; - duration: string; - }; - text: string; - sha: string; -} - -@customElement("ha-panel-mailbox") -class HaPanelMailbox extends LitElement { - @property({ attribute: false }) public hass!: HomeAssistant; - - @property({ attribute: false }) public narrow!: boolean; - - @property({ attribute: false }) public platforms?: any[]; - - @state() private _messages?: any[]; - - @state() private _currentPlatform: number = 0; - - private _unsubEvents?; - - protected render(): TemplateResult { - return html` - - -
${this.hass.localize("panel.mailbox")}
- ${!this._areTabsHidden(this.platforms) - ? html`
- - ${this.platforms?.map( - (platform) => - html` - ${this._getPlatformName(platform)} - ` - )} - -
` - : ""} -
-
- - ${!this._messages?.length - ? html`
- ${this.hass.localize("ui.panel.mailbox.empty")} -
` - : nothing} - ${this._messages?.map( - (message) => - html` - - ${message.caller} - - ${formatDuration(this.hass.locale, { - seconds: message.duration, - })} - - - - ${message.timestamp} - - ${message.message} - - ` - )} -
-
- `; - } - - connectedCallback() { - super.connectedCallback(); - if (!registeredDialog) { - registeredDialog = true; - fireEvent(this, "register-dialog", { - dialogShowEvent: "show-audio-message-dialog", - dialogTag: "ha-dialog-show-audio-message", - dialogImport: () => import("./ha-dialog-show-audio-message"), - }); - } - this.hassChanged = this.hassChanged.bind(this); - this.hass.connection - .subscribeEvents(this.hassChanged, "mailbox_updated") - .then((unsub) => { - this._unsubEvents = unsub; - }); - this._computePlatforms().then((platforms) => { - this.platforms = platforms; - this.hassChanged(); - }); - } - - disconnectedCallback() { - super.disconnectedCallback(); - if (this._unsubEvents) this._unsubEvents(); - } - - hassChanged() { - if (!this._messages) { - this._messages = []; - } - this._getMessages().then((items) => { - this._messages = items; - }); - } - - private _openMP3Dialog(ev) { - const message: any = (ev.currentTarget! as any).message; - fireEvent(this, "show-audio-message-dialog", { - hass: this.hass, - message: message, - }); - } - - private _getMessages() { - const platform = this.platforms![this._currentPlatform]; - return this.hass - .callApi("GET", `mailbox/messages/${platform.name}`) - .then((values) => { - const platformItems: any[] = []; - const arrayLength = values.length; - for (let i = 0; i < arrayLength; i++) { - const datetime = formatDateTime( - new Date(values[i].info.origtime * 1000), - this.hass.locale, - this.hass.config - ); - platformItems.push({ - timestamp: datetime, - caller: values[i].info.callerid, - message: values[i].text, - sha: values[i].sha, - duration: values[i].info.duration, - platform: platform, - }); - } - return platformItems.sort((a, b) => b.timestamp - a.timestamp); - }); - } - - private _computePlatforms(): Promise { - return this.hass.callApi("GET", "mailbox/platforms"); - } - - private _handlePlatformSelected(ev) { - const newPlatform = ev.detail.selected; - if (newPlatform !== this._currentPlatform) { - this._currentPlatform = newPlatform; - this.hassChanged(); - } - } - - private _areTabsHidden(platforms) { - return !platforms || platforms.length < 2; - } - - private _getPlatformName(item) { - const entity = `mailbox.${item.name}`; - const stateObj = this.hass.states[entity.toLowerCase()]; - return stateObj.attributes.friendly_name; - } - - static get styles(): CSSResultGroup { - return [ - haStyle, - css` - :host { - -ms-user-select: initial; - -webkit-user-select: initial; - -moz-user-select: initial; - } - - .content { - padding: 16px; - max-width: 600px; - margin: 0 auto; - } - - ha-card { - overflow: hidden; - } - - ha-tabs { - margin-left: max(env(safe-area-inset-left), 24px); - margin-right: max(env(safe-area-inset-right), 24px); - margin-inline-start: max(env(safe-area-inset-left), 24px); - margin-inline-end: max(env(safe-area-inset-right), 24px); - --paper-tabs-selection-bar-color: #fff; - text-transform: uppercase; - } - - .empty { - text-align: center; - color: var(--secondary-text-color); - } - - .header { - @apply --paper-font-title; - } - - .row { - display: flex; - justify-content: space-between; - } - - @media all and (max-width: 450px) { - .content { - width: auto; - padding: 0; - } - } - - .tip { - color: var(--secondary-text-color); - font-size: 14px; - } - .date { - color: var(--primary-text-color); - } - `, - ]; - } -} - -declare global { - interface HTMLElementTagNameMap { - "ha-panel-mailbox": HaPanelMailbox; - } -} - -declare global { - // for fire event - interface HASSDomEvents { - "show-audio-message-dialog": { - hass: HomeAssistant; - message: string; - }; - } -} diff --git a/src/translations/en.json b/src/translations/en.json index 7514ba4abfcc..7d05b89322a2 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -7,7 +7,6 @@ "map": "Map", "logbook": "Logbook", "history": "History", - "mailbox": "Mailbox", "todo": "To-do lists", "developer_tools": "Developer tools", "media_browser": "Media", @@ -6355,12 +6354,6 @@ }, "reload_lovelace": "Reload UI" }, - "mailbox": { - "empty": "You do not have any messages", - "playback_title": "Message playback", - "delete_prompt": "Delete this message?", - "delete_button": "Delete" - }, "media-browser": { "error": { "player_not_exist": "Media player {name} does not exist"