Skip to content

Commit

Permalink
[TASK] update
Browse files Browse the repository at this point in the history
  • Loading branch information
KartoffelToby committed Nov 24, 2022
1 parent ce95e5c commit 26a290e
Show file tree
Hide file tree
Showing 73 changed files with 9,796 additions and 6,732 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-typescript",
{
"optimizeConstEnums": true
}
]
]
}
2 changes: 2 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> 0.25%
not dead
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version - 0.9.0](https://img.shields.io/badge/Version-0.9.0-009688?style=for-the-badge)](https://github.com/KartoffelToby/better-thermostat-ui-card)
[![Version - 1.0.0](https://img.shields.io/badge/Version-1.0.0-009688?style=for-the-badge)](https://github.com/KartoffelToby/better-thermostat-ui-card)
[![Discord](https://img.shields.io/discord/925725316540923914.svg?style=for-the-badge)](https://discord.gg/9BUegWTG3K)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg?style=for-the-badge)](https://github.com/hacs/integration)

Expand Down
1,013 changes: 403 additions & 610 deletions dist/better-thermostat-ui-card.js

Large diffs are not rendered by default.

9,384 changes: 5,253 additions & 4,131 deletions package-lock.json

Large diffs are not rendered by default.

63 changes: 32 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "better-thermostat-ui",
"version": "0.9.0",
"version": "1.0.0",
"description": "Lovelace better-thermostat-ui",
"keywords": [
"home-assistant",
Expand All @@ -10,48 +10,49 @@
"lovelace",
"custom-cards",
"better-thermostat",
"better_thermostat",
"ai_thermostat"
"better_thermostat"
],
"module": "better-thermostat-ui-card.js",
"repository": "",
"author": "",
"repository": "https://github.com/KartoffelToby/better-thermostat-ui-card",
"author": "Tobias Haber",
"type": "module",
"scripts": {
"start": "rollup -c --watch",
"build": "rollup -c",
"format": "prettier --write .",
"start:hass": "docker run --rm -p8123:8123 -v ${PWD}/.hass_dev:/config homeassistant/home-assistant:beta",
"start:hass-cmd": "docker run --rm -p8123:8123 -v %cd%/.hass_dev:/config homeassistant/home-assistant:beta"
},
"dependencies": {
"@juggle/resize-observer": "^3.4.0",
"@babel/preset-env": "^7.20.2",
"@mdi/js": "^7.0.96",
"@svgdotjs/svg.js": "^3.1.2",
"@types/gsap": "^3.0.0",
"animejs": "^3.2.1",
"custom-card-helpers": "^1.9.0",
"gsap": "^3.11.3",
"home-assistant-js-websocket": "^8.0.0",
"lit": "^2.4.0"
"lit": "^2.4.1",
"memoize-one": "^6.0.0"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.19.3",
"@rollup/plugin-json": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"eslint": "^8.24.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"@babel/core": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@material/mwc-ripple": "^0.27.0",
"@material/tab-bar": "^14.0.0",
"@rollup/plugin-babel": "^6.0.2",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@types/color": "^3.0.3",
"@types/hammerjs": "^2.0.41",
"@types/node": "^18.11.9",
"eslint": "^8.28.0",
"prettier": "^2.7.1",
"rollup": "^2.79.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup": "^3.4.0",
"rollup-plugin-serve": "^2.0.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-uglify": "^6.0.4",
"typescript": "^4.8.4"
},
"scripts": {
"start": "rollup -c rollup.config.dev.js --watch",
"build": "npm run rollup",
"lint": "eslint src/*.ts",
"rollup": "rollup -c"
"typescript": "^4.9.3"
}
}
24 changes: 24 additions & 0 deletions rollup-ignore-plugin.js
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;
},
};
}
32 changes: 0 additions & 32 deletions rollup.config.dev.js

This file was deleted.

94 changes: 63 additions & 31 deletions rollup.config.js
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],
},
];
107 changes: 107 additions & 0 deletions src/better-thermostat-ui-card-editor.ts
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 });
}
}
Loading

0 comments on commit 26a290e

Please sign in to comment.