-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from davet2001/add-gui-card-editors
Add UI card editors
- Loading branch information
Showing
36 changed files
with
5,594 additions
and
281 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -14,17 +14,21 @@ | |
"url": "https://github.com/davet2001/homeassistant-energy-sankey-card" | ||
}, | ||
"dependencies": { | ||
"@davethompson/elec-sankey": "^1.0.0", | ||
"@material/mwc-icon-button": "^0.27.0", | ||
"@material/mwc-list": "^0.27.0", | ||
"@material/mwc-textfield": "^0.27.0", | ||
"@mdi/js": "^7.4.47", | ||
"@vaadin/combo-box": "24.5.3", | ||
"@vaadin/vaadin-themable-mixin": "24.5.3", | ||
"color-name": "^2.0.0", | ||
"date-fns": "^4.1.0", | ||
"date-fns-tz": "^3.2.0", | ||
"home-assistant-js-websocket": "^9.4.0", | ||
"lit": "^2.8.0", | ||
"memoize-one": "^6.0.0" | ||
"memoize-one": "^6.0.0", | ||
"sortablejs": "^1.15.6" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-alias": "^5.1.1", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^15.3.0", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
|
@@ -34,5 +38,17 @@ | |
"rollup-plugin-serve": "^2.0.3", | ||
"tslib": "^2.8.0", | ||
"typescript": "^5.5.3" | ||
}, | ||
"overrides": { | ||
"@lit/reactive-element": "1.6.3" | ||
}, | ||
"_comment": "Polymer 3.2 contained a bug, fixed in https://github.com/Polymer/polymer/pull/5569, add as patch", | ||
"resolutions": { | ||
"@polymer/polymer": "patch:@polymer/[email protected]#./.yarn/patches/@polymer/polymer/pr-5569.patch", | ||
"@material/mwc-button@^0.25.3": "^0.27.0", | ||
"lit": "2.8.0", | ||
"lit-html": "2.8.0", | ||
"@fullcalendar/daygrid": "6.1.15", | ||
"globals": "15.12.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const PREFIX_NAME = 'energy-sankey'; | ||
|
||
export const POWER_CARD_NAME = `${PREFIX_NAME}-power-flow-card`; | ||
export const POWER_CARD_EDITOR_NAME = `${POWER_CARD_NAME}-editor`; | ||
export const ENERGY_CARD_NAME = `${PREFIX_NAME}-energy-elec-flow-card`; | ||
export const ENERGY_CARD_EDITOR_NAME = `${ENERGY_CARD_NAME}-editor`; |
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,65 @@ | ||
import { customElement, property, state } from "lit/decorators"; | ||
|
||
import { LovelaceCardEditor } from "./ha/panels/lovelace/types"; | ||
import { EnergyElecFlowCardConfig, PowerFlowCardConfig } from "./types"; | ||
import { html, LitElement, nothing } from "lit"; | ||
import { HomeAssistant, LocalizeFunc } from "./ha/types"; | ||
import { HaFormSchema } from "./utils/form/ha-form"; | ||
import "./ha/panels/lovelace/editor/hui-entities-card-row-editor"; | ||
import { fireEvent } from "./ha/common/dom/fire_event"; | ||
|
||
import { ENERGY_CARD_EDITOR_NAME } from "./const"; | ||
|
||
const schema = [ | ||
{ name: "title", selector: { text: {} } }, | ||
]; | ||
|
||
@customElement(ENERGY_CARD_EDITOR_NAME) | ||
export class EnergyFlowCardEditor extends LitElement implements LovelaceCardEditor { | ||
|
||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@state() private _config?: EnergyElecFlowCardConfig; | ||
|
||
public setConfig(config: EnergyElecFlowCardConfig): void { | ||
this._config = config; | ||
} | ||
|
||
private _computeLabel = (schema: HaFormSchema) => { | ||
switch (schema.name) { | ||
case "title": return "Title"; | ||
} | ||
console.error("Error name key missing for '" + schema.name + "'") | ||
return "" | ||
}; | ||
|
||
protected render() { | ||
if (!this.hass || !this._config) { | ||
return nothing; | ||
} | ||
|
||
const data = { ...this._config } as any; | ||
return html` | ||
<ha-form | ||
.hass=${this.hass} | ||
.data=${data} | ||
.schema=${schema} | ||
.computeLabel=${this._computeLabel} | ||
@value-changed=${this._valueChanged} | ||
></ha-form> | ||
<ha-alert | ||
alert-type="info" | ||
.title="Note" | ||
> | ||
Energy flow entities are configured in the | ||
<a href="/config/energy">Energy Dashboard Config</a>. | ||
They cannot be modified via the card configuration. | ||
</ha-alert> | ||
`; | ||
} | ||
|
||
private _valueChanged(ev: CustomEvent): void { | ||
const config = ev.detail.value; | ||
fireEvent(this, "config-changed", { config }); | ||
} | ||
} |
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,13 @@ | ||
import { MAIN_WINDOW_NAME } from "../../data/main_window"; | ||
|
||
export const mainWindow = (() => { | ||
try { | ||
return window.name === MAIN_WINDOW_NAME | ||
? window | ||
: parent.name === MAIN_WINDOW_NAME | ||
? parent | ||
: top!; | ||
} catch { | ||
return window; | ||
} | ||
})(); |
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,47 @@ | ||
import memoizeOne from "memoize-one"; | ||
|
||
const collator = memoizeOne( | ||
(language: string | undefined) => new Intl.Collator(language) | ||
); | ||
|
||
const caseInsensitiveCollator = memoizeOne( | ||
(language: string | undefined) => | ||
new Intl.Collator(language, { sensitivity: "accent" }) | ||
); | ||
|
||
const fallbackStringCompare = (a: string, b: string) => { | ||
if (a < b) { | ||
return -1; | ||
} | ||
if (a > b) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
export const stringCompare = ( | ||
a: string, | ||
b: string, | ||
language: string | undefined = undefined | ||
) => { | ||
// @ts-ignore | ||
if (Intl?.Collator) { | ||
return collator(language).compare(a, b); | ||
} | ||
|
||
return fallbackStringCompare(a, b); | ||
}; | ||
|
||
export const caseInsensitiveStringCompare = ( | ||
a: string, | ||
b: string, | ||
language: string | undefined = undefined | ||
) => { | ||
// @ts-ignore | ||
if (Intl?.Collator) { | ||
return caseInsensitiveCollator(language).compare(a, b); | ||
} | ||
|
||
return fallbackStringCompare(a.toLowerCase(), b.toLowerCase()); | ||
}; |
Oops, something went wrong.