-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce95e5c
commit 26a290e
Showing
73 changed files
with
9,796 additions
and
6,732 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-typescript", | ||
{ | ||
"optimizeConstEnums": true | ||
} | ||
] | ||
] | ||
} |
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,2 @@ | ||
> 0.25% | ||
not dead |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
dist |
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.
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
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,24 @@ | ||
export default function (userOptions = {}) { | ||
// Files need to be absolute paths. | ||
// This only works if the file has no exports | ||
// and only is imported for its side effects | ||
const files = userOptions.files || []; | ||
|
||
if (files.length === 0) { | ||
return { | ||
name: "ignore", | ||
}; | ||
} | ||
|
||
return { | ||
name: "ignore", | ||
|
||
load(id) { | ||
return files.some((toIgnorePath) => id.startsWith(toIgnorePath)) | ||
? { | ||
code: "", | ||
} | ||
: null; | ||
}, | ||
}; | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -1,42 +1,74 @@ | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import babel from 'rollup-plugin-babel'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import serve from 'rollup-plugin-serve'; | ||
import json from '@rollup/plugin-json'; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import nodeResolve from "@rollup/plugin-node-resolve"; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import babel from "@rollup/plugin-babel"; | ||
import json from "@rollup/plugin-json"; | ||
import { terser } from "rollup-plugin-terser"; | ||
import serve from "rollup-plugin-serve"; | ||
import ignore from "./rollup-ignore-plugin.js"; | ||
|
||
const IGNORED_FILES = [ | ||
|
||
]; | ||
|
||
const dev = process.env.ROLLUP_WATCH; | ||
|
||
const serveopts = { | ||
contentBase: ['./dist'], | ||
host: '0.0.0.0', | ||
port: 5000, | ||
allowCrossOrigin: true, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
}, | ||
const serveOptions = { | ||
contentBase: ["./dist"], | ||
host: "0.0.0.0", | ||
port: 4000, | ||
allowCrossOrigin: true, | ||
headers: { | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
}; | ||
|
||
const plugins = [ | ||
nodeResolve({}), | ||
commonjs(), | ||
typescript(), | ||
json(), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
}), | ||
dev && serve(serveopts), | ||
!dev && terser(), | ||
ignore({ | ||
files: IGNORED_FILES.map((file) => require.resolve(file)), | ||
}), | ||
typescript({ | ||
declaration: false, | ||
}), | ||
nodeResolve(), | ||
json(), | ||
commonjs(), | ||
babel({ | ||
exclude: "node_modules/**", | ||
babelHelpers: "bundled", | ||
}), | ||
...(dev ? [serve(serveOptions)] : [terser({ | ||
warnings: true, | ||
output: { | ||
comments: function (node, comment) { | ||
var text = comment.value; | ||
var type = comment.type; | ||
if (type == "comment2") { | ||
// multiline comment | ||
return /@preserve|@license|@cc_on/i.test(text); | ||
} | ||
}, | ||
}, | ||
})]), | ||
]; | ||
|
||
export default [ | ||
{ | ||
input: 'src/better-thermostat-ui-card.ts', | ||
output: { | ||
dir: 'dist', | ||
format: 'es', | ||
{ | ||
input: "src/better-thermostat-ui.ts", | ||
output: { | ||
inlineDynamicImports: true, | ||
file: "dist/better-thermostat-ui-card.js", | ||
format: "es", | ||
}, | ||
plugins, | ||
moduleContext: (id) => { | ||
const thisAsWindowForModules = [ | ||
"node_modules/@formatjs/intl-utils/lib/src/diff.js", | ||
"node_modules/@formatjs/intl-utils/lib/src/resolve-locale.js", | ||
]; | ||
if (thisAsWindowForModules.some((id_) => id.trimRight().endsWith(id_))) { | ||
return "window"; | ||
} | ||
}, | ||
}, | ||
plugins: [...plugins], | ||
}, | ||
]; |
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 { LitElement } from 'lit'; | ||
import { html, TemplateResult } from "lit"; | ||
import { customElement, property, state } from "lit/decorators.js"; | ||
import memoizeOne from "memoize-one"; | ||
import { assert } from "superstruct"; | ||
import { fireEvent, LocalizeFunc, LovelaceCardEditor, atLeastHaVersion, HomeAssistant, computeDomain } from "./ha"; | ||
import setupCustomlocalize from "./localize/localize"; | ||
import { ClimateCardConfig, climateCardConfigStruct, HVAC_MODES } from "./climate-card-config"; | ||
import { HassEntity } from "home-assistant-js-websocket"; | ||
|
||
const GENERIC_LABELS = [ | ||
"icon_color", | ||
"layout", | ||
"fill_container", | ||
"primary_info", | ||
"secondary_info", | ||
"icon_type", | ||
"content_info", | ||
"use_entity_picture", | ||
"collapsible_controls", | ||
"icon_animation", | ||
]; | ||
|
||
const loadHaComponents = (version: string) => { | ||
if ( | ||
!customElements.get("ha-form") || | ||
(!customElements.get("hui-action-editor") && !atLeastHaVersion(version, 2022, 11)) | ||
) { | ||
(customElements.get("hui-button-card") as any)?.getConfigElement(); | ||
} | ||
if (!customElements.get("ha-entity-picker")) { | ||
(customElements.get("hui-entities-card") as any)?.getConfigElement(); | ||
} | ||
}; | ||
|
||
const CLIMATE_LABELS = ["eco_temperature", "disable_window", "disable_summer", "disable_eco", "disable_heat", "disable_off", "set_current_as_main"] as string[]; | ||
|
||
const computeSchema = memoizeOne( | ||
(): any[] => [ | ||
{ name: "entity", selector: { entity: { domain: ["climate"] } } }, | ||
{ name: "name", selector: { text: {} } }, | ||
{ name: "eco_temperature", selector: { number: {placeholder: 20, min: 5, max: 45} } }, | ||
{ | ||
type: "grid", | ||
name: "", | ||
schema: [ | ||
{ name: "disable_window", selector: { boolean: {} } }, | ||
{ name: "disable_summer", selector: { boolean: {} } }, | ||
{ name: "disable_eco", selector: { boolean: {} } }, | ||
{ name: "disable_heat", selector: { boolean: {} } }, | ||
{ name: "disable_off", selector: { boolean: {} } }, | ||
{ name: "set_current_as_main", selector: { boolean: {} } }, | ||
], | ||
}, | ||
] | ||
); | ||
|
||
@customElement("better-thermostat-ui-card-editor") | ||
export class ClimateCardEditor extends LitElement implements LovelaceCardEditor { | ||
@state() private _config?: ClimateCardConfig; | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
void loadHaComponents(this.hass.connection.haVersion); | ||
} | ||
|
||
public setConfig(config: ClimateCardConfig): void { | ||
assert(config, climateCardConfigStruct); | ||
this._config = config; | ||
} | ||
|
||
private _computeLabel = (schema: any) => { | ||
const customLocalize = setupCustomlocalize(this.hass!); | ||
|
||
if (GENERIC_LABELS.includes(schema.name)) { | ||
return customLocalize(`editor.card.generic.${schema.name}`); | ||
} | ||
if (CLIMATE_LABELS.includes(schema.name)) { | ||
return customLocalize(`editor.card.climate.${schema.name}`); | ||
} | ||
return this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); | ||
}; | ||
|
||
protected render(): TemplateResult { | ||
if (!this.hass || !this._config) { | ||
return html``; | ||
} | ||
|
||
|
||
const schema = computeSchema(); | ||
|
||
return html` | ||
<ha-form | ||
.hass=${this.hass} | ||
.data=${this._config} | ||
.schema=${schema} | ||
.computeLabel=${this._computeLabel} | ||
@value-changed=${this._valueChanged} | ||
></ha-form> | ||
`; | ||
} | ||
|
||
private _valueChanged(ev: CustomEvent): void { | ||
fireEvent(this, "config-changed", { config: ev.detail.value }); | ||
} | ||
} |
Oops, something went wrong.