-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore Bluetooth configuration panel (#23877)
* Restore Bluetooth configuration panel * cleanup copypasta * Apply suggestions from code review * Update src/panels/config/integrations/integration-panels/bluetooth/bluetooth-config-dashboard-router.ts * preen * trim down updatePageEl
- Loading branch information
Showing
6 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...els/config/integrations/integration-panels/bluetooth/bluetooth-config-dashboard-router.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { customElement, property } from "lit/decorators"; | ||
import type { RouterOptions } from "../../../../../layouts/hass-router-page"; | ||
import { HassRouterPage } from "../../../../../layouts/hass-router-page"; | ||
import type { HomeAssistant } from "../../../../../types"; | ||
|
||
@customElement("bluetooth-config-dashboard-router") | ||
class BluetoothConfigDashboardRouter extends HassRouterPage { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property({ attribute: "is-wide", type: Boolean }) public isWide = false; | ||
|
||
@property({ type: Boolean }) public narrow = false; | ||
|
||
private _configEntry = new URLSearchParams(window.location.search).get( | ||
"config_entry" | ||
); | ||
|
||
protected routerOptions: RouterOptions = { | ||
defaultPage: "dashboard", | ||
showLoading: true, | ||
routes: { | ||
dashboard: { | ||
tag: "bluetooth-config-dashboard", | ||
load: () => import("./bluetooth-config-dashboard"), | ||
}, | ||
"advertisement-monitor": { | ||
tag: "bluetooth-advertisement-monitor", | ||
load: () => import("./bluetooth-advertisement-monitor"), | ||
}, | ||
}, | ||
}; | ||
|
||
protected updatePageEl(el): void { | ||
el.route = this.routeTail; | ||
el.hass = this.hass; | ||
el.isWide = this.isWide; | ||
el.narrow = this.narrow; | ||
el.configEntryId = this._configEntry; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"bluetooth-config-dashboard-router": BluetoothConfigDashboardRouter; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/panels/config/integrations/integration-panels/bluetooth/bluetooth-config-dashboard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import "@material/mwc-button"; | ||
import type { CSSResultGroup, TemplateResult } from "lit"; | ||
import { css, html, LitElement } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import "../../../../../components/ha-card"; | ||
import "../../../../../components/ha-code-editor"; | ||
import "../../../../../components/ha-formfield"; | ||
import "../../../../../components/ha-switch"; | ||
import { getConfigEntries } from "../../../../../data/config_entries"; | ||
import { showOptionsFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-options-flow"; | ||
import "../../../../../layouts/hass-subpage"; | ||
import { haStyle } from "../../../../../resources/styles"; | ||
import type { HomeAssistant } from "../../../../../types"; | ||
|
||
@customElement("bluetooth-config-dashboard") | ||
export class BluetoothConfigDashboard extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property({ type: Boolean }) public narrow = false; | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<hass-subpage .narrow=${this.narrow} .hass=${this.hass}> | ||
<div class="content"> | ||
<ha-card | ||
.header=${this.hass.localize( | ||
"ui.panel.config.bluetooth.settings_title" | ||
)} | ||
> | ||
<div class="card-actions"> | ||
<mwc-button @click=${this._openOptionFlow} | ||
>${this.hass.localize( | ||
"ui.panel.config.bluetooth.option_flow" | ||
)}</mwc-button | ||
> | ||
</div> | ||
</ha-card> | ||
<ha-card | ||
.header=${this.hass.localize( | ||
"ui.panel.config.bluetooth.advertisement_monitor" | ||
)} | ||
> | ||
<div class="card-content"> | ||
<p> | ||
${this.hass.localize( | ||
"ui.panel.config.bluetooth.advertisement_monitor_details" | ||
)} | ||
</p> | ||
</div> | ||
<div class="card-actions"> | ||
<a href="/config/bluetooth/advertisement-monitor" | ||
><mwc-button> | ||
${this.hass.localize( | ||
"ui.panel.config.bluetooth.advertisement_monitor" | ||
)} | ||
</mwc-button></a | ||
> | ||
</div> | ||
</ha-card> | ||
</div> | ||
</hass-subpage> | ||
`; | ||
} | ||
|
||
private async _openOptionFlow() { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
if (!searchParams.has("config_entry")) { | ||
return; | ||
} | ||
const configEntryId = searchParams.get("config_entry") as string; | ||
const configEntries = await getConfigEntries(this.hass, { | ||
domain: "bluetooth", | ||
}); | ||
const configEntry = configEntries.find( | ||
(entry) => entry.entry_id === configEntryId | ||
); | ||
showOptionsFlowDialog(this, configEntry!); | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return [ | ||
haStyle, | ||
css` | ||
:host { | ||
-ms-user-select: initial; | ||
-webkit-user-select: initial; | ||
-moz-user-select: initial; | ||
} | ||
.content { | ||
padding: 24px 0 32px; | ||
max-width: 600px; | ||
margin: 0 auto; | ||
direction: ltr; | ||
} | ||
ha-card:first-child { | ||
margin-bottom: 16px; | ||
} | ||
`, | ||
]; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"bluetooth-config-dashboard": BluetoothConfigDashboard; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters