mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-27 01:59:26 +00:00
Compare commits
1 Commits
20221102.1
...
fix-entity
Author | SHA1 | Date | |
---|---|---|---|
![]() |
be6fef1824 |
4
.github/workflows/demo.yaml
vendored
4
.github/workflows/demo.yaml
vendored
@@ -27,7 +27,9 @@ jobs:
|
|||||||
- name: Build Demo
|
- name: Build Demo
|
||||||
run: ./node_modules/.bin/gulp build-demo
|
run: ./node_modules/.bin/gulp build-demo
|
||||||
- name: Deploy to Netlify
|
- name: Deploy to Netlify
|
||||||
run: npx netlify-cli deploy --dir=demo/dist --prod
|
uses: netlify/actions/cli@master
|
||||||
env:
|
env:
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
|
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
|
||||||
|
with:
|
||||||
|
args: deploy --dir=demo/dist --prod
|
||||||
|
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -75,7 +75,7 @@ jobs:
|
|||||||
echo "home-assistant-frontend==$version" > ./requirements.txt
|
echo "home-assistant-frontend==$version" > ./requirements.txt
|
||||||
|
|
||||||
- name: Build wheels
|
- name: Build wheels
|
||||||
uses: home-assistant/wheels@2022.10.1
|
uses: home-assistant/wheels@2022.06.7
|
||||||
with:
|
with:
|
||||||
abi: cp310
|
abi: cp310
|
||||||
tag: musllinux_1_2
|
tag: musllinux_1_2
|
||||||
|
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 90 days stale policy
|
- name: 90 days stale policy
|
||||||
uses: actions/stale@v6.0.1
|
uses: actions/stale@v5.1.1
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-stale: 90
|
days-before-stale: 90
|
||||||
|
785
.yarn/releases/yarn-3.2.0.cjs
vendored
Executable file
785
.yarn/releases/yarn-3.2.0.cjs
vendored
Executable file
File diff suppressed because one or more lines are too long
783
.yarn/releases/yarn-3.2.3.cjs
vendored
783
.yarn/releases/yarn-3.2.3.cjs
vendored
File diff suppressed because one or more lines are too long
@@ -6,4 +6,4 @@ plugins:
|
|||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
spec: "@yarnpkg/plugin-interactive-tools"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-3.2.3.cjs
|
yarnPath: .yarn/releases/yarn-3.2.0.cjs
|
||||||
|
@@ -1,12 +1,17 @@
|
|||||||
|
const del = require("del");
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const mapStream = require("map-stream");
|
const mapStream = require("map-stream");
|
||||||
|
|
||||||
const inDirFrontend = "translations/frontend";
|
const inDirFrontend = "translations/frontend";
|
||||||
const inDirBackend = "translations/backend";
|
const inDirBackend = "translations/backend";
|
||||||
|
const downloadDir = "translations/downloads";
|
||||||
const srcMeta = "src/translations/translationMetadata.json";
|
const srcMeta = "src/translations/translationMetadata.json";
|
||||||
|
|
||||||
const encoding = "utf8";
|
const encoding = "utf8";
|
||||||
|
|
||||||
|
const tasks = [];
|
||||||
|
|
||||||
function hasHtml(data) {
|
function hasHtml(data) {
|
||||||
return /<[a-z][\s\S]*>/i.test(data);
|
return /<[a-z][\s\S]*>/i.test(data);
|
||||||
}
|
}
|
||||||
@@ -41,12 +46,20 @@ function checkHtml() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend translations do not currently pass HTML check so are excluded here for now
|
let taskName = "clean-downloaded-translations";
|
||||||
gulp.task("check-translations-html", function () {
|
gulp.task(taskName, function () {
|
||||||
return gulp.src([`${inDirFrontend}/*.json`]).pipe(checkHtml());
|
return del([`${downloadDir}/**`]);
|
||||||
});
|
});
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
gulp.task("check-all-files-exist", function () {
|
taskName = "check-translations-html";
|
||||||
|
gulp.task(taskName, function () {
|
||||||
|
return gulp.src(`${downloadDir}/*.json`).pipe(checkHtml());
|
||||||
|
});
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
taskName = "check-all-files-exist";
|
||||||
|
gulp.task(taskName, function () {
|
||||||
const file = fs.readFileSync(srcMeta, { encoding });
|
const file = fs.readFileSync(srcMeta, { encoding });
|
||||||
const meta = JSON.parse(file);
|
const meta = JSON.parse(file);
|
||||||
Object.keys(meta).forEach((lang) => {
|
Object.keys(meta).forEach((lang) => {
|
||||||
@@ -59,8 +72,24 @@ gulp.task("check-all-files-exist", function () {
|
|||||||
});
|
});
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
taskName = "move-downloaded-translations";
|
||||||
|
gulp.task(taskName, function () {
|
||||||
|
return gulp.src(`${downloadDir}/*.json`).pipe(gulp.dest(inDirFrontend));
|
||||||
|
});
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
taskName = "check-downloaded-translations";
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"check-downloaded-translations",
|
taskName,
|
||||||
gulp.series("check-translations-html", "check-all-files-exist")
|
gulp.series(
|
||||||
|
"check-translations-html",
|
||||||
|
"move-downloaded-translations",
|
||||||
|
"check-all-files-exist",
|
||||||
|
"clean-downloaded-translations"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
module.exports = tasks;
|
||||||
|
@@ -508,7 +508,7 @@ export const demoEntitiesArsaboo: DemoConfig["entities"] = (localize) =>
|
|||||||
origin_addresses: ["XYZ"],
|
origin_addresses: ["XYZ"],
|
||||||
status: "OK",
|
status: "OK",
|
||||||
mode: "driving",
|
mode: "driving",
|
||||||
units: "us_customary",
|
units: "imperial",
|
||||||
duration_in_traffic: "41 mins",
|
duration_in_traffic: "41 mins",
|
||||||
duration: "44 mins",
|
duration: "44 mins",
|
||||||
distance: "34.3 mi",
|
distance: "34.3 mi",
|
||||||
@@ -527,7 +527,7 @@ export const demoEntitiesArsaboo: DemoConfig["entities"] = (localize) =>
|
|||||||
origin_addresses: ["XYZ"],
|
origin_addresses: ["XYZ"],
|
||||||
status: "OK",
|
status: "OK",
|
||||||
mode: "driving",
|
mode: "driving",
|
||||||
units: "us_customary",
|
units: "imperial",
|
||||||
duration_in_traffic: "37 mins",
|
duration_in_traffic: "37 mins",
|
||||||
duration: "37 mins",
|
duration: "37 mins",
|
||||||
distance: "30.2 mi",
|
distance: "30.2 mi",
|
||||||
|
@@ -1196,7 +1196,7 @@ export const demoLovelaceJimpower: DemoConfig["lovelace"] = () => ({
|
|||||||
left: "15%",
|
left: "15%",
|
||||||
},
|
},
|
||||||
type: "state-icon",
|
type: "state-icon",
|
||||||
entity: "binary_sensor.water_leak_sensor_158d00026e26dc",
|
entity: "binary_sensor.water_leak_sensor_158d0002338651",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prefix: "Kitchen: ",
|
prefix: "Kitchen: ",
|
||||||
@@ -1206,7 +1206,7 @@ export const demoLovelaceJimpower: DemoConfig["lovelace"] = () => ({
|
|||||||
top: "89%",
|
top: "89%",
|
||||||
left: "32%",
|
left: "32%",
|
||||||
},
|
},
|
||||||
entity: "binary_sensor.water_leak_sensor_158d00026e26dc",
|
entity: "binary_sensor.water_leak_sensor_158d0002338651",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
style: {
|
style: {
|
||||||
@@ -1215,7 +1215,7 @@ export const demoLovelaceJimpower: DemoConfig["lovelace"] = () => ({
|
|||||||
left: "60%",
|
left: "60%",
|
||||||
},
|
},
|
||||||
type: "state-icon",
|
type: "state-icon",
|
||||||
entity: "binary_sensor.water_leak_sensor_158d0002338651",
|
entity: "binary_sensor.water_leak_sensor_158d00026e26dc",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prefix: "Bathroom: ",
|
prefix: "Bathroom: ",
|
||||||
@@ -1225,7 +1225,7 @@ export const demoLovelaceJimpower: DemoConfig["lovelace"] = () => ({
|
|||||||
top: "89%",
|
top: "89%",
|
||||||
left: "77%",
|
left: "77%",
|
||||||
},
|
},
|
||||||
entity: "binary_sensor.water_leak_sensor_158d0002338651",
|
entity: "binary_sensor.water_leak_sensor_158d00026e26dc",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
type: "picture-elements",
|
type: "picture-elements",
|
||||||
|
@@ -20,7 +20,6 @@ import { mockHistory } from "./stubs/history";
|
|||||||
import { mockLovelace } from "./stubs/lovelace";
|
import { mockLovelace } from "./stubs/lovelace";
|
||||||
import { mockMediaPlayer } from "./stubs/media_player";
|
import { mockMediaPlayer } from "./stubs/media_player";
|
||||||
import { mockPersistentNotification } from "./stubs/persistent_notification";
|
import { mockPersistentNotification } from "./stubs/persistent_notification";
|
||||||
import { mockRecorder } from "./stubs/recorder";
|
|
||||||
import { mockShoppingList } from "./stubs/shopping_list";
|
import { mockShoppingList } from "./stubs/shopping_list";
|
||||||
import { mockSystemLog } from "./stubs/system_log";
|
import { mockSystemLog } from "./stubs/system_log";
|
||||||
import { mockTemplate } from "./stubs/template";
|
import { mockTemplate } from "./stubs/template";
|
||||||
@@ -46,7 +45,6 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
mockAuth(hass);
|
mockAuth(hass);
|
||||||
mockTranslations(hass);
|
mockTranslations(hass);
|
||||||
mockHistory(hass);
|
mockHistory(hass);
|
||||||
mockRecorder(hass);
|
|
||||||
mockShoppingList(hass);
|
mockShoppingList(hass);
|
||||||
mockSystemLog(hass);
|
mockSystemLog(hass);
|
||||||
mockTemplate(hass);
|
mockTemplate(hass);
|
||||||
@@ -63,14 +61,12 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
area_id: null,
|
area_id: null,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
entity_id: "sensor.co2_intensity",
|
entity_id: "sensor.co2_intensity",
|
||||||
id: "sensor.co2_intensity",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "co2signal",
|
platform: "co2signal",
|
||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "co2_intensity",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
config_entry_id: "co2signal",
|
config_entry_id: "co2signal",
|
||||||
@@ -78,14 +74,12 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
area_id: null,
|
area_id: null,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
entity_id: "sensor.grid_fossil_fuel_percentage",
|
entity_id: "sensor.grid_fossil_fuel_percentage",
|
||||||
id: "sensor.co2_intensity",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "co2signal",
|
platform: "co2signal",
|
||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "grid_fossil_fuel_percentage",
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -122,9 +116,3 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-demo", HaDemo);
|
customElements.define("ha-demo", HaDemo);
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-demo": HaDemo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,16 +1,9 @@
|
|||||||
import { format, startOfToday, startOfTomorrow } from "date-fns/esm";
|
import { format, startOfToday, startOfTomorrow } from "date-fns/esm";
|
||||||
import {
|
import { EnergySolarForecasts } from "../../../src/data/energy";
|
||||||
EnergyInfo,
|
|
||||||
EnergyPreferences,
|
|
||||||
EnergySolarForecasts,
|
|
||||||
FossilEnergyConsumption,
|
|
||||||
} from "../../../src/data/energy";
|
|
||||||
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
export const mockEnergy = (hass: MockHomeAssistant) => {
|
export const mockEnergy = (hass: MockHomeAssistant) => {
|
||||||
hass.mockWS(
|
hass.mockWS("energy/get_prefs", () => ({
|
||||||
"energy/get_prefs",
|
|
||||||
(): EnergyPreferences => ({
|
|
||||||
energy_sources: [
|
energy_sources: [
|
||||||
{
|
{
|
||||||
type: "grid",
|
type: "grid",
|
||||||
@@ -18,12 +11,14 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
{
|
{
|
||||||
stat_energy_from: "sensor.energy_consumption_tarif_1",
|
stat_energy_from: "sensor.energy_consumption_tarif_1",
|
||||||
stat_cost: "sensor.energy_consumption_tarif_1_cost",
|
stat_cost: "sensor.energy_consumption_tarif_1_cost",
|
||||||
|
entity_energy_from: "sensor.energy_consumption_tarif_1",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_energy_from: "sensor.energy_consumption_tarif_2",
|
stat_energy_from: "sensor.energy_consumption_tarif_2",
|
||||||
stat_cost: "sensor.energy_consumption_tarif_2_cost",
|
stat_cost: "sensor.energy_consumption_tarif_2_cost",
|
||||||
|
entity_energy_from: "sensor.energy_consumption_tarif_2",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
@@ -31,15 +26,15 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
flow_to: [
|
flow_to: [
|
||||||
{
|
{
|
||||||
stat_energy_to: "sensor.energy_production_tarif_1",
|
stat_energy_to: "sensor.energy_production_tarif_1",
|
||||||
stat_compensation:
|
stat_compensation: "sensor.energy_production_tarif_1_compensation",
|
||||||
"sensor.energy_production_tarif_1_compensation",
|
entity_energy_to: "sensor.energy_production_tarif_1",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_energy_to: "sensor.energy_production_tarif_2",
|
stat_energy_to: "sensor.energy_production_tarif_2",
|
||||||
stat_compensation:
|
stat_compensation: "sensor.energy_production_tarif_2_compensation",
|
||||||
"sensor.energy_production_tarif_2_compensation",
|
entity_energy_to: "sensor.energy_production_tarif_2",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
@@ -60,6 +55,7 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
type: "gas",
|
type: "gas",
|
||||||
stat_energy_from: "sensor.energy_gas",
|
stat_energy_from: "sensor.energy_gas",
|
||||||
stat_cost: "sensor.energy_gas_cost",
|
stat_cost: "sensor.energy_gas_cost",
|
||||||
|
entity_energy_from: "sensor.energy_gas",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
@@ -84,18 +80,11 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
stat_consumption: "sensor.energy_boiler",
|
stat_consumption: "sensor.energy_boiler",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
}));
|
||||||
);
|
hass.mockWS("energy/info", () => ({ cost_sensors: [] }));
|
||||||
hass.mockWS(
|
hass.mockWS("energy/fossil_energy_consumption", ({ period }) => ({
|
||||||
"energy/info",
|
|
||||||
(): EnergyInfo => ({ cost_sensors: {}, solar_forecast_domains: [] })
|
|
||||||
);
|
|
||||||
hass.mockWS(
|
|
||||||
"energy/fossil_energy_consumption",
|
|
||||||
({ period }): FossilEnergyConsumption => ({
|
|
||||||
start: period === "month" ? 250 : period === "day" ? 10 : 2,
|
start: period === "month" ? 250 : period === "day" ? 10 : 2,
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
const todayString = format(startOfToday(), "yyyy-MM-dd");
|
const todayString = format(startOfToday(), "yyyy-MM-dd");
|
||||||
const tomorrowString = format(startOfTomorrow(), "yyyy-MM-dd");
|
const tomorrowString = format(startOfTomorrow(), "yyyy-MM-dd");
|
||||||
hass.mockWS(
|
hass.mockWS(
|
||||||
|
@@ -1,4 +1,12 @@
|
|||||||
|
import {
|
||||||
|
addDays,
|
||||||
|
addHours,
|
||||||
|
addMonths,
|
||||||
|
differenceInHours,
|
||||||
|
endOfDay,
|
||||||
|
} from "date-fns/esm";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
|
import { StatisticValue } from "../../../src/data/history";
|
||||||
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
interface HistoryQueryParams {
|
interface HistoryQueryParams {
|
||||||
@@ -64,6 +72,331 @@ const generateHistory = (state, deltas) => {
|
|||||||
|
|
||||||
const incrementalUnits = ["clients", "queries", "ads"];
|
const incrementalUnits = ["clients", "queries", "ads"];
|
||||||
|
|
||||||
|
const generateMeanStatistics = (
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
period: "5minute" | "hour" | "day" | "month" = "hour",
|
||||||
|
initValue: number,
|
||||||
|
maxDiff: number
|
||||||
|
) => {
|
||||||
|
const statistics: StatisticValue[] = [];
|
||||||
|
let currentDate = new Date(start);
|
||||||
|
currentDate.setMinutes(0, 0, 0);
|
||||||
|
let lastVal = initValue;
|
||||||
|
const now = new Date();
|
||||||
|
while (end > currentDate && currentDate < now) {
|
||||||
|
const delta = Math.random() * maxDiff;
|
||||||
|
const mean = lastVal + delta;
|
||||||
|
statistics.push({
|
||||||
|
statistic_id: id,
|
||||||
|
start: currentDate.toISOString(),
|
||||||
|
end: currentDate.toISOString(),
|
||||||
|
mean,
|
||||||
|
min: mean - Math.random() * maxDiff,
|
||||||
|
max: mean + Math.random() * maxDiff,
|
||||||
|
last_reset: "1970-01-01T00:00:00+00:00",
|
||||||
|
state: mean,
|
||||||
|
sum: null,
|
||||||
|
});
|
||||||
|
lastVal = mean;
|
||||||
|
currentDate =
|
||||||
|
period === "day"
|
||||||
|
? addDays(currentDate, 1)
|
||||||
|
: period === "month"
|
||||||
|
? addMonths(currentDate, 1)
|
||||||
|
: addHours(currentDate, 1);
|
||||||
|
}
|
||||||
|
return statistics;
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateSumStatistics = (
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
period: "5minute" | "hour" | "day" | "month" = "hour",
|
||||||
|
initValue: number,
|
||||||
|
maxDiff: number
|
||||||
|
) => {
|
||||||
|
const statistics: StatisticValue[] = [];
|
||||||
|
let currentDate = new Date(start);
|
||||||
|
currentDate.setMinutes(0, 0, 0);
|
||||||
|
let sum = initValue;
|
||||||
|
const now = new Date();
|
||||||
|
while (end > currentDate && currentDate < now) {
|
||||||
|
const add = Math.random() * maxDiff;
|
||||||
|
sum += add;
|
||||||
|
statistics.push({
|
||||||
|
statistic_id: id,
|
||||||
|
start: currentDate.toISOString(),
|
||||||
|
end: currentDate.toISOString(),
|
||||||
|
mean: null,
|
||||||
|
min: null,
|
||||||
|
max: null,
|
||||||
|
last_reset: "1970-01-01T00:00:00+00:00",
|
||||||
|
state: initValue + sum,
|
||||||
|
sum,
|
||||||
|
});
|
||||||
|
currentDate =
|
||||||
|
period === "day"
|
||||||
|
? addDays(currentDate, 1)
|
||||||
|
: period === "month"
|
||||||
|
? addMonths(currentDate, 1)
|
||||||
|
: addHours(currentDate, 1);
|
||||||
|
}
|
||||||
|
return statistics;
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateCurvedStatistics = (
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
_period: "5minute" | "hour" | "day" | "month" = "hour",
|
||||||
|
initValue: number,
|
||||||
|
maxDiff: number,
|
||||||
|
metered: boolean
|
||||||
|
) => {
|
||||||
|
const statistics: StatisticValue[] = [];
|
||||||
|
let currentDate = new Date(start);
|
||||||
|
currentDate.setMinutes(0, 0, 0);
|
||||||
|
let sum = initValue;
|
||||||
|
const hours = differenceInHours(end, start) - 1;
|
||||||
|
let i = 0;
|
||||||
|
let half = false;
|
||||||
|
const now = new Date();
|
||||||
|
while (end > currentDate && currentDate < now) {
|
||||||
|
const add = Math.random() * maxDiff;
|
||||||
|
sum += i * add;
|
||||||
|
statistics.push({
|
||||||
|
statistic_id: id,
|
||||||
|
start: currentDate.toISOString(),
|
||||||
|
end: currentDate.toISOString(),
|
||||||
|
mean: null,
|
||||||
|
min: null,
|
||||||
|
max: null,
|
||||||
|
last_reset: "1970-01-01T00:00:00+00:00",
|
||||||
|
state: initValue + sum,
|
||||||
|
sum: metered ? sum : null,
|
||||||
|
});
|
||||||
|
currentDate = addHours(currentDate, 1);
|
||||||
|
if (!half && i > hours / 2) {
|
||||||
|
half = true;
|
||||||
|
}
|
||||||
|
i += half ? -1 : 1;
|
||||||
|
}
|
||||||
|
return statistics;
|
||||||
|
};
|
||||||
|
|
||||||
|
const statisticsFunctions: Record<
|
||||||
|
string,
|
||||||
|
(
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
period: "5minute" | "hour" | "day" | "month"
|
||||||
|
) => StatisticValue[]
|
||||||
|
> = {
|
||||||
|
"sensor.energy_consumption_tarif_1": (
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
period = "hour"
|
||||||
|
) => {
|
||||||
|
if (period !== "hour") {
|
||||||
|
return generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
period === "day" ? 17 : 504
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const morningEnd = new Date(start.getTime() + 10 * 60 * 60 * 1000);
|
||||||
|
const morningLow = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
morningEnd,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0.7
|
||||||
|
);
|
||||||
|
const eveningStart = new Date(start.getTime() + 20 * 60 * 60 * 1000);
|
||||||
|
const morningFinalVal = morningLow.length
|
||||||
|
? morningLow[morningLow.length - 1].sum!
|
||||||
|
: 0;
|
||||||
|
const empty = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
morningEnd,
|
||||||
|
eveningStart,
|
||||||
|
period,
|
||||||
|
morningFinalVal,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const eveningLow = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
eveningStart,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
morningFinalVal,
|
||||||
|
0.7
|
||||||
|
);
|
||||||
|
return [...morningLow, ...empty, ...eveningLow];
|
||||||
|
},
|
||||||
|
"sensor.energy_consumption_tarif_2": (
|
||||||
|
id: string,
|
||||||
|
start: Date,
|
||||||
|
end: Date,
|
||||||
|
period = "hour"
|
||||||
|
) => {
|
||||||
|
if (period !== "hour") {
|
||||||
|
return generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
period === "day" ? 17 : 504
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const morningEnd = new Date(start.getTime() + 9 * 60 * 60 * 1000);
|
||||||
|
const eveningStart = new Date(start.getTime() + 20 * 60 * 60 * 1000);
|
||||||
|
const highTarif = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
morningEnd,
|
||||||
|
eveningStart,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0.3
|
||||||
|
);
|
||||||
|
const highTarifFinalVal = highTarif.length
|
||||||
|
? highTarif[highTarif.length - 1].sum!
|
||||||
|
: 0;
|
||||||
|
const morning = generateSumStatistics(id, start, morningEnd, period, 0, 0);
|
||||||
|
const evening = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
eveningStart,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
highTarifFinalVal,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
return [...morning, ...highTarif, ...evening];
|
||||||
|
},
|
||||||
|
"sensor.energy_production_tarif_1": (id, start, end, period = "hour") =>
|
||||||
|
generateSumStatistics(id, start, end, period, 0, 0),
|
||||||
|
"sensor.energy_production_tarif_1_compensation": (
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period = "hour"
|
||||||
|
) => generateSumStatistics(id, start, end, period, 0, 0),
|
||||||
|
"sensor.energy_production_tarif_2": (id, start, end, period = "hour") => {
|
||||||
|
if (period !== "hour") {
|
||||||
|
return generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
period === "day" ? 17 : 504
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const productionStart = new Date(start.getTime() + 9 * 60 * 60 * 1000);
|
||||||
|
const productionEnd = new Date(start.getTime() + 21 * 60 * 60 * 1000);
|
||||||
|
const dayEnd = new Date(endOfDay(productionEnd));
|
||||||
|
const production = generateCurvedStatistics(
|
||||||
|
id,
|
||||||
|
productionStart,
|
||||||
|
productionEnd,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0.15,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const productionFinalVal = production.length
|
||||||
|
? production[production.length - 1].sum!
|
||||||
|
: 0;
|
||||||
|
const morning = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
productionStart,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const evening = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
productionEnd,
|
||||||
|
dayEnd,
|
||||||
|
period,
|
||||||
|
productionFinalVal,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const rest = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
dayEnd,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
productionFinalVal,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
return [...morning, ...production, ...evening, ...rest];
|
||||||
|
},
|
||||||
|
"sensor.solar_production": (id, start, end, period = "hour") => {
|
||||||
|
if (period !== "hour") {
|
||||||
|
return generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
period === "day" ? 17 : 504
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const productionStart = new Date(start.getTime() + 7 * 60 * 60 * 1000);
|
||||||
|
const productionEnd = new Date(start.getTime() + 23 * 60 * 60 * 1000);
|
||||||
|
const dayEnd = new Date(endOfDay(productionEnd));
|
||||||
|
const production = generateCurvedStatistics(
|
||||||
|
id,
|
||||||
|
productionStart,
|
||||||
|
productionEnd,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0.3,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const productionFinalVal = production.length
|
||||||
|
? production[production.length - 1].sum!
|
||||||
|
: 0;
|
||||||
|
const morning = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
productionStart,
|
||||||
|
period,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const evening = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
productionEnd,
|
||||||
|
dayEnd,
|
||||||
|
period,
|
||||||
|
productionFinalVal,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const rest = generateSumStatistics(
|
||||||
|
id,
|
||||||
|
dayEnd,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
productionFinalVal,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
return [...morning, ...production, ...evening, ...rest];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const mockHistory = (mockHass: MockHomeAssistant) => {
|
export const mockHistory = (mockHass: MockHomeAssistant) => {
|
||||||
mockHass.mockAPI(
|
mockHass.mockAPI(
|
||||||
new RegExp("history/period/.+"),
|
new RegExp("history/period/.+"),
|
||||||
@@ -133,4 +466,43 @@ export const mockHistory = (mockHass: MockHomeAssistant) => {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
mockHass.mockWS("recorder/get_statistics_metadata", () => []);
|
||||||
|
mockHass.mockWS("history/list_statistic_ids", () => []);
|
||||||
|
mockHass.mockWS(
|
||||||
|
"history/statistics_during_period",
|
||||||
|
({ statistic_ids, start_time, end_time, period }, hass) => {
|
||||||
|
const start = new Date(start_time);
|
||||||
|
const end = end_time ? new Date(end_time) : new Date();
|
||||||
|
|
||||||
|
const statistics: Record<string, StatisticValue[]> = {};
|
||||||
|
|
||||||
|
statistic_ids.forEach((id: string) => {
|
||||||
|
if (id in statisticsFunctions) {
|
||||||
|
statistics[id] = statisticsFunctions[id](id, start, end, period);
|
||||||
|
} else {
|
||||||
|
const entityState = hass.states[id];
|
||||||
|
const state = entityState ? Number(entityState.state) : 1;
|
||||||
|
statistics[id] =
|
||||||
|
entityState && "last_reset" in entityState.attributes
|
||||||
|
? generateSumStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
state,
|
||||||
|
state * (state > 80 ? 0.01 : 0.05)
|
||||||
|
)
|
||||||
|
: generateMeanStatistics(
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
period,
|
||||||
|
state,
|
||||||
|
state * (state > 80 ? 0.05 : 0.1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@@ -1,385 +0,0 @@
|
|||||||
import {
|
|
||||||
addDays,
|
|
||||||
addHours,
|
|
||||||
addMonths,
|
|
||||||
differenceInHours,
|
|
||||||
endOfDay,
|
|
||||||
} from "date-fns";
|
|
||||||
import {
|
|
||||||
Statistics,
|
|
||||||
StatisticsMetaData,
|
|
||||||
StatisticValue,
|
|
||||||
} from "../../../src/data/recorder";
|
|
||||||
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
|
||||||
|
|
||||||
const generateMeanStatistics = (
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
period: "5minute" | "hour" | "day" | "month" = "hour",
|
|
||||||
initValue: number,
|
|
||||||
maxDiff: number
|
|
||||||
): StatisticValue[] => {
|
|
||||||
const statistics: StatisticValue[] = [];
|
|
||||||
let currentDate = new Date(start);
|
|
||||||
currentDate.setMinutes(0, 0, 0);
|
|
||||||
let lastVal = initValue;
|
|
||||||
const now = new Date();
|
|
||||||
while (end > currentDate && currentDate < now) {
|
|
||||||
const delta = Math.random() * maxDiff;
|
|
||||||
const mean = lastVal + delta;
|
|
||||||
statistics.push({
|
|
||||||
statistic_id: id,
|
|
||||||
start: currentDate.toISOString(),
|
|
||||||
end: currentDate.toISOString(),
|
|
||||||
mean,
|
|
||||||
min: mean - Math.random() * maxDiff,
|
|
||||||
max: mean + Math.random() * maxDiff,
|
|
||||||
last_reset: "1970-01-01T00:00:00+00:00",
|
|
||||||
state: mean,
|
|
||||||
sum: null,
|
|
||||||
});
|
|
||||||
lastVal = mean;
|
|
||||||
currentDate =
|
|
||||||
period === "day"
|
|
||||||
? addDays(currentDate, 1)
|
|
||||||
: period === "month"
|
|
||||||
? addMonths(currentDate, 1)
|
|
||||||
: addHours(currentDate, 1);
|
|
||||||
}
|
|
||||||
return statistics;
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateSumStatistics = (
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
period: "5minute" | "hour" | "day" | "month" = "hour",
|
|
||||||
initValue: number,
|
|
||||||
maxDiff: number
|
|
||||||
): StatisticValue[] => {
|
|
||||||
const statistics: StatisticValue[] = [];
|
|
||||||
let currentDate = new Date(start);
|
|
||||||
currentDate.setMinutes(0, 0, 0);
|
|
||||||
let sum = initValue;
|
|
||||||
const now = new Date();
|
|
||||||
while (end > currentDate && currentDate < now) {
|
|
||||||
const add = Math.random() * maxDiff;
|
|
||||||
sum += add;
|
|
||||||
statistics.push({
|
|
||||||
statistic_id: id,
|
|
||||||
start: currentDate.toISOString(),
|
|
||||||
end: currentDate.toISOString(),
|
|
||||||
mean: null,
|
|
||||||
min: null,
|
|
||||||
max: null,
|
|
||||||
last_reset: "1970-01-01T00:00:00+00:00",
|
|
||||||
state: initValue + sum,
|
|
||||||
sum,
|
|
||||||
});
|
|
||||||
currentDate =
|
|
||||||
period === "day"
|
|
||||||
? addDays(currentDate, 1)
|
|
||||||
: period === "month"
|
|
||||||
? addMonths(currentDate, 1)
|
|
||||||
: addHours(currentDate, 1);
|
|
||||||
}
|
|
||||||
return statistics;
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateCurvedStatistics = (
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
_period: "5minute" | "hour" | "day" | "month" = "hour",
|
|
||||||
initValue: number,
|
|
||||||
maxDiff: number,
|
|
||||||
metered: boolean
|
|
||||||
): StatisticValue[] => {
|
|
||||||
const statistics: StatisticValue[] = [];
|
|
||||||
let currentDate = new Date(start);
|
|
||||||
currentDate.setMinutes(0, 0, 0);
|
|
||||||
let sum = initValue;
|
|
||||||
const hours = differenceInHours(end, start) - 1;
|
|
||||||
let i = 0;
|
|
||||||
let half = false;
|
|
||||||
const now = new Date();
|
|
||||||
while (end > currentDate && currentDate < now) {
|
|
||||||
const add = Math.random() * maxDiff;
|
|
||||||
sum += i * add;
|
|
||||||
statistics.push({
|
|
||||||
statistic_id: id,
|
|
||||||
start: currentDate.toISOString(),
|
|
||||||
end: currentDate.toISOString(),
|
|
||||||
mean: null,
|
|
||||||
min: null,
|
|
||||||
max: null,
|
|
||||||
last_reset: "1970-01-01T00:00:00+00:00",
|
|
||||||
state: initValue + sum,
|
|
||||||
sum: metered ? sum : null,
|
|
||||||
});
|
|
||||||
currentDate = addHours(currentDate, 1);
|
|
||||||
if (!half && i > hours / 2) {
|
|
||||||
half = true;
|
|
||||||
}
|
|
||||||
i += half ? -1 : 1;
|
|
||||||
}
|
|
||||||
return statistics;
|
|
||||||
};
|
|
||||||
|
|
||||||
const statisticsFunctions: Record<
|
|
||||||
string,
|
|
||||||
(
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
period: "5minute" | "hour" | "day" | "month"
|
|
||||||
) => StatisticValue[]
|
|
||||||
> = {
|
|
||||||
"sensor.energy_consumption_tarif_1": (
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
period = "hour"
|
|
||||||
) => {
|
|
||||||
if (period !== "hour") {
|
|
||||||
return generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
period === "day" ? 17 : 504
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const morningEnd = new Date(start.getTime() + 10 * 60 * 60 * 1000);
|
|
||||||
const morningLow = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
morningEnd,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0.7
|
|
||||||
);
|
|
||||||
const eveningStart = new Date(start.getTime() + 20 * 60 * 60 * 1000);
|
|
||||||
const morningFinalVal = morningLow.length
|
|
||||||
? morningLow[morningLow.length - 1].sum!
|
|
||||||
: 0;
|
|
||||||
const empty = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
morningEnd,
|
|
||||||
eveningStart,
|
|
||||||
period,
|
|
||||||
morningFinalVal,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const eveningLow = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
eveningStart,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
morningFinalVal,
|
|
||||||
0.7
|
|
||||||
);
|
|
||||||
return [...morningLow, ...empty, ...eveningLow];
|
|
||||||
},
|
|
||||||
"sensor.energy_consumption_tarif_2": (
|
|
||||||
id: string,
|
|
||||||
start: Date,
|
|
||||||
end: Date,
|
|
||||||
period = "hour"
|
|
||||||
) => {
|
|
||||||
if (period !== "hour") {
|
|
||||||
return generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
period === "day" ? 17 : 504
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const morningEnd = new Date(start.getTime() + 9 * 60 * 60 * 1000);
|
|
||||||
const eveningStart = new Date(start.getTime() + 20 * 60 * 60 * 1000);
|
|
||||||
const highTarif = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
morningEnd,
|
|
||||||
eveningStart,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0.3
|
|
||||||
);
|
|
||||||
const highTarifFinalVal = highTarif.length
|
|
||||||
? highTarif[highTarif.length - 1].sum!
|
|
||||||
: 0;
|
|
||||||
const morning = generateSumStatistics(id, start, morningEnd, period, 0, 0);
|
|
||||||
const evening = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
eveningStart,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
highTarifFinalVal,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
return [...morning, ...highTarif, ...evening];
|
|
||||||
},
|
|
||||||
"sensor.energy_production_tarif_1": (id, start, end, period = "hour") =>
|
|
||||||
generateSumStatistics(id, start, end, period, 0, 0),
|
|
||||||
"sensor.energy_production_tarif_1_compensation": (
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period = "hour"
|
|
||||||
) => generateSumStatistics(id, start, end, period, 0, 0),
|
|
||||||
"sensor.energy_production_tarif_2": (id, start, end, period = "hour") => {
|
|
||||||
if (period !== "hour") {
|
|
||||||
return generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
period === "day" ? 17 : 504
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const productionStart = new Date(start.getTime() + 9 * 60 * 60 * 1000);
|
|
||||||
const productionEnd = new Date(start.getTime() + 21 * 60 * 60 * 1000);
|
|
||||||
const dayEnd = new Date(endOfDay(productionEnd));
|
|
||||||
const production = generateCurvedStatistics(
|
|
||||||
id,
|
|
||||||
productionStart,
|
|
||||||
productionEnd,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0.15,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
const productionFinalVal = production.length
|
|
||||||
? production[production.length - 1].sum!
|
|
||||||
: 0;
|
|
||||||
const morning = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
productionStart,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const evening = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
productionEnd,
|
|
||||||
dayEnd,
|
|
||||||
period,
|
|
||||||
productionFinalVal,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const rest = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
dayEnd,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
productionFinalVal,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
return [...morning, ...production, ...evening, ...rest];
|
|
||||||
},
|
|
||||||
"sensor.solar_production": (id, start, end, period = "hour") => {
|
|
||||||
if (period !== "hour") {
|
|
||||||
return generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
period === "day" ? 17 : 504
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const productionStart = new Date(start.getTime() + 7 * 60 * 60 * 1000);
|
|
||||||
const productionEnd = new Date(start.getTime() + 23 * 60 * 60 * 1000);
|
|
||||||
const dayEnd = new Date(endOfDay(productionEnd));
|
|
||||||
const production = generateCurvedStatistics(
|
|
||||||
id,
|
|
||||||
productionStart,
|
|
||||||
productionEnd,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0.3,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
const productionFinalVal = production.length
|
|
||||||
? production[production.length - 1].sum!
|
|
||||||
: 0;
|
|
||||||
const morning = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
productionStart,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const evening = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
productionEnd,
|
|
||||||
dayEnd,
|
|
||||||
period,
|
|
||||||
productionFinalVal,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const rest = generateSumStatistics(
|
|
||||||
id,
|
|
||||||
dayEnd,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
productionFinalVal,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
return [...morning, ...production, ...evening, ...rest];
|
|
||||||
},
|
|
||||||
};
|
|
||||||
export const mockRecorder = (mockHass: MockHomeAssistant) => {
|
|
||||||
mockHass.mockWS(
|
|
||||||
"recorder/get_statistics_metadata",
|
|
||||||
(): StatisticsMetaData[] => []
|
|
||||||
);
|
|
||||||
mockHass.mockWS(
|
|
||||||
"recorder/list_statistic_ids",
|
|
||||||
(): StatisticsMetaData[] => []
|
|
||||||
);
|
|
||||||
mockHass.mockWS(
|
|
||||||
"recorder/statistics_during_period",
|
|
||||||
({ statistic_ids, start_time, end_time, period }, hass): Statistics => {
|
|
||||||
const start = new Date(start_time);
|
|
||||||
const end = end_time ? new Date(end_time) : new Date();
|
|
||||||
|
|
||||||
const statistics: Record<string, StatisticValue[]> = {};
|
|
||||||
|
|
||||||
statistic_ids.forEach((id: string) => {
|
|
||||||
if (id in statisticsFunctions) {
|
|
||||||
statistics[id] = statisticsFunctions[id](id, start, end, period);
|
|
||||||
} else {
|
|
||||||
const entityState = hass.states[id];
|
|
||||||
const state = entityState ? Number(entityState.state) : 1;
|
|
||||||
statistics[id] =
|
|
||||||
entityState && "last_reset" in entityState.attributes
|
|
||||||
? generateSumStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
state,
|
|
||||||
state * (state > 80 ? 0.01 : 0.05)
|
|
||||||
)
|
|
||||||
: generateMeanStatistics(
|
|
||||||
id,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
period,
|
|
||||||
state,
|
|
||||||
state * (state > 80 ? 0.05 : 0.1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return statistics;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
BIN
gallery/public/images/using-our-logo.png
Normal file
BIN
gallery/public/images/using-our-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
@@ -1,56 +0,0 @@
|
|||||||
---
|
|
||||||
title: When to use remove, delete, add and create
|
|
||||||
subtitle: The difference between remove/delete and add/create.
|
|
||||||
---
|
|
||||||
|
|
||||||
# Remove vs Delete
|
|
||||||
Remove and Delete are quite similar, but can be frustrating if used inconsistently.
|
|
||||||
|
|
||||||
## Remove
|
|
||||||
Take away and set aside, but kept in existence.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Removing a user's permission
|
|
||||||
* Removing a user from a group
|
|
||||||
* Removing links between items
|
|
||||||
* Removing a widget
|
|
||||||
* Removing a link
|
|
||||||
* Removing an item from a cart
|
|
||||||
|
|
||||||
## Delete
|
|
||||||
Erase, rendered nonexistent or nonrecoverable.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Deleting a field
|
|
||||||
* Deleting a value in a field
|
|
||||||
* Deleting a task
|
|
||||||
* Deleting a group
|
|
||||||
* Deleting a permission
|
|
||||||
* Deleting a calendar event
|
|
||||||
|
|
||||||
# Add vs Create
|
|
||||||
In most cases, Create can be paired with Delete, and Add can be paired with Remove.
|
|
||||||
|
|
||||||
## Add
|
|
||||||
An already-exisiting item.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Adding a permission to a user
|
|
||||||
* Adding a user to a group
|
|
||||||
* Adding links between items
|
|
||||||
* Adding a widget
|
|
||||||
* Adding a link
|
|
||||||
* Adding an item to a cart
|
|
||||||
|
|
||||||
## Create
|
|
||||||
Something made from scratch.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Creating a new field
|
|
||||||
* Creating a new value in a field
|
|
||||||
* Creating a new task
|
|
||||||
* Creating a new group
|
|
||||||
* Creating a new permission
|
|
||||||
* Creating a new calendar event
|
|
||||||
|
|
||||||
Based on this is [UX magazine article](https://uxmag.com/articles/ui-copy-remove-vs-delete2-banner).
|
|
@@ -36,7 +36,6 @@ const conditions = [
|
|||||||
{ condition: "sun", after: "sunset" },
|
{ condition: "sun", after: "sunset" },
|
||||||
{ condition: "sun", after: "sunrise", offset: "-01:00" },
|
{ condition: "sun", after: "sunrise", offset: "-01:00" },
|
||||||
{ condition: "zone", entity_id: "device_tracker.person", zone: "zone.home" },
|
{ condition: "zone", entity_id: "device_tracker.person", zone: "zone.home" },
|
||||||
{ condition: "trigger", id: "motion" },
|
|
||||||
{ condition: "time" },
|
{ condition: "time" },
|
||||||
{ condition: "template" },
|
{ condition: "template" },
|
||||||
];
|
];
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -47,8 +47,6 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
|
|||||||
class DemoHaAutomationEditorAction extends LitElement {
|
class DemoHaAutomationEditorAction extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.actions);
|
private data: any = SCHEMAS.map((info) => info.actions);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -69,15 +67,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -92,7 +81,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.actions=${this.data[sampleIdx]}
|
.actions=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`
|
`
|
||||||
@@ -102,20 +90,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -83,8 +83,6 @@ const SCHEMAS: { name: string; conditions: ConditionWithShorthand[] }[] = [
|
|||||||
class DemoHaAutomationEditorCondition extends LitElement {
|
class DemoHaAutomationEditorCondition extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.conditions);
|
private data: any = SCHEMAS.map((info) => info.conditions);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -105,15 +103,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -128,7 +117,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.conditions=${this.data[sampleIdx]}
|
.conditions=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
`
|
`
|
||||||
@@ -138,20 +126,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -107,8 +107,6 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
|||||||
class DemoHaAutomationEditorTrigger extends LitElement {
|
class DemoHaAutomationEditorTrigger extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.triggers);
|
private data: any = SCHEMAS.map((info) => info.triggers);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -129,15 +127,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -152,7 +141,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.triggers=${this.data[sampleIdx]}
|
.triggers=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
`
|
`
|
||||||
@@ -162,20 +150,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
title: "Logo"
|
title: "Logo"
|
||||||
---
|
---
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
# Using our logo
|
# Using our logo
|
||||||
|
|
||||||
As a community, we are proud of our logo. Follow these guidelines to ensure it always looks its best. Our logo follows Google's material design spec and uses the blue interface color.
|
As a community, we are proud of our logo. Follow these guidelines to ensure it always looks its best. Our logo follows Google's material design spec and uses the blue interface color.
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
title: Dialogs
|
title: Dialgos
|
||||||
subtitle: Dialogs provide important prompts in a user flow.
|
subtitle: Dialogs provide important prompts in a user flow.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Material Design 3
|
# Material Desing 3
|
||||||
|
|
||||||
Our dialogs are based on the latest version of Material Design. Specs and guidelines can be found on it's [website](https://m3.material.io/components/dialogs/overview).
|
Our dialogs are based on the latest version of Material Design. Specs and guidelines can be found on it's [website](https://m3.material.io/components/dialogs/overview).
|
||||||
|
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
title: Bar Sliders
|
|
||||||
---
|
|
@@ -1,169 +0,0 @@
|
|||||||
import { css, html, LitElement, TemplateResult } from "lit";
|
|
||||||
import { customElement, state } from "lit/decorators";
|
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
|
||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import "../../../../src/components/ha-bar-slider";
|
|
||||||
import "../../../../src/components/ha-card";
|
|
||||||
|
|
||||||
const sliders: {
|
|
||||||
id: string;
|
|
||||||
label: string;
|
|
||||||
mode?: "start" | "end" | "indicator";
|
|
||||||
class?: string;
|
|
||||||
}[] = [
|
|
||||||
{
|
|
||||||
id: "slider-start",
|
|
||||||
label: "Slider (start mode)",
|
|
||||||
mode: "start",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "slider-end",
|
|
||||||
label: "Slider (end mode)",
|
|
||||||
mode: "end",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "slider-indicator",
|
|
||||||
label: "Slider (indicator mode)",
|
|
||||||
mode: "indicator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "slider-start-custom",
|
|
||||||
label: "Slider (start mode) and custom style",
|
|
||||||
mode: "start",
|
|
||||||
class: "custom",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "slider-end-custom",
|
|
||||||
label: "Slider (end mode) and custom style",
|
|
||||||
mode: "end",
|
|
||||||
class: "custom",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "slider-indicator-custom",
|
|
||||||
label: "Slider (indicator mode) and custom style",
|
|
||||||
mode: "indicator",
|
|
||||||
class: "custom",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
@customElement("demo-components-ha-bar-slider")
|
|
||||||
export class DemoHaBarSlider extends LitElement {
|
|
||||||
@state() private value = 50;
|
|
||||||
|
|
||||||
@state() private sliderPosition?: number;
|
|
||||||
|
|
||||||
handleValueChanged(e: CustomEvent) {
|
|
||||||
this.value = e.detail.value as number;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSliderMoved(e: CustomEvent) {
|
|
||||||
this.sliderPosition = e.detail.value as number;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<ha-card>
|
|
||||||
<div class="card-content">
|
|
||||||
<p><b>Slider values</b></p>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>position</td>
|
|
||||||
<td>${this.sliderPosition ?? "-"}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>value</td>
|
|
||||||
<td>${this.value ?? "-"}</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
${repeat(sliders, (slider) => {
|
|
||||||
const { id, label, ...config } = slider;
|
|
||||||
return html`
|
|
||||||
<ha-card>
|
|
||||||
<div class="card-content">
|
|
||||||
<label id=${id}>${label}</label>
|
|
||||||
<pre>Config: ${JSON.stringify(config)}</pre>
|
|
||||||
<ha-bar-slider
|
|
||||||
.value=${this.value}
|
|
||||||
.mode=${config.mode}
|
|
||||||
class=${ifDefined(config.class)}
|
|
||||||
@value-changed=${this.handleValueChanged}
|
|
||||||
@slider-moved=${this.handleSliderMoved}
|
|
||||||
aria-labelledby=${id}
|
|
||||||
>
|
|
||||||
</ha-bar-slider>
|
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
`;
|
|
||||||
})}
|
|
||||||
<ha-card>
|
|
||||||
<div class="card-content">
|
|
||||||
<p class="title"><b>Vertical</b></p>
|
|
||||||
<div class="vertical-sliders">
|
|
||||||
${repeat(sliders, (slider) => {
|
|
||||||
const { id, label, ...config } = slider;
|
|
||||||
return html`
|
|
||||||
<ha-bar-slider
|
|
||||||
.value=${this.value}
|
|
||||||
.mode=${config.mode}
|
|
||||||
vertical
|
|
||||||
class=${ifDefined(config.class)}
|
|
||||||
@value-changed=${this.handleValueChanged}
|
|
||||||
@slider-moved=${this.handleSliderMoved}
|
|
||||||
aria-label=${label}
|
|
||||||
>
|
|
||||||
</ha-bar-slider>
|
|
||||||
`;
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles() {
|
|
||||||
return css`
|
|
||||||
ha-card {
|
|
||||||
max-width: 600px;
|
|
||||||
margin: 24px auto;
|
|
||||||
}
|
|
||||||
pre {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
label {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
.custom {
|
|
||||||
--slider-bar-color: #ffcf4c;
|
|
||||||
--slider-bar-background: #ffcf4c64;
|
|
||||||
--slider-bar-thickness: 100px;
|
|
||||||
--slider-bar-border-radius: 24px;
|
|
||||||
}
|
|
||||||
.vertical-sliders {
|
|
||||||
height: 300px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
p.title {
|
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
|
||||||
.vertical-sliders > *:not(:last-child) {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"demo-components-ha-bar-slider": DemoHaBarSlider;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -195,48 +195,6 @@ const SCHEMAS: {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select_disabled_list: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
],
|
|
||||||
mode: "list",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_disabled_multiple: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
multiple: true,
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
],
|
|
||||||
mode: "list",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_disabled: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
{ label: "Option 4", value: "Option 4", disabled: true },
|
|
||||||
{ label: "Option 5", value: "Option 5", disabled: true },
|
|
||||||
{ label: "Option 6", value: "Option 6" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_custom: {
|
select_custom: {
|
||||||
name: "Select (Custom)",
|
name: "Select (Custom)",
|
||||||
selector: {
|
selector: {
|
||||||
|
@@ -191,12 +191,10 @@ const createEntityRegistryEntries = (
|
|||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
entity_id: "binary_sensor.updater",
|
entity_id: "binary_sensor.updater",
|
||||||
id: "binary_sensor.updater",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "updater",
|
platform: "updater",
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "updater",
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -1,7 +1,16 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-card";
|
import "../../../../src/components/ha-card";
|
||||||
import { CoverEntityFeature } from "../../../../src/data/cover";
|
import {
|
||||||
|
SUPPORT_OPEN,
|
||||||
|
SUPPORT_STOP,
|
||||||
|
SUPPORT_CLOSE,
|
||||||
|
SUPPORT_SET_POSITION,
|
||||||
|
SUPPORT_OPEN_TILT,
|
||||||
|
SUPPORT_STOP_TILT,
|
||||||
|
SUPPORT_CLOSE_TILT,
|
||||||
|
SUPPORT_SET_TILT_POSITION,
|
||||||
|
} from "../../../../src/data/cover";
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
import "../../../../src/dialogs/more-info/more-info-content";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import {
|
import {
|
||||||
@@ -13,127 +22,113 @@ import "../../components/demo-more-infos";
|
|||||||
const ENTITIES = [
|
const ENTITIES = [
|
||||||
getEntity("cover", "position_buttons", "on", {
|
getEntity("cover", "position_buttons", "on", {
|
||||||
friendly_name: "Position Buttons",
|
friendly_name: "Position Buttons",
|
||||||
supported_features:
|
supported_features: SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE,
|
||||||
CoverEntityFeature.OPEN +
|
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE,
|
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_half", "on", {
|
getEntity("cover", "position_slider_half", "on", {
|
||||||
friendly_name: "Position Half-Open",
|
friendly_name: "Position Half-Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 50,
|
current_position: 50,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_open", "on", {
|
getEntity("cover", "position_slider_open", "on", {
|
||||||
friendly_name: "Position Open",
|
friendly_name: "Position Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 100,
|
current_position: 100,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_closed", "on", {
|
getEntity("cover", "position_slider_closed", "on", {
|
||||||
friendly_name: "Position Closed",
|
friendly_name: "Position Closed",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 0,
|
current_position: 0,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_buttons", "on", {
|
getEntity("cover", "tilt_buttons", "on", {
|
||||||
friendly_name: "Tilt Buttons",
|
friendly_name: "Tilt Buttons",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT + SUPPORT_STOP_TILT + SUPPORT_CLOSE_TILT,
|
||||||
CoverEntityFeature.STOP_TILT +
|
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_half", "on", {
|
getEntity("cover", "tilt_slider_half", "on", {
|
||||||
friendly_name: "Tilt Half-Open",
|
friendly_name: "Tilt Half-Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 50,
|
current_tilt_position: 50,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_open", "on", {
|
getEntity("cover", "tilt_slider_open", "on", {
|
||||||
friendly_name: "Tilt Open",
|
friendly_name: "Tilt Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 100,
|
current_tilt_position: 100,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_closed", "on", {
|
getEntity("cover", "tilt_slider_closed", "on", {
|
||||||
friendly_name: "Tilt Closed",
|
friendly_name: "Tilt Closed",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 0,
|
current_tilt_position: 0,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_tilt_slider", "on", {
|
getEntity("cover", "position_slider_tilt_slider", "on", {
|
||||||
friendly_name: "Both Sliders",
|
friendly_name: "Both Sliders",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_tilt_slider", "on", {
|
getEntity("cover", "position_tilt_slider", "on", {
|
||||||
friendly_name: "Position & Tilt Slider",
|
friendly_name: "Position & Tilt Slider",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_tilt", "on", {
|
getEntity("cover", "position_slider_tilt", "on", {
|
||||||
friendly_name: "Position Slider & Tilt",
|
friendly_name: "Position Slider & Tilt",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
SUPPORT_CLOSE_TILT,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_only_tilt_slider", "on", {
|
getEntity("cover", "position_slider_only_tilt_slider", "on", {
|
||||||
friendly_name: "Position Slider Only & Tilt Buttons",
|
friendly_name: "Position Slider Only & Tilt Buttons",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
SUPPORT_CLOSE_TILT,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_only_tilt", "on", {
|
getEntity("cover", "position_slider_only_tilt", "on", {
|
||||||
friendly_name: "Position Slider Only & Tilt",
|
friendly_name: "Position Slider Only & Tilt",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
title: Input Number
|
|
||||||
---
|
|
@@ -1,60 +0,0 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
|
||||||
import "../../../../src/components/ha-card";
|
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
|
||||||
import {
|
|
||||||
MockHomeAssistant,
|
|
||||||
provideHass,
|
|
||||||
} from "../../../../src/fake_data/provide_hass";
|
|
||||||
import "../../components/demo-more-infos";
|
|
||||||
|
|
||||||
const ENTITIES = [
|
|
||||||
getEntity("input_number", "box1", 0, {
|
|
||||||
friendly_name: "Box1",
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
step: 1,
|
|
||||||
initial: 0,
|
|
||||||
mode: "box",
|
|
||||||
unit_of_measurement: "items",
|
|
||||||
}),
|
|
||||||
getEntity("input_number", "slider1", 0, {
|
|
||||||
friendly_name: "Slider1",
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
step: 1,
|
|
||||||
initial: 0,
|
|
||||||
mode: "slider",
|
|
||||||
unit_of_measurement: "items",
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
@customElement("demo-more-info-input-number")
|
|
||||||
class DemoMoreInfoInputNumber extends LitElement {
|
|
||||||
@property() public hass!: MockHomeAssistant;
|
|
||||||
|
|
||||||
@query("demo-more-infos") private _demoRoot!: HTMLElement;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<demo-more-infos
|
|
||||||
.hass=${this.hass}
|
|
||||||
.entities=${ENTITIES.map((ent) => ent.entityId)}
|
|
||||||
></demo-more-infos>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues) {
|
|
||||||
super.firstUpdated(changedProperties);
|
|
||||||
const hass = provideHass(this._demoRoot);
|
|
||||||
hass.updateTranslations(null, "en");
|
|
||||||
hass.addEntities(ENTITIES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"demo-more-info-input-number": DemoMoreInfoInputNumber;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +1,12 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-card";
|
import "../../../../src/components/ha-card";
|
||||||
import { LightColorMode, LightEntityFeature } from "../../../../src/data/light";
|
import {
|
||||||
|
LightColorModes,
|
||||||
|
SUPPORT_EFFECT,
|
||||||
|
SUPPORT_FLASH,
|
||||||
|
SUPPORT_TRANSITION,
|
||||||
|
} from "../../../../src/data/light";
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
import "../../../../src/dialogs/more-info/more-info-content";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import {
|
import {
|
||||||
@@ -17,8 +22,8 @@ const ENTITIES = [
|
|||||||
getEntity("light", "kitchen_light", "on", {
|
getEntity("light", "kitchen_light", "on", {
|
||||||
friendly_name: "Brightness Light",
|
friendly_name: "Brightness Light",
|
||||||
brightness: 200,
|
brightness: 200,
|
||||||
supported_color_modes: [LightColorMode.BRIGHTNESS],
|
supported_color_modes: [LightColorModes.BRIGHTNESS],
|
||||||
color_mode: LightColorMode.BRIGHTNESS,
|
color_mode: LightColorModes.BRIGHTNESS,
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_temperature_light", "on", {
|
getEntity("light", "color_temperature_light", "on", {
|
||||||
friendly_name: "White Color Temperature Light",
|
friendly_name: "White Color Temperature Light",
|
||||||
@@ -27,10 +32,10 @@ const ENTITIES = [
|
|||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.COLOR_TEMP,
|
color_mode: LightColorModes.COLOR_TEMP,
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_hs_light", "on", {
|
getEntity("light", "color_hs_light", "on", {
|
||||||
friendly_name: "Color HS Light",
|
friendly_name: "Color HS Light",
|
||||||
@@ -39,16 +44,13 @@ const ENTITIES = [
|
|||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.HS,
|
LightColorModes.HS,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.HS,
|
color_mode: LightColorModes.HS,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgb_ct_light", "on", {
|
getEntity("light", "color_rgb_ct_light", "on", {
|
||||||
@@ -57,28 +59,22 @@ const ENTITIES = [
|
|||||||
color_temp: 75,
|
color_temp: 75,
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGB,
|
LightColorModes.RGB,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.COLOR_TEMP,
|
color_mode: LightColorModes.COLOR_TEMP,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_RGB_light", "on", {
|
getEntity("light", "color_RGB_light", "on", {
|
||||||
friendly_name: "Color Effects Light",
|
friendly_name: "Color Effects Light",
|
||||||
brightness: 255,
|
brightness: 255,
|
||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
supported_color_modes: [LightColorModes.BRIGHTNESS, LightColorModes.RGB],
|
||||||
LightEntityFeature.FLASH +
|
color_mode: LightColorModes.RGB,
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [LightColorMode.BRIGHTNESS, LightColorMode.RGB],
|
|
||||||
color_mode: LightColorMode.RGB,
|
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgbw_light", "on", {
|
getEntity("light", "color_rgbw_light", "on", {
|
||||||
@@ -87,16 +83,13 @@ const ENTITIES = [
|
|||||||
rgbw_color: [30, 100, 255, 125],
|
rgbw_color: [30, 100, 255, 125],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGBW,
|
LightColorModes.RGBW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.RGBW,
|
color_mode: LightColorModes.RGBW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgbww_light", "on", {
|
getEntity("light", "color_rgbww_light", "on", {
|
||||||
@@ -105,16 +98,13 @@ const ENTITIES = [
|
|||||||
rgbww_color: [30, 100, 255, 125, 10],
|
rgbww_color: [30, 100, 255, 125, 10],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGBWW,
|
LightColorModes.RGBWW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.RGBWW,
|
color_mode: LightColorModes.RGBWW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_xy_light", "on", {
|
getEntity("light", "color_xy_light", "on", {
|
||||||
@@ -124,16 +114,13 @@ const ENTITIES = [
|
|||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.XY,
|
LightColorModes.XY,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.XY,
|
color_mode: LightColorModes.XY,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
@@ -139,13 +139,6 @@ const ENTITIES = [
|
|||||||
title: undefined,
|
title: undefined,
|
||||||
friendly_name: "Installing without title",
|
friendly_name: "Installing without title",
|
||||||
}),
|
}),
|
||||||
getEntity("update", "update21", "on", {
|
|
||||||
...base_attributes,
|
|
||||||
in_progress: true,
|
|
||||||
friendly_name: "Update with in_progress true and UPDATE_SUPPORT_PROGRESS",
|
|
||||||
supported_features:
|
|
||||||
base_attributes.supported_features + UPDATE_SUPPORT_PROGRESS,
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@customElement("demo-more-info-update")
|
@customElement("demo-more-info-update")
|
||||||
|
@@ -118,7 +118,7 @@ class HassioAddonRepositoryEl extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _addonTapped(ev) {
|
private _addonTapped(ev) {
|
||||||
navigate(`/hassio/addon/${ev.currentTarget.addon.slug}?store=true`);
|
navigate(`/hassio/addon/${ev.currentTarget.addon.slug}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@@ -53,13 +53,7 @@ class HassioAddonDashboard extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public narrow!: boolean;
|
@property({ type: Boolean }) public narrow!: boolean;
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() _error?: string;
|
||||||
|
|
||||||
private _backPath = new URLSearchParams(window.parent.location.search).get(
|
|
||||||
"store"
|
|
||||||
)
|
|
||||||
? "/hassio/store"
|
|
||||||
: "/hassio/dashboard";
|
|
||||||
|
|
||||||
private _computeTail = memoizeOne((route: Route) => {
|
private _computeTail = memoizeOne((route: Route) => {
|
||||||
const dividerPos = route.path.indexOf("/", 1);
|
const dividerPos = route.path.indexOf("/", 1);
|
||||||
@@ -125,7 +119,6 @@ class HassioAddonDashboard extends LitElement {
|
|||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${route}
|
.route=${route}
|
||||||
.tabs=${addonTabs}
|
.tabs=${addonTabs}
|
||||||
.backPath=${this._backPath}
|
|
||||||
supervisor
|
supervisor
|
||||||
>
|
>
|
||||||
<span slot="header">${this.addon.name}</span>
|
<span slot="header">${this.addon.name}</span>
|
||||||
|
@@ -1024,13 +1024,10 @@ class HassioAddonInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
const confirmed = await showConfirmationDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
title: this.supervisor.localize("dialog.uninstall_addon.title", {
|
title: this.addon.name,
|
||||||
name: this.addon.name,
|
text: "Are you sure you want to uninstall this add-on?",
|
||||||
}),
|
confirmText: "uninstall add-on",
|
||||||
text: this.supervisor.localize("dialog.uninstall_addon.text"),
|
dismissText: "no",
|
||||||
confirmText: this.supervisor.localize("dialog.uninstall_addon.uninstall"),
|
|
||||||
dismissText: this.supervisor.localize("common.cancel"),
|
|
||||||
destructive: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
|
@@ -119,7 +119,6 @@ export class HassioBackups extends LitElement {
|
|||||||
(narrow: boolean): DataTableColumnContainer => ({
|
(narrow: boolean): DataTableColumnContainer => ({
|
||||||
name: {
|
name: {
|
||||||
title: this.supervisor.localize("backup.name"),
|
title: this.supervisor.localize("backup.name"),
|
||||||
main: true,
|
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
grows: true,
|
grows: true,
|
||||||
|
@@ -18,11 +18,9 @@ export const suggestAddonRestart = async (
|
|||||||
addon: HassioAddonDetails
|
addon: HassioAddonDetails
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const confirmed = await showConfirmationDialog(element, {
|
const confirmed = await showConfirmationDialog(element, {
|
||||||
title: supervisor.localize("dialog.restart_addon.title", {
|
title: supervisor.localize("common.restart_name", "name", addon.name),
|
||||||
name: addon.name,
|
|
||||||
}),
|
|
||||||
text: supervisor.localize("dialog.restart_addon.text"),
|
text: supervisor.localize("dialog.restart_addon.text"),
|
||||||
confirmText: supervisor.localize("dialog.restart_addon.restart"),
|
confirmText: supervisor.localize("dialog.restart_addon.confirm_text"),
|
||||||
dismissText: supervisor.localize("common.cancel"),
|
dismissText: supervisor.localize("common.cancel"),
|
||||||
});
|
});
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
@@ -30,9 +28,11 @@ export const suggestAddonRestart = async (
|
|||||||
await restartHassioAddon(hass, addon.slug);
|
await restartHassioAddon(hass, addon.slug);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(element, {
|
showAlertDialog(element, {
|
||||||
title: supervisor.localize("common.failed_to_restart_name", {
|
title: supervisor.localize(
|
||||||
name: addon.name,
|
"common.failed_to_restart_name",
|
||||||
}),
|
"name",
|
||||||
|
addon.name
|
||||||
|
),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@ import {
|
|||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
} from "../../../src/dialogs/generic/show-dialog-box";
|
} from "../../../src/dialogs/generic/show-dialog-box";
|
||||||
import { showJoinBetaDialog } from "../../../src/panels/config/core/updates/show-dialog-join-beta";
|
|
||||||
import {
|
import {
|
||||||
UNHEALTHY_REASON_URL,
|
UNHEALTHY_REASON_URL,
|
||||||
UNSUPPORTED_REASON_URL,
|
UNSUPPORTED_REASON_URL,
|
||||||
@@ -231,27 +230,36 @@ class HassioSupervisorInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
if (this.supervisor.supervisor.channel === "stable") {
|
if (this.supervisor.supervisor.channel === "stable") {
|
||||||
showJoinBetaDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
join: async () => {
|
title: this.supervisor.localize("system.supervisor.warning"),
|
||||||
await this._setChannel("beta");
|
text: html`${this.supervisor.localize("system.supervisor.beta_warning")}
|
||||||
button.progress = false;
|
<br />
|
||||||
},
|
<b> ${this.supervisor.localize("system.supervisor.beta_backup")} </b>
|
||||||
cancel: () => {
|
<br /><br />
|
||||||
button.progress = false;
|
${this.supervisor.localize("system.supervisor.beta_release_items")}
|
||||||
},
|
<ul>
|
||||||
|
<li>Home Assistant Core</li>
|
||||||
|
<li>Home Assistant Supervisor</li>
|
||||||
|
<li>Home Assistant Operating System</li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
${this.supervisor.localize("system.supervisor.beta_join_confirm")}`,
|
||||||
|
confirmText: this.supervisor.localize(
|
||||||
|
"system.supervisor.join_beta_action"
|
||||||
|
),
|
||||||
|
dismissText: this.supervisor.localize("common.cancel"),
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
await this._setChannel("stable");
|
if (!confirmed) {
|
||||||
button.progress = false;
|
button.progress = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _setChannel(
|
|
||||||
channel: SupervisorOptions["channel"]
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const data: Partial<SupervisorOptions> = {
|
const data: Partial<SupervisorOptions> = {
|
||||||
channel,
|
channel:
|
||||||
|
this.supervisor.supervisor.channel === "stable" ? "beta" : "stable",
|
||||||
};
|
};
|
||||||
await setSupervisorOption(this.hass, data);
|
await setSupervisorOption(this.hass, data);
|
||||||
await this._reloadSupervisor();
|
await this._reloadSupervisor();
|
||||||
@@ -262,6 +270,8 @@ class HassioSupervisorInfo extends LitElement {
|
|||||||
),
|
),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
button.progress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
package.json
12
package.json
@@ -43,6 +43,7 @@
|
|||||||
"@formatjs/intl-numberformat": "^7.2.5",
|
"@formatjs/intl-numberformat": "^7.2.5",
|
||||||
"@formatjs/intl-pluralrules": "^4.1.5",
|
"@formatjs/intl-pluralrules": "^4.1.5",
|
||||||
"@formatjs/intl-relativetimeformat": "^9.3.2",
|
"@formatjs/intl-relativetimeformat": "^9.3.2",
|
||||||
|
"@formatjs/intl-utils": "^3.8.4",
|
||||||
"@fullcalendar/common": "5.9.0",
|
"@fullcalendar/common": "5.9.0",
|
||||||
"@fullcalendar/core": "5.9.0",
|
"@fullcalendar/core": "5.9.0",
|
||||||
"@fullcalendar/daygrid": "5.9.0",
|
"@fullcalendar/daygrid": "5.9.0",
|
||||||
@@ -92,8 +93,8 @@
|
|||||||
"@polymer/paper-tooltip": "^3.0.1",
|
"@polymer/paper-tooltip": "^3.0.1",
|
||||||
"@polymer/polymer": "3.4.1",
|
"@polymer/polymer": "3.4.1",
|
||||||
"@thomasloven/round-slider": "0.5.4",
|
"@thomasloven/round-slider": "0.5.4",
|
||||||
"@vaadin/combo-box": "^23.2.0",
|
"@vaadin/combo-box": "^23.1.5",
|
||||||
"@vaadin/vaadin-themable-mixin": "^23.2.0",
|
"@vaadin/vaadin-themable-mixin": "^23.1.5",
|
||||||
"@vibrant/color": "^3.2.1-alpha.1",
|
"@vibrant/color": "^3.2.1-alpha.1",
|
||||||
"@vibrant/core": "^3.2.1-alpha.1",
|
"@vibrant/core": "^3.2.1-alpha.1",
|
||||||
"@vibrant/quantizer-mmcq": "^3.2.1-alpha.1",
|
"@vibrant/quantizer-mmcq": "^3.2.1-alpha.1",
|
||||||
@@ -110,8 +111,7 @@
|
|||||||
"deep-freeze": "^0.0.1",
|
"deep-freeze": "^0.0.1",
|
||||||
"fuse.js": "^6.0.0",
|
"fuse.js": "^6.0.0",
|
||||||
"google-timezones-json": "^1.0.2",
|
"google-timezones-json": "^1.0.2",
|
||||||
"hammerjs": "^2.0.8",
|
"hls.js": "^1.2.1",
|
||||||
"hls.js": "^1.2.3",
|
|
||||||
"home-assistant-js-websocket": "^8.0.0",
|
"home-assistant-js-websocket": "^8.0.0",
|
||||||
"idb-keyval": "^5.1.3",
|
"idb-keyval": "^5.1.3",
|
||||||
"intl-messageformat": "^9.9.1",
|
"intl-messageformat": "^9.9.1",
|
||||||
@@ -138,7 +138,6 @@
|
|||||||
"vis-network": "^8.5.4",
|
"vis-network": "^8.5.4",
|
||||||
"vue": "^2.6.12",
|
"vue": "^2.6.12",
|
||||||
"vue2-daterange-picker": "^0.5.1",
|
"vue2-daterange-picker": "^0.5.1",
|
||||||
"weekstart": "^1.1.0",
|
|
||||||
"workbox-cacheable-response": "^6.4.2",
|
"workbox-cacheable-response": "^6.4.2",
|
||||||
"workbox-core": "^6.4.2",
|
"workbox-core": "^6.4.2",
|
||||||
"workbox-expiration": "^6.4.2",
|
"workbox-expiration": "^6.4.2",
|
||||||
@@ -170,7 +169,6 @@
|
|||||||
"@types/chromecast-caf-receiver": "5.0.12",
|
"@types/chromecast-caf-receiver": "5.0.12",
|
||||||
"@types/chromecast-caf-sender": "^1.0.3",
|
"@types/chromecast-caf-sender": "^1.0.3",
|
||||||
"@types/glob": "^7",
|
"@types/glob": "^7",
|
||||||
"@types/hammerjs": "^2.0.41",
|
|
||||||
"@types/js-yaml": "^4",
|
"@types/js-yaml": "^4",
|
||||||
"@types/leaflet": "^1",
|
"@types/leaflet": "^1",
|
||||||
"@types/leaflet-draw": "^1",
|
"@types/leaflet-draw": "^1",
|
||||||
@@ -255,5 +253,5 @@
|
|||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"arrowParens": "always"
|
"arrowParens": "always"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@3.2.3"
|
"packageManager": "yarn@3.2.0"
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20221102.1"
|
version = "20220816.0"
|
||||||
license = {text = "Apache-2.0"}
|
license = {text = "Apache-2.0"}
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@@ -46,14 +46,6 @@ frontend:
|
|||||||
# development_repo: ${WD}" >> "${WD}/config/configuration.yaml"
|
# development_repo: ${WD}" >> "${WD}/config/configuration.yaml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "${CODESPACES}" ]; then
|
|
||||||
echo "
|
|
||||||
http:
|
|
||||||
use_x_forwarded_for: true
|
|
||||||
trusted_proxies:
|
|
||||||
- 127.0.0.1
|
|
||||||
" >> "${WD}/config/configuration.yaml"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hass -c "${WD}/config"
|
hass -c "${WD}/config"
|
||||||
|
@@ -20,21 +20,18 @@ fi
|
|||||||
# Load token from file if not already in the environment
|
# Load token from file if not already in the environment
|
||||||
[ -z "${LOKALISE_TOKEN-}" ] && LOKALISE_TOKEN="$(<.lokalise_token)"
|
[ -z "${LOKALISE_TOKEN-}" ] && LOKALISE_TOKEN="$(<.lokalise_token)"
|
||||||
|
|
||||||
declare -A PROJECT_ID=( \
|
PROJECT_ID="3420425759f6d6d241f598.13594006"
|
||||||
[frontend]="3420425759f6d6d241f598.13594006" \
|
LOCAL_DIR="$(pwd)/translations/downloads"
|
||||||
[backend]="130246255a974bd3b5e8a1.51616605" \
|
FILE_FORMAT=json
|
||||||
)
|
|
||||||
|
|
||||||
for project in ${!PROJECT_ID[*]}; do
|
mkdir -p ${LOCAL_DIR}
|
||||||
LOCAL_DIR=`pwd`/translations/${project}
|
|
||||||
rm -f ${LOCAL_DIR}/* || mkdir -p ${LOCAL_DIR}
|
docker run \
|
||||||
docker run \
|
|
||||||
-v ${LOCAL_DIR}:/opt/dest/locale \
|
-v ${LOCAL_DIR}:/opt/dest/locale \
|
||||||
--rm \
|
--rm \
|
||||||
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d \
|
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d lokalise2 \
|
||||||
lokalise2 \
|
|
||||||
--token ${LOKALISE_TOKEN} \
|
--token ${LOKALISE_TOKEN} \
|
||||||
--project-id ${PROJECT_ID[${project}]} \
|
--project-id ${PROJECT_ID} \
|
||||||
file download \
|
file download \
|
||||||
--export-empty-as skip \
|
--export-empty-as skip \
|
||||||
--format json \
|
--format json \
|
||||||
@@ -42,6 +39,5 @@ rm -f ${LOCAL_DIR}/* || mkdir -p ${LOCAL_DIR}
|
|||||||
--replace-breaks=false \
|
--replace-breaks=false \
|
||||||
--original-filenames=false \
|
--original-filenames=false \
|
||||||
--unzip-to /opt/dest
|
--unzip-to /opt/dest
|
||||||
done
|
|
||||||
|
|
||||||
./node_modules/.bin/gulp check-downloaded-translations
|
./node_modules/.bin/gulp check-downloaded-translations
|
@@ -15,7 +15,7 @@ import { computeInitialHaFormData } from "../components/ha-form/compute-initial-
|
|||||||
import "../components/ha-form/ha-form";
|
import "../components/ha-form/ha-form";
|
||||||
import "../components/ha-formfield";
|
import "../components/ha-formfield";
|
||||||
import "../components/ha-markdown";
|
import "../components/ha-markdown";
|
||||||
import { AuthProvider, autocompleteLoginFields } from "../data/auth";
|
import { AuthProvider } from "../data/auth";
|
||||||
import {
|
import {
|
||||||
DataEntryFlowStep,
|
DataEntryFlowStep,
|
||||||
DataEntryFlowStepForm,
|
DataEntryFlowStepForm,
|
||||||
@@ -204,7 +204,7 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
: html``}
|
: html``}
|
||||||
<ha-form
|
<ha-form
|
||||||
.data=${this._stepData}
|
.data=${this._stepData}
|
||||||
.schema=${autocompleteLoginFields(step.data_schema)}
|
.schema=${step.data_schema}
|
||||||
.error=${step.errors}
|
.error=${step.errors}
|
||||||
.disabled=${this._submitting}
|
.disabled=${this._submitting}
|
||||||
.computeLabel=${this._computeLabelCallback(step)}
|
.computeLabel=${this._computeLabelCallback(step)}
|
||||||
|
@@ -3,7 +3,6 @@ import { html, LitElement, TemplateResult } from "lit";
|
|||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import type { HaFormSchema } from "../components/ha-form/types";
|
import type { HaFormSchema } from "../components/ha-form/types";
|
||||||
import { autocompleteLoginFields } from "../data/auth";
|
|
||||||
import type { DataEntryFlowStep } from "../data/data_entry_flow";
|
import type { DataEntryFlowStep } from "../data/data_entry_flow";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -70,9 +69,7 @@ export class HaPasswordManagerPolyfill extends LitElement {
|
|||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
@submit=${this._handleSubmit}
|
@submit=${this._handleSubmit}
|
||||||
>
|
>
|
||||||
${autocompleteLoginFields(this.step.data_schema).map((input) =>
|
${this.step.data_schema.map((input) => this.render_input(input))}
|
||||||
this.render_input(input)
|
|
||||||
)}
|
|
||||||
<input type="submit" />
|
<input type="submit" />
|
||||||
<style>
|
<style>
|
||||||
${this.styles}
|
${this.styles}
|
||||||
@@ -92,10 +89,8 @@ export class HaPasswordManagerPolyfill extends LitElement {
|
|||||||
<input
|
<input
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
.id=${schema.name}
|
.id=${schema.name}
|
||||||
.name=${schema.name}
|
|
||||||
.type=${inputType}
|
.type=${inputType}
|
||||||
.value=${this.stepData[schema.name] || ""}
|
.value=${this.stepData[schema.name] || ""}
|
||||||
.autocomplete=${schema.autocomplete}
|
|
||||||
@input=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
import { hex2rgb } from "./convert-color";
|
|
||||||
|
|
||||||
export const THEME_COLORS = new Set([
|
|
||||||
"primary",
|
|
||||||
"accent",
|
|
||||||
"disabled",
|
|
||||||
"red",
|
|
||||||
"pink",
|
|
||||||
"purple",
|
|
||||||
"deep-purple",
|
|
||||||
"indigo",
|
|
||||||
"blue",
|
|
||||||
"light-blue",
|
|
||||||
"cyan",
|
|
||||||
"teal",
|
|
||||||
"green",
|
|
||||||
"light-green",
|
|
||||||
"lime",
|
|
||||||
"yellow",
|
|
||||||
"amber",
|
|
||||||
"orange",
|
|
||||||
"deep-orange",
|
|
||||||
"brown",
|
|
||||||
"grey",
|
|
||||||
"blue-grey",
|
|
||||||
"black",
|
|
||||||
"white",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export function computeRgbColor(color: string): string {
|
|
||||||
if (THEME_COLORS.has(color)) {
|
|
||||||
return `var(--rgb-${color}-color)`;
|
|
||||||
}
|
|
||||||
if (color.startsWith("#")) {
|
|
||||||
try {
|
|
||||||
return hex2rgb(color).join(", ");
|
|
||||||
} catch (err) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
|
@@ -6,14 +6,12 @@ import {
|
|||||||
mdiAlert,
|
mdiAlert,
|
||||||
mdiAngleAcute,
|
mdiAngleAcute,
|
||||||
mdiAppleSafari,
|
mdiAppleSafari,
|
||||||
mdiArrowLeftRight,
|
|
||||||
mdiBell,
|
mdiBell,
|
||||||
mdiBookmark,
|
mdiBookmark,
|
||||||
mdiBrightness5,
|
mdiBrightness5,
|
||||||
mdiBullhorn,
|
mdiBullhorn,
|
||||||
mdiCalendar,
|
mdiCalendar,
|
||||||
mdiCalendarClock,
|
mdiCalendarClock,
|
||||||
mdiCarCoolantLevel,
|
|
||||||
mdiCash,
|
mdiCash,
|
||||||
mdiClock,
|
mdiClock,
|
||||||
mdiCloudUpload,
|
mdiCloudUpload,
|
||||||
@@ -27,6 +25,7 @@ import {
|
|||||||
mdiFlower,
|
mdiFlower,
|
||||||
mdiFormatListBulleted,
|
mdiFormatListBulleted,
|
||||||
mdiFormTextbox,
|
mdiFormTextbox,
|
||||||
|
mdiGasCylinder,
|
||||||
mdiGauge,
|
mdiGauge,
|
||||||
mdiGestureTapButton,
|
mdiGestureTapButton,
|
||||||
mdiGoogleAssistant,
|
mdiGoogleAssistant,
|
||||||
@@ -38,30 +37,23 @@ import {
|
|||||||
mdiLightningBolt,
|
mdiLightningBolt,
|
||||||
mdiMailbox,
|
mdiMailbox,
|
||||||
mdiMapMarkerRadius,
|
mdiMapMarkerRadius,
|
||||||
mdiMeterGas,
|
|
||||||
mdiMicrophoneMessage,
|
|
||||||
mdiMolecule,
|
mdiMolecule,
|
||||||
mdiMoleculeCo,
|
mdiMoleculeCo,
|
||||||
mdiMoleculeCo2,
|
mdiMoleculeCo2,
|
||||||
mdiPalette,
|
mdiPalette,
|
||||||
mdiProgressClock,
|
|
||||||
mdiRayVertex,
|
mdiRayVertex,
|
||||||
mdiRemote,
|
mdiRemote,
|
||||||
mdiRobot,
|
mdiRobot,
|
||||||
mdiRobotVacuum,
|
mdiRobotVacuum,
|
||||||
mdiScriptText,
|
mdiScriptText,
|
||||||
mdiSineWave,
|
mdiSineWave,
|
||||||
mdiSpeedometer,
|
mdiMicrophoneMessage,
|
||||||
mdiThermometer,
|
mdiThermometer,
|
||||||
mdiThermostat,
|
mdiThermostat,
|
||||||
mdiTimerOutline,
|
mdiTimerOutline,
|
||||||
mdiVideo,
|
mdiVideo,
|
||||||
mdiWater,
|
|
||||||
mdiWaterPercent,
|
mdiWaterPercent,
|
||||||
mdiWeatherCloudy,
|
mdiWeatherCloudy,
|
||||||
mdiWeatherPouring,
|
|
||||||
mdiWeatherWindy,
|
|
||||||
mdiWeight,
|
|
||||||
mdiWhiteBalanceSunny,
|
mdiWhiteBalanceSunny,
|
||||||
mdiWifi,
|
mdiWifi,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
@@ -129,14 +121,11 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
|||||||
carbon_monoxide: mdiMoleculeCo,
|
carbon_monoxide: mdiMoleculeCo,
|
||||||
current: mdiCurrentAc,
|
current: mdiCurrentAc,
|
||||||
date: mdiCalendar,
|
date: mdiCalendar,
|
||||||
distance: mdiArrowLeftRight,
|
|
||||||
duration: mdiProgressClock,
|
|
||||||
energy: mdiLightningBolt,
|
energy: mdiLightningBolt,
|
||||||
frequency: mdiSineWave,
|
frequency: mdiSineWave,
|
||||||
gas: mdiMeterGas,
|
gas: mdiGasCylinder,
|
||||||
humidity: mdiWaterPercent,
|
humidity: mdiWaterPercent,
|
||||||
illuminance: mdiBrightness5,
|
illuminance: mdiBrightness5,
|
||||||
moisture: mdiWaterPercent,
|
|
||||||
monetary: mdiCash,
|
monetary: mdiCash,
|
||||||
nitrogen_dioxide: mdiMolecule,
|
nitrogen_dioxide: mdiMolecule,
|
||||||
nitrogen_monoxide: mdiMolecule,
|
nitrogen_monoxide: mdiMolecule,
|
||||||
@@ -147,20 +136,14 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
|||||||
pm25: mdiMolecule,
|
pm25: mdiMolecule,
|
||||||
power: mdiFlash,
|
power: mdiFlash,
|
||||||
power_factor: mdiAngleAcute,
|
power_factor: mdiAngleAcute,
|
||||||
precipitation_intensity: mdiWeatherPouring,
|
|
||||||
pressure: mdiGauge,
|
pressure: mdiGauge,
|
||||||
reactive_power: mdiFlash,
|
reactive_power: mdiFlash,
|
||||||
signal_strength: mdiWifi,
|
signal_strength: mdiWifi,
|
||||||
speed: mdiSpeedometer,
|
|
||||||
sulphur_dioxide: mdiMolecule,
|
sulphur_dioxide: mdiMolecule,
|
||||||
temperature: mdiThermometer,
|
temperature: mdiThermometer,
|
||||||
timestamp: mdiClock,
|
timestamp: mdiClock,
|
||||||
volatile_organic_compounds: mdiMolecule,
|
volatile_organic_compounds: mdiMolecule,
|
||||||
voltage: mdiSineWave,
|
voltage: mdiSineWave,
|
||||||
volume: mdiCarCoolantLevel,
|
|
||||||
water: mdiWater,
|
|
||||||
weight: mdiWeight,
|
|
||||||
wind_speed: mdiWeatherWindy,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Domains that have a state card. */
|
/** Domains that have a state card. */
|
||||||
|
@@ -1,33 +0,0 @@
|
|||||||
import { getWeekStartByLocale } from "weekstart";
|
|
||||||
import { FrontendLocaleData, FirstWeekday } from "../../data/translation";
|
|
||||||
|
|
||||||
export const weekdays = [
|
|
||||||
"sunday",
|
|
||||||
"monday",
|
|
||||||
"tuesday",
|
|
||||||
"wednesday",
|
|
||||||
"thursday",
|
|
||||||
"friday",
|
|
||||||
"saturday",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
||||||
|
|
||||||
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
|
||||||
if (locale.first_weekday === FirstWeekday.language) {
|
|
||||||
// @ts-ignore
|
|
||||||
if ("weekInfo" in Intl.Locale.prototype) {
|
|
||||||
// @ts-ignore
|
|
||||||
return new Intl.Locale(locale.language).weekInfo.firstDay % 7;
|
|
||||||
}
|
|
||||||
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
|
||||||
}
|
|
||||||
return weekdays.includes(locale.first_weekday)
|
|
||||||
? (weekdays.indexOf(locale.first_weekday) as WeekdayIndex)
|
|
||||||
: 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const firstWeekday = (locale: FrontendLocaleData) => {
|
|
||||||
const index = firstWeekdayIndex(locale);
|
|
||||||
return weekdays[index];
|
|
||||||
};
|
|
@@ -1,28 +0,0 @@
|
|||||||
import { HaDurationData } from "../../components/ha-duration-input";
|
|
||||||
|
|
||||||
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);
|
|
||||||
|
|
||||||
export const formatDuration = (duration: HaDurationData) => {
|
|
||||||
const d = duration.days || 0;
|
|
||||||
const h = duration.hours || 0;
|
|
||||||
const m = duration.minutes || 0;
|
|
||||||
const s = duration.seconds || 0;
|
|
||||||
const ms = duration.milliseconds || 0;
|
|
||||||
|
|
||||||
if (d > 0) {
|
|
||||||
return `${d} day${d === 1 ? "" : "s"} ${h}:${leftPad(m)}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (h > 0) {
|
|
||||||
return `${h}:${leftPad(m)}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (m > 0) {
|
|
||||||
return `${m}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (s > 0) {
|
|
||||||
return `${s} second${s === 1 ? "" : "s"}`;
|
|
||||||
}
|
|
||||||
if (ms > 0) {
|
|
||||||
return `${ms} millisecond${ms === 1 ? "" : "s"}`;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
@@ -1,7 +1,7 @@
|
|||||||
|
import { selectUnit } from "@formatjs/intl-utils";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import { polyfillsLoaded } from "../translations/localize";
|
import { polyfillsLoaded } from "../translations/localize";
|
||||||
import { selectUnit } from "../util/select-unit";
|
|
||||||
|
|
||||||
if (__BUILD__ === "latest" && polyfillsLoaded) {
|
if (__BUILD__ === "latest" && polyfillsLoaded) {
|
||||||
await polyfillsLoaded;
|
await polyfillsLoaded;
|
||||||
|
@@ -1,18 +0,0 @@
|
|||||||
export const alarmControlPanelColor = (state?: string): string | undefined => {
|
|
||||||
switch (state) {
|
|
||||||
case "armed_away":
|
|
||||||
case "armed_vacation":
|
|
||||||
case "armed_home":
|
|
||||||
case "armed_night":
|
|
||||||
case "armed_custom_bypass":
|
|
||||||
return "alarm-armed";
|
|
||||||
case "pending":
|
|
||||||
return "alarm-pending";
|
|
||||||
case "triggered":
|
|
||||||
return "alarm-triggered";
|
|
||||||
case "disarmed":
|
|
||||||
return "alarm-disarmed";
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
@@ -1,15 +0,0 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
|
|
||||||
export const batteryStateColor = (stateObj: HassEntity) => {
|
|
||||||
const value = Number(stateObj.state);
|
|
||||||
if (isNaN(value)) {
|
|
||||||
return "sensor-battery-unknown";
|
|
||||||
}
|
|
||||||
if (value >= 70) {
|
|
||||||
return "sensor-battery-high";
|
|
||||||
}
|
|
||||||
if (value >= 30) {
|
|
||||||
return "sensor-battery-medium";
|
|
||||||
}
|
|
||||||
return "sensor-battery-low";
|
|
||||||
};
|
|
@@ -1,20 +0,0 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
|
|
||||||
const NORMAL_DEVICE_CLASSES = new Set([
|
|
||||||
"battery_charging",
|
|
||||||
"connectivity",
|
|
||||||
"light",
|
|
||||||
"moving",
|
|
||||||
"plug",
|
|
||||||
"power",
|
|
||||||
"presence",
|
|
||||||
"running",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const binarySensorColor = (stateObj: HassEntity): string | undefined => {
|
|
||||||
const deviceClass = stateObj?.attributes.device_class;
|
|
||||||
|
|
||||||
return deviceClass && NORMAL_DEVICE_CLASSES.has(deviceClass)
|
|
||||||
? "binary-sensor"
|
|
||||||
: "binary-sensor-danger";
|
|
||||||
};
|
|
@@ -1,18 +0,0 @@
|
|||||||
export const climateColor = (state: string): string | undefined => {
|
|
||||||
switch (state) {
|
|
||||||
case "auto":
|
|
||||||
return "climate-auto";
|
|
||||||
case "cool":
|
|
||||||
return "climate-cool";
|
|
||||||
case "dry":
|
|
||||||
return "climate-dry";
|
|
||||||
case "fan_only":
|
|
||||||
return "climate-fan-only";
|
|
||||||
case "heat":
|
|
||||||
return "climate-heat";
|
|
||||||
case "heat_cool":
|
|
||||||
return "climate-heat-cool";
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
@@ -1,10 +0,0 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
|
|
||||||
const SECURE_DEVICE_CLASSES = new Set(["door", "gate", "garage", "window"]);
|
|
||||||
|
|
||||||
export const coverColor = (stateObj?: HassEntity): string | undefined => {
|
|
||||||
const isSecure =
|
|
||||||
stateObj?.attributes.device_class &&
|
|
||||||
SECURE_DEVICE_CLASSES.has(stateObj.attributes.device_class);
|
|
||||||
return isSecure ? "cover-secure" : "cover";
|
|
||||||
};
|
|
@@ -1,15 +0,0 @@
|
|||||||
export const lockColor = (state?: string): string | undefined => {
|
|
||||||
switch (state) {
|
|
||||||
case "locked":
|
|
||||||
return "lock-locked";
|
|
||||||
case "unlocked":
|
|
||||||
return "lock-unlocked";
|
|
||||||
case "jammed":
|
|
||||||
return "lock-jammed";
|
|
||||||
case "locking":
|
|
||||||
case "unlocking":
|
|
||||||
return "lock-pending";
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
@@ -1,32 +0,0 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
import { batteryStateColor } from "./battery_color";
|
|
||||||
|
|
||||||
export const sensorColor = (stateObj: HassEntity): string | undefined => {
|
|
||||||
const deviceClass = stateObj?.attributes.device_class;
|
|
||||||
|
|
||||||
if (deviceClass === "battery") {
|
|
||||||
return batteryStateColor(stateObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (deviceClass) {
|
|
||||||
case "apparent_power":
|
|
||||||
case "current":
|
|
||||||
case "energy":
|
|
||||||
case "gas":
|
|
||||||
case "power_factor":
|
|
||||||
case "power":
|
|
||||||
case "reactive_power":
|
|
||||||
case "voltage":
|
|
||||||
return "sensor-energy";
|
|
||||||
case "temperature":
|
|
||||||
return "sensor-temperature";
|
|
||||||
case "humidity":
|
|
||||||
return "sensor-humidity";
|
|
||||||
case "illuminance":
|
|
||||||
return "sensor-illuminance";
|
|
||||||
case "moisture":
|
|
||||||
return "sensor-moisture";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "sensor";
|
|
||||||
};
|
|
@@ -2,22 +2,17 @@ import { HassEntity } from "home-assistant-js-websocket";
|
|||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import {
|
import {
|
||||||
updateIsInstallingFromAttributes,
|
|
||||||
UPDATE_SUPPORT_PROGRESS,
|
UPDATE_SUPPORT_PROGRESS,
|
||||||
|
updateIsInstallingFromAttributes,
|
||||||
} from "../../data/update";
|
} from "../../data/update";
|
||||||
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
|
||||||
import { formatDate } from "../datetime/format_date";
|
import { formatDate } from "../datetime/format_date";
|
||||||
import { formatDateTime } from "../datetime/format_date_time";
|
import { formatDateTime } from "../datetime/format_date_time";
|
||||||
import { formatTime } from "../datetime/format_time";
|
import { formatTime } from "../datetime/format_time";
|
||||||
import {
|
import { formatNumber, isNumericFromAttributes } from "../number/format_number";
|
||||||
formatNumber,
|
|
||||||
getNumberFormatOptions,
|
|
||||||
isNumericFromAttributes,
|
|
||||||
} from "../number/format_number";
|
|
||||||
import { blankBeforePercent } from "../translations/blank_before_percent";
|
|
||||||
import { LocalizeFunc } from "../translations/localize";
|
import { LocalizeFunc } from "../translations/localize";
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
import { supportsFeatureFromAttributes } from "./supports-feature";
|
import { supportsFeatureFromAttributes } from "./supports-feature";
|
||||||
|
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
||||||
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export const computeStateDisplay = (
|
export const computeStateDisplay = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
@@ -72,13 +67,9 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
const unit = !attributes.unit_of_measurement
|
const unit = !attributes.unit_of_measurement
|
||||||
? ""
|
? ""
|
||||||
: attributes.unit_of_measurement === "%"
|
: attributes.unit_of_measurement === "%"
|
||||||
? blankBeforePercent(locale) + "%"
|
? "%"
|
||||||
: ` ${attributes.unit_of_measurement}`;
|
: ` ${attributes.unit_of_measurement}`;
|
||||||
return `${formatNumber(
|
return `${formatNumber(state, locale)}${unit}`;
|
||||||
state,
|
|
||||||
locale,
|
|
||||||
getNumberFormatOptions({ state, attributes } as HassEntity)
|
|
||||||
)}${unit}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = computeDomain(entityId);
|
const domain = computeDomain(entityId);
|
||||||
@@ -151,12 +142,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
domain === "number" ||
|
domain === "number" ||
|
||||||
domain === "input_number"
|
domain === "input_number"
|
||||||
) {
|
) {
|
||||||
// Format as an integer if the value and step are integers
|
return formatNumber(state, locale);
|
||||||
return formatNumber(
|
|
||||||
state,
|
|
||||||
locale,
|
|
||||||
getNumberFormatOptions({ state, attributes } as HassEntity)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// state of button is a timestamp
|
// state of button is a timestamp
|
||||||
@@ -182,8 +168,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
// When update is not available and there is no latest_version show "Unavailable"
|
// When update is not available and there is no latest_version show "Unavailable"
|
||||||
return state === "on"
|
return state === "on"
|
||||||
? updateIsInstallingFromAttributes(attributes)
|
? updateIsInstallingFromAttributes(attributes)
|
||||||
? supportsFeatureFromAttributes(attributes, UPDATE_SUPPORT_PROGRESS) &&
|
? supportsFeatureFromAttributes(attributes, UPDATE_SUPPORT_PROGRESS)
|
||||||
typeof attributes.in_progress === "number"
|
|
||||||
? localize("ui.card.update.installing_with_progress", {
|
? localize("ui.card.update.installing_with_progress", {
|
||||||
progress: attributes.in_progress,
|
progress: attributes.in_progress,
|
||||||
})
|
})
|
||||||
|
@@ -25,8 +25,6 @@ import {
|
|||||||
mdiPackageUp,
|
mdiPackageUp,
|
||||||
mdiPowerPlug,
|
mdiPowerPlug,
|
||||||
mdiPowerPlugOff,
|
mdiPowerPlugOff,
|
||||||
mdiAudioVideo,
|
|
||||||
mdiAudioVideoOff,
|
|
||||||
mdiRestart,
|
mdiRestart,
|
||||||
mdiSpeaker,
|
mdiSpeaker,
|
||||||
mdiSpeakerOff,
|
mdiSpeakerOff,
|
||||||
@@ -161,13 +159,6 @@ export const domainIconWithoutDefault = (
|
|||||||
default:
|
default:
|
||||||
return mdiTelevision;
|
return mdiTelevision;
|
||||||
}
|
}
|
||||||
case "receiver":
|
|
||||||
switch (compareState) {
|
|
||||||
case "off":
|
|
||||||
return mdiAudioVideoOff;
|
|
||||||
default:
|
|
||||||
return mdiAudioVideo;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
switch (compareState) {
|
switch (compareState) {
|
||||||
case "playing":
|
case "playing":
|
||||||
|
@@ -1,14 +1,10 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { supportsFeature } from "./supports-feature";
|
import { supportsFeature } from "./supports-feature";
|
||||||
|
|
||||||
export type FeatureClassNames<T extends number = number> = Partial<
|
|
||||||
Record<T, string>
|
|
||||||
>;
|
|
||||||
|
|
||||||
// Expects classNames to be an object mapping feature-bit -> className
|
// Expects classNames to be an object mapping feature-bit -> className
|
||||||
export const featureClassNames = (
|
export const featureClassNames = (
|
||||||
stateObj: HassEntity,
|
stateObj: HassEntity,
|
||||||
classNames: FeatureClassNames
|
classNames: { [feature: number]: string }
|
||||||
) => {
|
) => {
|
||||||
if (!stateObj || !stateObj.attributes.supported_features) {
|
if (!stateObj || !stateObj.attributes.supported_features) {
|
||||||
return "";
|
return "";
|
||||||
|
@@ -37,7 +37,6 @@ const FIXED_DOMAIN_STATES = {
|
|||||||
siren: ["on", "off"],
|
siren: ["on", "off"],
|
||||||
sun: ["above_horizon", "below_horizon"],
|
sun: ["above_horizon", "below_horizon"],
|
||||||
switch: ["on", "off"],
|
switch: ["on", "off"],
|
||||||
timer: ["active", "idle", "paused"],
|
|
||||||
update: ["on", "off"],
|
update: ["on", "off"],
|
||||||
vacuum: ["cleaning", "docked", "error", "idle", "paused", "returning"],
|
vacuum: ["cleaning", "docked", "error", "idle", "paused", "returning"],
|
||||||
weather: [
|
weather: [
|
||||||
@@ -240,13 +239,10 @@ export const getStates = (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "light":
|
case "light":
|
||||||
if (attribute === "effect" && state.attributes.effect_list) {
|
if (attribute === "effect") {
|
||||||
result.push(...state.attributes.effect_list);
|
result.push(...state.attributes.effect_list);
|
||||||
} else if (
|
} else if (attribute === "color_mode") {
|
||||||
attribute === "color_mode" &&
|
result.push(...state.attributes.color_modes);
|
||||||
state.attributes.supported_color_modes
|
|
||||||
) {
|
|
||||||
result.push(...state.attributes.supported_color_modes);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "media_player":
|
case "media_player":
|
||||||
|
@@ -1,36 +0,0 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
import { OFF_STATES } from "../../data/entity";
|
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
|
|
||||||
const NORMAL_UNKNOWN_DOMAIN = ["button", "input_button", "scene"];
|
|
||||||
const NORMAL_OFF_DOMAIN = ["script"];
|
|
||||||
|
|
||||||
export function stateActive(stateObj: HassEntity): boolean {
|
|
||||||
const domain = computeDomain(stateObj.entity_id);
|
|
||||||
const state = stateObj.state;
|
|
||||||
|
|
||||||
if (
|
|
||||||
OFF_STATES.includes(state) &&
|
|
||||||
!(NORMAL_UNKNOWN_DOMAIN.includes(domain) && state === "unknown") &&
|
|
||||||
!(NORMAL_OFF_DOMAIN.includes(domain) && state === "script")
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom cases
|
|
||||||
switch (domain) {
|
|
||||||
case "cover":
|
|
||||||
return state === "open" || state === "opening";
|
|
||||||
case "device_tracker":
|
|
||||||
case "person":
|
|
||||||
return state !== "not_home";
|
|
||||||
case "media-player":
|
|
||||||
return state !== "idle" && state !== "standby";
|
|
||||||
case "vacuum":
|
|
||||||
return state === "on" || state === "cleaning";
|
|
||||||
case "plant":
|
|
||||||
return state === "problem";
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
/** Return an color representing a state. */
|
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
import { UpdateEntity, updateIsInstalling } from "../../data/update";
|
|
||||||
import { alarmControlPanelColor } from "./color/alarm_control_panel_color";
|
|
||||||
import { binarySensorColor } from "./color/binary_sensor_color";
|
|
||||||
import { climateColor } from "./color/climate_color";
|
|
||||||
import { coverColor } from "./color/cover_color";
|
|
||||||
import { lockColor } from "./color/lock_color";
|
|
||||||
import { sensorColor } from "./color/sensor_color";
|
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
import { stateActive } from "./state_active";
|
|
||||||
|
|
||||||
export const stateColorCss = (stateObj?: HassEntity) => {
|
|
||||||
if (!stateObj || !stateActive(stateObj)) {
|
|
||||||
return `var(--rgb-disabled-color)`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const color = stateColor(stateObj);
|
|
||||||
|
|
||||||
if (color) {
|
|
||||||
return `var(--rgb-state-${color}-color)`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `var(--rgb-primary-color)`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const stateColor = (stateObj: HassEntity) => {
|
|
||||||
const state = stateObj.state;
|
|
||||||
const domain = computeDomain(stateObj.entity_id);
|
|
||||||
|
|
||||||
switch (domain) {
|
|
||||||
case "alarm_control_panel":
|
|
||||||
return alarmControlPanelColor(state);
|
|
||||||
|
|
||||||
case "binary_sensor":
|
|
||||||
return binarySensorColor(stateObj);
|
|
||||||
|
|
||||||
case "cover":
|
|
||||||
return coverColor(stateObj);
|
|
||||||
|
|
||||||
case "climate":
|
|
||||||
return climateColor(state);
|
|
||||||
|
|
||||||
case "lock":
|
|
||||||
return lockColor(state);
|
|
||||||
|
|
||||||
case "light":
|
|
||||||
return "light";
|
|
||||||
|
|
||||||
case "humidifier":
|
|
||||||
return "humidifier";
|
|
||||||
|
|
||||||
case "media_player":
|
|
||||||
return "media-player";
|
|
||||||
|
|
||||||
case "person":
|
|
||||||
case "device_tracker":
|
|
||||||
return "person";
|
|
||||||
|
|
||||||
case "sensor":
|
|
||||||
return sensorColor(stateObj);
|
|
||||||
|
|
||||||
case "vacuum":
|
|
||||||
return "vacuum";
|
|
||||||
|
|
||||||
case "sun":
|
|
||||||
return state === "above_horizon" ? "sun-day" : "sun-night";
|
|
||||||
|
|
||||||
case "update":
|
|
||||||
return updateIsInstalling(stateObj as UpdateEntity)
|
|
||||||
? "update-installing"
|
|
||||||
: "update";
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
};
|
|
@@ -1,50 +1,30 @@
|
|||||||
import { html } from "lit";
|
import { html } from "lit";
|
||||||
import { getConfigEntries } from "../../data/config_entries";
|
import { getConfigEntries } from "../../data/config_entries";
|
||||||
import { domainToName } from "../../data/integration";
|
|
||||||
import { getIntegrationDescriptions } from "../../data/integrations";
|
|
||||||
import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow";
|
|
||||||
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
||||||
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node";
|
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
import { isComponentLoaded } from "../config/is_component_loaded";
|
import { isComponentLoaded } from "../config/is_component_loaded";
|
||||||
|
import { fireEvent } from "../dom/fire_event";
|
||||||
import { navigate } from "../navigate";
|
import { navigate } from "../navigate";
|
||||||
|
|
||||||
export const protocolIntegrationPicked = async (
|
export const protocolIntegrationPicked = async (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
domain: string,
|
slug: string
|
||||||
options?: { brand?: string; domain?: string }
|
|
||||||
) => {
|
) => {
|
||||||
if (options?.domain) {
|
if (slug === "zwave_js") {
|
||||||
const localize = await hass.loadBackendTranslation("title", options.domain);
|
|
||||||
options.domain = domainToName(localize, options.domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.brand) {
|
|
||||||
const integrationDescriptions = await getIntegrationDescriptions(hass);
|
|
||||||
options.brand =
|
|
||||||
integrationDescriptions.core.integration[options.brand]?.name ||
|
|
||||||
options.brand;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (domain === "zwave_js") {
|
|
||||||
const entries = await getConfigEntries(hass, {
|
const entries = await getConfigEntries(hass, {
|
||||||
domain,
|
domain: "zwave_js",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isComponentLoaded(hass, "zwave_js") || !entries.length) {
|
if (!entries.length) {
|
||||||
// If the component isn't loaded, ask them to load the integration first
|
// If the component isn't loaded, ask them to load the integration first
|
||||||
showConfirmationDialog(element, {
|
showConfirmationDialog(element, {
|
||||||
title: hass.localize(
|
|
||||||
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
|
|
||||||
{ integration: "Z-Wave" }
|
|
||||||
),
|
|
||||||
text: hass.localize(
|
text: hass.localize(
|
||||||
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
|
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
|
||||||
{
|
{
|
||||||
integration: "Z-Wave",
|
integration: "Z-Wave",
|
||||||
brand: options?.brand || options?.domain || "Z-Wave",
|
|
||||||
supported_hardware_link: html`<a
|
supported_hardware_link: html`<a
|
||||||
href=${documentationUrl(hass, "/docs/z-wave/controllers")}
|
href=${documentationUrl(hass, "/docs/z-wave/controllers")}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -59,8 +39,8 @@ export const protocolIntegrationPicked = async (
|
|||||||
"ui.panel.config.integrations.config_flow.proceed"
|
"ui.panel.config.integrations.config_flow.proceed"
|
||||||
),
|
),
|
||||||
confirm: () => {
|
confirm: () => {
|
||||||
showConfigFlowDialog(element, {
|
fireEvent(element, "handler-picked", {
|
||||||
startFlowHandler: "zwave_js",
|
handler: "zwave_js",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -70,23 +50,14 @@ export const protocolIntegrationPicked = async (
|
|||||||
showZWaveJSAddNodeDialog(element, {
|
showZWaveJSAddNodeDialog(element, {
|
||||||
entry_id: entries[0].entry_id,
|
entry_id: entries[0].entry_id,
|
||||||
});
|
});
|
||||||
} else if (domain === "zha") {
|
} else if (slug === "zha") {
|
||||||
const entries = await getConfigEntries(hass, {
|
|
||||||
domain,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isComponentLoaded(hass, "zha") || !entries.length) {
|
|
||||||
// If the component isn't loaded, ask them to load the integration first
|
// If the component isn't loaded, ask them to load the integration first
|
||||||
|
if (!isComponentLoaded(hass, "zha")) {
|
||||||
showConfirmationDialog(element, {
|
showConfirmationDialog(element, {
|
||||||
title: hass.localize(
|
|
||||||
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
|
|
||||||
{ integration: "Zigbee" }
|
|
||||||
),
|
|
||||||
text: hass.localize(
|
text: hass.localize(
|
||||||
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
|
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
|
||||||
{
|
{
|
||||||
integration: "Zigbee",
|
integration: "Zigbee",
|
||||||
brand: options?.brand || options?.domain || "Z-Wave",
|
|
||||||
supported_hardware_link: html`<a
|
supported_hardware_link: html`<a
|
||||||
href=${documentationUrl(
|
href=${documentationUrl(
|
||||||
hass,
|
hass,
|
||||||
@@ -104,8 +75,8 @@ export const protocolIntegrationPicked = async (
|
|||||||
"ui.panel.config.integrations.config_flow.proceed"
|
"ui.panel.config.integrations.config_flow.proceed"
|
||||||
),
|
),
|
||||||
confirm: () => {
|
confirm: () => {
|
||||||
showConfigFlowDialog(element, {
|
fireEvent(element, "handler-picked", {
|
||||||
startFlowHandler: "zha",
|
handler: "zha",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
HassEntity,
|
|
||||||
HassEntityAttributeBase,
|
|
||||||
} from "home-assistant-js-websocket";
|
|
||||||
import { FrontendLocaleData, NumberFormat } from "../../data/translation";
|
import { FrontendLocaleData, NumberFormat } from "../../data/translation";
|
||||||
import { round } from "./round";
|
import { round } from "./round";
|
||||||
|
|
||||||
@@ -12,9 +9,9 @@ import { round } from "./round";
|
|||||||
export const isNumericState = (stateObj: HassEntity): boolean =>
|
export const isNumericState = (stateObj: HassEntity): boolean =>
|
||||||
isNumericFromAttributes(stateObj.attributes);
|
isNumericFromAttributes(stateObj.attributes);
|
||||||
|
|
||||||
export const isNumericFromAttributes = (
|
export const isNumericFromAttributes = (attributes: {
|
||||||
attributes: HassEntityAttributeBase
|
[key: string]: any;
|
||||||
): boolean => !!attributes.unit_of_measurement || !!attributes.state_class;
|
}): boolean => !!attributes.unit_of_measurement || !!attributes.state_class;
|
||||||
|
|
||||||
export const numberFormatToLocale = (
|
export const numberFormatToLocale = (
|
||||||
localeOptions: FrontendLocaleData
|
localeOptions: FrontendLocaleData
|
||||||
@@ -37,7 +34,7 @@ export const numberFormatToLocale = (
|
|||||||
* Formats a number based on the user's preference with thousands separator(s) and decimal character for better legibility.
|
* Formats a number based on the user's preference with thousands separator(s) and decimal character for better legibility.
|
||||||
*
|
*
|
||||||
* @param num The number to format
|
* @param num The number to format
|
||||||
* @param localeOptions The user-selected language and formatting, from `hass.locale`
|
* @param locale The user-selected language and number format, from `hass.locale`
|
||||||
* @param options Intl.NumberFormatOptions to use
|
* @param options Intl.NumberFormatOptions to use
|
||||||
*/
|
*/
|
||||||
export const formatNumber = (
|
export const formatNumber = (
|
||||||
@@ -84,29 +81,12 @@ export const formatNumber = (
|
|||||||
}`;
|
}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the current entity state should be formatted as an integer based on the `state` and `step` attribute and returns the appropriate `Intl.NumberFormatOptions` object with `maximumFractionDigits` set
|
|
||||||
* @param entityState The state object of the entity
|
|
||||||
* @returns An `Intl.NumberFormatOptions` object with `maximumFractionDigits` set to 0, or `undefined`
|
|
||||||
*/
|
|
||||||
export const getNumberFormatOptions = (
|
|
||||||
entityState: HassEntity
|
|
||||||
): Intl.NumberFormatOptions | undefined => {
|
|
||||||
if (
|
|
||||||
Number.isInteger(Number(entityState.attributes?.step)) &&
|
|
||||||
Number.isInteger(Number(entityState.state))
|
|
||||||
) {
|
|
||||||
return { maximumFractionDigits: 0 };
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates default options for Intl.NumberFormat
|
* Generates default options for Intl.NumberFormat
|
||||||
* @param num The number to be formatted
|
* @param num The number to be formatted
|
||||||
* @param options The Intl.NumberFormatOptions that should be included in the returned options
|
* @param options The Intl.NumberFormatOptions that should be included in the returned options
|
||||||
*/
|
*/
|
||||||
export const getDefaultFormatOptions = (
|
const getDefaultFormatOptions = (
|
||||||
num: string | number,
|
num: string | number,
|
||||||
options?: Intl.NumberFormatOptions
|
options?: Intl.NumberFormatOptions
|
||||||
): Intl.NumberFormatOptions => {
|
): Intl.NumberFormatOptions => {
|
||||||
@@ -122,8 +102,7 @@ export const getDefaultFormatOptions = (
|
|||||||
// Keep decimal trailing zeros if they are present in a string numeric value
|
// Keep decimal trailing zeros if they are present in a string numeric value
|
||||||
if (
|
if (
|
||||||
!options ||
|
!options ||
|
||||||
(options.minimumFractionDigits === undefined &&
|
(!options.minimumFractionDigits && !options.maximumFractionDigits)
|
||||||
options.maximumFractionDigits === undefined)
|
|
||||||
) {
|
) {
|
||||||
const digits = num.indexOf(".") > -1 ? num.split(".")[1].length : 0;
|
const digits = num.indexOf(".") > -1 ? num.split(".")[1].length : 0;
|
||||||
defaultOptions.minimumFractionDigits = digits;
|
defaultOptions.minimumFractionDigits = digits;
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
export const titleCase = (s) =>
|
|
||||||
s.replace(/^_*(.)|_+(.)/g, (_s, c, d) =>
|
|
||||||
c ? c.toUpperCase() : " " + d.toUpperCase()
|
|
||||||
);
|
|
@@ -1,18 +0,0 @@
|
|||||||
import { FrontendLocaleData } from "../../data/translation";
|
|
||||||
|
|
||||||
// Logic based on https://en.wikipedia.org/wiki/Percent_sign#Form_and_spacing
|
|
||||||
export const blankBeforePercent = (
|
|
||||||
localeOptions: FrontendLocaleData
|
|
||||||
): string => {
|
|
||||||
switch (localeOptions.language) {
|
|
||||||
case "cz":
|
|
||||||
case "de":
|
|
||||||
case "fi":
|
|
||||||
case "fr":
|
|
||||||
case "sk":
|
|
||||||
case "sv":
|
|
||||||
return " ";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
@@ -22,7 +22,9 @@ export type LocalizeKeys =
|
|||||||
| `ui.components.selectors.file.${string}`
|
| `ui.components.selectors.file.${string}`
|
||||||
| `ui.dialogs.entity_registry.editor.${string}`
|
| `ui.dialogs.entity_registry.editor.${string}`
|
||||||
| `ui.dialogs.more_info_control.vacuum.${string}`
|
| `ui.dialogs.more_info_control.vacuum.${string}`
|
||||||
|
| `ui.dialogs.options_flow.loading.${string}`
|
||||||
| `ui.dialogs.quick-bar.commands.${string}`
|
| `ui.dialogs.quick-bar.commands.${string}`
|
||||||
|
| `ui.dialogs.repair_flow.loading.${string}`
|
||||||
| `ui.dialogs.unhealthy.reason.${string}`
|
| `ui.dialogs.unhealthy.reason.${string}`
|
||||||
| `ui.dialogs.unsupported.reason.${string}`
|
| `ui.dialogs.unsupported.reason.${string}`
|
||||||
| `ui.panel.config.${string}.${"caption" | "description"}`
|
| `ui.panel.config.${string}.${"caption" | "description"}`
|
||||||
@@ -32,6 +34,7 @@ export type LocalizeKeys =
|
|||||||
| `ui.panel.config.energy.${string}`
|
| `ui.panel.config.energy.${string}`
|
||||||
| `ui.panel.config.helpers.${string}`
|
| `ui.panel.config.helpers.${string}`
|
||||||
| `ui.panel.config.info.${string}`
|
| `ui.panel.config.info.${string}`
|
||||||
|
| `ui.panel.config.integrations.${string}`
|
||||||
| `ui.panel.config.logs.${string}`
|
| `ui.panel.config.logs.${string}`
|
||||||
| `ui.panel.config.lovelace.${string}`
|
| `ui.panel.config.lovelace.${string}`
|
||||||
| `ui.panel.config.network.${string}`
|
| `ui.panel.config.network.${string}`
|
||||||
@@ -39,6 +42,7 @@ export type LocalizeKeys =
|
|||||||
| `ui.panel.config.url.${string}`
|
| `ui.panel.config.url.${string}`
|
||||||
| `ui.panel.config.zha.${string}`
|
| `ui.panel.config.zha.${string}`
|
||||||
| `ui.panel.config.zwave_js.${string}`
|
| `ui.panel.config.zwave_js.${string}`
|
||||||
|
| `ui.panel.developer-tools.tabs.${string}`
|
||||||
| `ui.panel.lovelace.card.${string}`
|
| `ui.panel.lovelace.card.${string}`
|
||||||
| `ui.panel.lovelace.editor.${string}`
|
| `ui.panel.lovelace.editor.${string}`
|
||||||
| `ui.panel.page-authorize.form.${string}`
|
| `ui.panel.page-authorize.form.${string}`
|
||||||
|
@@ -1,97 +0,0 @@
|
|||||||
export type Unit =
|
|
||||||
| "second"
|
|
||||||
| "minute"
|
|
||||||
| "hour"
|
|
||||||
| "day"
|
|
||||||
| "week"
|
|
||||||
| "month"
|
|
||||||
| "quarter"
|
|
||||||
| "year";
|
|
||||||
|
|
||||||
const MS_PER_SECOND = 1e3;
|
|
||||||
const SECS_PER_MIN = 60;
|
|
||||||
const SECS_PER_HOUR = SECS_PER_MIN * 60;
|
|
||||||
const SECS_PER_DAY = SECS_PER_HOUR * 24;
|
|
||||||
const SECS_PER_WEEK = SECS_PER_DAY * 7;
|
|
||||||
|
|
||||||
// Adapted from https://github.com/formatjs/formatjs/blob/186cef62f980ec66252ee232f438a42d0b51b9f9/packages/intl-utils/src/diff.ts
|
|
||||||
export function selectUnit(
|
|
||||||
from: Date | number,
|
|
||||||
to: Date | number = Date.now(),
|
|
||||||
thresholds: Partial<Thresholds> = {}
|
|
||||||
): { value: number; unit: Unit } {
|
|
||||||
const resolvedThresholds: Thresholds = {
|
|
||||||
...DEFAULT_THRESHOLDS,
|
|
||||||
...(thresholds || {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
const secs = (+from - +to) / MS_PER_SECOND;
|
|
||||||
if (Math.abs(secs) < resolvedThresholds.second) {
|
|
||||||
return {
|
|
||||||
value: Math.round(secs),
|
|
||||||
unit: "second",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const mins = secs / SECS_PER_MIN;
|
|
||||||
if (Math.abs(mins) < resolvedThresholds.minute) {
|
|
||||||
return {
|
|
||||||
value: Math.round(mins),
|
|
||||||
unit: "minute",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const hours = secs / SECS_PER_HOUR;
|
|
||||||
if (Math.abs(hours) < resolvedThresholds.hour) {
|
|
||||||
return {
|
|
||||||
value: Math.round(hours),
|
|
||||||
unit: "hour",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const days = secs / SECS_PER_DAY;
|
|
||||||
if (Math.abs(days) < resolvedThresholds.day) {
|
|
||||||
return {
|
|
||||||
value: Math.round(days),
|
|
||||||
unit: "day",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const weeks = secs / SECS_PER_WEEK;
|
|
||||||
if (Math.abs(weeks) < resolvedThresholds.week) {
|
|
||||||
return {
|
|
||||||
value: Math.round(weeks),
|
|
||||||
unit: "week",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const fromDate = new Date(from);
|
|
||||||
const toDate = new Date(to);
|
|
||||||
const years = fromDate.getFullYear() - toDate.getFullYear();
|
|
||||||
const months = years * 12 + fromDate.getMonth() - toDate.getMonth();
|
|
||||||
if (Math.round(Math.abs(months)) < resolvedThresholds.month) {
|
|
||||||
return {
|
|
||||||
value: Math.round(months),
|
|
||||||
unit: "month",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
value: Math.round(years),
|
|
||||||
unit: "year",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type Thresholds = Record<
|
|
||||||
"second" | "minute" | "hour" | "day" | "week" | "month",
|
|
||||||
number
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const DEFAULT_THRESHOLDS: Thresholds = {
|
|
||||||
second: 45, // seconds to minute
|
|
||||||
minute: 45, // minutes to hour
|
|
||||||
hour: 22, // hour to day
|
|
||||||
day: 5, // day to week
|
|
||||||
week: 4, // week to months
|
|
||||||
month: 11, // month to years
|
|
||||||
};
|
|
@@ -14,7 +14,6 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) {
|
|||||||
<ha-progress-button
|
<ha-progress-button
|
||||||
id="progress"
|
id="progress"
|
||||||
progress="[[progress]]"
|
progress="[[progress]]"
|
||||||
disabled="[[disabled]]"
|
|
||||||
on-click="buttonTapped"
|
on-click="buttonTapped"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
><slot></slot
|
><slot></slot
|
||||||
@@ -49,10 +48,6 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) {
|
|||||||
confirmation: {
|
confirmation: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,25 +118,6 @@ export class StateHistoryChartTimeline extends LitElement {
|
|||||||
|
|
||||||
public willUpdate(changedProps: PropertyValues) {
|
public willUpdate(changedProps: PropertyValues) {
|
||||||
if (!this.hasUpdated) {
|
if (!this.hasUpdated) {
|
||||||
this._createOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
changedProps.has("data") ||
|
|
||||||
this._chartTime <
|
|
||||||
new Date(this.endTime.getTime() - MIN_TIME_BETWEEN_UPDATES)
|
|
||||||
) {
|
|
||||||
// If the line is more than 5 minutes old, re-gen it
|
|
||||||
// so the X axis grows even if there is no new data
|
|
||||||
this._generateData();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changedProps.has("startTime") || changedProps.has("endTime")) {
|
|
||||||
this._createOptions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _createOptions() {
|
|
||||||
const narrow = this.narrow;
|
const narrow = this.narrow;
|
||||||
this._chartOptions = {
|
this._chartOptions = {
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
@@ -232,6 +213,16 @@ export class StateHistoryChartTimeline extends LitElement {
|
|||||||
locale: numberFormatToLocale(this.hass.locale),
|
locale: numberFormatToLocale(this.hass.locale),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
changedProps.has("data") ||
|
||||||
|
this._chartTime <
|
||||||
|
new Date(this.endTime.getTime() - MIN_TIME_BETWEEN_UPDATES)
|
||||||
|
) {
|
||||||
|
// If the line is more than 5 minutes old, re-gen it
|
||||||
|
// so the X axis grows even if there is no new data
|
||||||
|
this._generateData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _generateData() {
|
private _generateData() {
|
||||||
const computedStyles = getComputedStyle(this);
|
const computedStyles = getComputedStyle(this);
|
||||||
|
@@ -13,7 +13,6 @@ import {
|
|||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import {
|
import {
|
||||||
@@ -21,38 +20,31 @@ import {
|
|||||||
numberFormatToLocale,
|
numberFormatToLocale,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import {
|
import {
|
||||||
getDisplayUnit,
|
getStatisticIds,
|
||||||
getStatisticLabel,
|
getStatisticLabel,
|
||||||
getStatisticMetadata,
|
|
||||||
Statistics,
|
Statistics,
|
||||||
statisticsHaveType,
|
statisticsHaveType,
|
||||||
|
StatisticsMetaData,
|
||||||
StatisticType,
|
StatisticType,
|
||||||
} from "../../data/recorder";
|
} from "../../data/history";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "./ha-chart-base";
|
import "./ha-chart-base";
|
||||||
|
|
||||||
export type ExtendedStatisticType = StatisticType | "state";
|
|
||||||
|
|
||||||
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
|
|
||||||
mean: "mean",
|
|
||||||
min: "min",
|
|
||||||
max: "max",
|
|
||||||
sum: "sum",
|
|
||||||
state: "sum",
|
|
||||||
};
|
|
||||||
@customElement("statistics-chart")
|
@customElement("statistics-chart")
|
||||||
class StatisticsChart extends LitElement {
|
class StatisticsChart extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public statisticsData!: Statistics;
|
@property({ attribute: false }) public statisticsData!: Statistics;
|
||||||
|
|
||||||
|
@property({ type: Array }) public statisticIds?: StatisticsMetaData[];
|
||||||
|
|
||||||
@property() public names: boolean | Record<string, string> = false;
|
@property() public names: boolean | Record<string, string> = false;
|
||||||
|
|
||||||
@property() public unit?: string;
|
@property() public unit?: string;
|
||||||
|
|
||||||
@property({ attribute: false }) public endTime?: Date;
|
@property({ attribute: false }) public endTime?: Date;
|
||||||
|
|
||||||
@property({ type: Array }) public statTypes: Array<ExtendedStatisticType> = [
|
@property({ type: Array }) public statTypes: Array<StatisticType> = [
|
||||||
"sum",
|
"sum",
|
||||||
"min",
|
"min",
|
||||||
"mean",
|
"mean",
|
||||||
@@ -199,28 +191,18 @@ class StatisticsChart extends LitElement {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getStatisticsMetaData = memoizeOne(
|
private async _getStatisticIds() {
|
||||||
async (statisticIds: string[] | undefined) => {
|
this.statisticIds = await getStatisticIds(this.hass);
|
||||||
const statsMetadataArray = await getStatisticMetadata(
|
|
||||||
this.hass,
|
|
||||||
statisticIds
|
|
||||||
);
|
|
||||||
const statisticsMetaData = {};
|
|
||||||
statsMetadataArray.forEach((x) => {
|
|
||||||
statisticsMetaData[x.statistic_id] = x;
|
|
||||||
});
|
|
||||||
return statisticsMetaData;
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
private async _generateData() {
|
private async _generateData() {
|
||||||
if (!this.statisticsData) {
|
if (!this.statisticsData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const statisticsMetaData = await this._getStatisticsMetaData(
|
if (!this.statisticIds) {
|
||||||
Object.keys(this.statisticsData)
|
await this._getStatisticIds();
|
||||||
);
|
}
|
||||||
|
|
||||||
let colorIndex = 0;
|
let colorIndex = 0;
|
||||||
const statisticsData = Object.values(this.statisticsData);
|
const statisticsData = Object.values(this.statisticsData);
|
||||||
@@ -251,19 +233,18 @@ class StatisticsChart extends LitElement {
|
|||||||
const names = this.names || {};
|
const names = this.names || {};
|
||||||
statisticsData.forEach((stats) => {
|
statisticsData.forEach((stats) => {
|
||||||
const firstStat = stats[0];
|
const firstStat = stats[0];
|
||||||
const meta = statisticsMetaData?.[firstStat.statistic_id];
|
const meta = this.statisticIds!.find(
|
||||||
|
(stat) => stat.statistic_id === firstStat.statistic_id
|
||||||
|
);
|
||||||
let name = names[firstStat.statistic_id];
|
let name = names[firstStat.statistic_id];
|
||||||
if (name === undefined) {
|
if (!name) {
|
||||||
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
|
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.unit) {
|
if (!this.unit) {
|
||||||
if (unit === undefined) {
|
if (unit === undefined) {
|
||||||
unit = getDisplayUnit(this.hass, firstStat.statistic_id, meta);
|
unit = meta?.display_unit_of_measurement;
|
||||||
} else if (
|
} else if (unit !== meta?.display_unit_of_measurement) {
|
||||||
unit !== getDisplayUnit(this.hass, firstStat.statistic_id, meta)
|
|
||||||
) {
|
|
||||||
// Clear unit if not all statistics have same unit
|
|
||||||
unit = null;
|
unit = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,18 +301,14 @@ class StatisticsChart extends LitElement {
|
|||||||
: this.statTypes;
|
: this.statTypes;
|
||||||
|
|
||||||
sortedTypes.forEach((type) => {
|
sortedTypes.forEach((type) => {
|
||||||
if (statisticsHaveType(stats, statTypeMap[type])) {
|
if (statisticsHaveType(stats, type)) {
|
||||||
const band = drawBands && (type === "min" || type === "max");
|
const band = drawBands && (type === "min" || type === "max");
|
||||||
statTypes.push(type);
|
statTypes.push(type);
|
||||||
statDataSets.push({
|
statDataSets.push({
|
||||||
label: name
|
label: `${name} (${this.hass.localize(
|
||||||
? `${name} (${this.hass.localize(
|
|
||||||
`ui.components.statistics_charts.statistic_types.${type}`
|
`ui.components.statistics_charts.statistic_types.${type}`
|
||||||
)})
|
)})
|
||||||
`
|
`,
|
||||||
: this.hass.localize(
|
|
||||||
`ui.components.statistics_charts.statistic_types.${type}`
|
|
||||||
),
|
|
||||||
fill: drawBands
|
fill: drawBands
|
||||||
? type === "min"
|
? type === "min"
|
||||||
? "+1"
|
? "+1"
|
||||||
@@ -352,6 +329,7 @@ class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
let prevDate: Date | null = null;
|
let prevDate: Date | null = null;
|
||||||
// Process chart data.
|
// Process chart data.
|
||||||
|
let initVal: number | null = null;
|
||||||
let prevSum: number | null = null;
|
let prevSum: number | null = null;
|
||||||
stats.forEach((stat) => {
|
stats.forEach((stat) => {
|
||||||
const date = new Date(stat.start);
|
const date = new Date(stat.start);
|
||||||
@@ -363,11 +341,11 @@ class StatisticsChart extends LitElement {
|
|||||||
statTypes.forEach((type) => {
|
statTypes.forEach((type) => {
|
||||||
let val: number | null;
|
let val: number | null;
|
||||||
if (type === "sum") {
|
if (type === "sum") {
|
||||||
if (prevSum === null) {
|
if (initVal === null) {
|
||||||
val = 0;
|
initVal = val = stat.state || 0;
|
||||||
prevSum = stat.sum;
|
prevSum = stat.sum;
|
||||||
} else {
|
} else {
|
||||||
val = (stat.sum || 0) - prevSum;
|
val = initVal + ((stat.sum || 0) - prevSum!);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val = stat[type];
|
val = stat[type];
|
||||||
|
@@ -69,7 +69,6 @@ export interface DataTableSortColumnData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DataTableColumnData<T = any> extends DataTableSortColumnData {
|
export interface DataTableColumnData<T = any> extends DataTableSortColumnData {
|
||||||
main?: boolean;
|
|
||||||
title: TemplateResult | string;
|
title: TemplateResult | string;
|
||||||
label?: TemplateResult | string;
|
label?: TemplateResult | string;
|
||||||
type?: "numeric" | "icon" | "icon-button" | "overflow-menu";
|
type?: "numeric" | "icon" | "icon-button" | "overflow-menu";
|
||||||
@@ -407,7 +406,7 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
role=${column.main ? "rowheader" : "cell"}
|
role="cell"
|
||||||
class="mdc-data-table__cell ${classMap({
|
class="mdc-data-table__cell ${classMap({
|
||||||
"mdc-data-table__cell--numeric": column.type === "numeric",
|
"mdc-data-table__cell--numeric": column.type === "numeric",
|
||||||
"mdc-data-table__cell--icon": column.type === "icon",
|
"mdc-data-table__cell--icon": column.type === "icon",
|
||||||
@@ -724,11 +723,6 @@ export class HaDataTable extends LitElement {
|
|||||||
width: 54px;
|
width: 54px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mdc-data-table__cell--icon img {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mdc-data-table__header-cell.mdc-data-table__header-cell--icon {
|
.mdc-data-table__header-cell.mdc-data-table__header-cell--icon {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@@ -745,7 +739,6 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mdc-data-table__cell--icon:first-child ha-icon,
|
.mdc-data-table__cell--icon:first-child ha-icon,
|
||||||
.mdc-data-table__cell--icon:first-child img,
|
|
||||||
.mdc-data-table__cell--icon:first-child ha-state-icon,
|
.mdc-data-table__cell--icon:first-child ha-state-icon,
|
||||||
.mdc-data-table__cell--icon:first-child ha-svg-icon {
|
.mdc-data-table__cell--icon:first-child ha-svg-icon {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
@@ -754,12 +747,7 @@ export class HaDataTable extends LitElement {
|
|||||||
:host([dir="rtl"])
|
:host([dir="rtl"])
|
||||||
.mdc-data-table__cell--icon:first-child
|
.mdc-data-table__cell--icon:first-child
|
||||||
ha-state-icon,
|
ha-state-icon,
|
||||||
:host([dir="rtl"])
|
:host([dir="rtl"]) .mdc-data-table__cell--icon:first-child ha-svg-icon {
|
||||||
.mdc-data-table__cell--icon:first-child
|
|
||||||
ha-svg-icon
|
|
||||||
:host([dir="rtl"])
|
|
||||||
.mdc-data-table__cell--icon:first-child
|
|
||||||
img {
|
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
@@ -33,10 +33,6 @@ const Component = Vue.extend({
|
|||||||
return new Date();
|
return new Date();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
firstDay: {
|
|
||||||
type: Number,
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
render(createElement) {
|
render(createElement) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -52,10 +48,6 @@ const Component = Vue.extend({
|
|||||||
disabled: this.disabled,
|
disabled: this.disabled,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
ranges: this.ranges ? {} : false,
|
ranges: this.ranges ? {} : false,
|
||||||
"locale-data": {
|
|
||||||
// @ts-ignore
|
|
||||||
firstDay: this.firstDay,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
model: {
|
model: {
|
||||||
value: {
|
value: {
|
||||||
@@ -111,14 +103,14 @@ class DateRangePickerElement extends WrappedElement {
|
|||||||
.daterangepicker {
|
.daterangepicker {
|
||||||
left: 0px !important;
|
left: 0px !important;
|
||||||
top: auto;
|
top: auto;
|
||||||
box-shadow: var(--ha-card-box-shadow, none);
|
|
||||||
background-color: var(--card-background-color);
|
background-color: var(--card-background-color);
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
border: none;
|
||||||
border-width: var(--ha-card-border-width, 1px);
|
border-radius: var(--ha-card-border-radius, 4px);
|
||||||
border-style: solid;
|
box-shadow: var(
|
||||||
border-color: var(
|
--ha-card-box-shadow,
|
||||||
--ha-card-border-color,
|
0px 2px 1px -1px rgba(0, 0, 0, 0.2),
|
||||||
var(--divider-color, #e0e0e0)
|
0px 1px 1px 0px rgba(0, 0, 0, 0.14),
|
||||||
|
0px 1px 3px 0px rgba(0, 0, 0, 0.12)
|
||||||
);
|
);
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
min-width: initial !important;
|
min-width: initial !important;
|
||||||
|
@@ -221,14 +221,12 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
public async open() {
|
public open() {
|
||||||
await this.updateComplete;
|
this.comboBox?.open();
|
||||||
await this.comboBox?.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async focus() {
|
public focus() {
|
||||||
await this.updateComplete;
|
this.comboBox?.focus();
|
||||||
await this.comboBox?.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
@@ -248,7 +246,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
(!this._init && this.devices && this.areas && this.entities) ||
|
(!this._init && this.devices && this.areas && this.entities) ||
|
||||||
(this._init && changedProps.has("_opened") && this._opened)
|
(changedProps.has("_opened") && this._opened)
|
||||||
) {
|
) {
|
||||||
this._init = true;
|
this._init = true;
|
||||||
(this.comboBox as any).items = this._getDevices(
|
(this.comboBox as any).items = this._getDevices(
|
||||||
@@ -264,6 +262,9 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
|
if (!this.devices || !this.areas || !this.entities) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@@ -107,14 +107,16 @@ export class HaEntityPicker extends LitElement {
|
|||||||
|
|
||||||
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
||||||
|
|
||||||
public async open() {
|
public open() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
await this.comboBox?.open();
|
this.comboBox?.open();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async focus() {
|
public focus() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
await this.comboBox?.focus();
|
this.comboBox?.focus();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _initedStates = false;
|
private _initedStates = false;
|
||||||
@@ -310,7 +312,6 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.filteredItems=${this._states}
|
.filteredItems=${this._states}
|
||||||
.renderer=${rowRenderer}
|
.renderer=${rowRenderer}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.disabled=${this.disabled}
|
|
||||||
@opened-changed=${this._openedChanged}
|
@opened-changed=${this._openedChanged}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@filter-changed=${this._filterChanged}
|
@filter-changed=${this._filterChanged}
|
||||||
|
@@ -7,8 +7,6 @@ import { getStates } from "../../common/entity/get_states";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "../ha-combo-box";
|
import "../ha-combo-box";
|
||||||
import type { HaComboBox } from "../ha-combo-box";
|
import type { HaComboBox } from "../ha-combo-box";
|
||||||
import { formatAttributeValue } from "../../data/entity_attributes";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
|
||||||
|
|
||||||
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
|
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
: formatAttributeValue(this.hass, key),
|
: key,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
@@ -71,7 +69,16 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._value}
|
.value=${this.value
|
||||||
|
? this.entityId && this.hass.states[this.entityId]
|
||||||
|
? computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
this.hass.states[this.entityId],
|
||||||
|
this.hass.locale,
|
||||||
|
this.value
|
||||||
|
)
|
||||||
|
: this.value
|
||||||
|
: ""}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label ??
|
.label=${this.label ??
|
||||||
this.hass.localize("ui.components.entity.entity-state-picker.state")}
|
this.hass.localize("ui.components.entity.entity-state-picker.state")}
|
||||||
@@ -88,28 +95,12 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _value() {
|
|
||||||
return this.value || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
private _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
||||||
this._opened = ev.detail.value;
|
this._opened = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
||||||
ev.stopPropagation();
|
this.value = ev.detail.value;
|
||||||
const newValue = ev.detail.value;
|
|
||||||
if (newValue !== this._value) {
|
|
||||||
this._setValue(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _setValue(value: string) {
|
|
||||||
this.value = value;
|
|
||||||
setTimeout(() => {
|
|
||||||
fireEvent(this, "value-changed", { value });
|
|
||||||
fireEvent(this, "change");
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@ import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
|||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
getNumberFormatOptions,
|
|
||||||
isNumericState,
|
isNumericState,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
@@ -150,11 +149,7 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
entityState.state === UNAVAILABLE
|
entityState.state === UNAVAILABLE
|
||||||
? "—"
|
? "—"
|
||||||
: isNumericState(entityState)
|
: isNumericState(entityState)
|
||||||
? formatNumber(
|
? formatNumber(entityState.state, this.hass!.locale)
|
||||||
entityState.state,
|
|
||||||
this.hass!.locale,
|
|
||||||
getNumberFormatOptions(entityState)
|
|
||||||
)
|
|
||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
entityState,
|
entityState,
|
||||||
|
@@ -3,14 +3,10 @@ import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/ensure-array";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { stringCompare } from "../../common/string/compare";
|
import { stringCompare } from "../../common/string/compare";
|
||||||
import {
|
import { getStatisticIds, StatisticsMetaData } from "../../data/history";
|
||||||
getStatisticIds,
|
|
||||||
getStatisticLabel,
|
|
||||||
StatisticsMetaData,
|
|
||||||
} from "../../data/recorder";
|
|
||||||
import { PolymerChangedEvent } from "../../polymer-types";
|
import { PolymerChangedEvent } from "../../polymer-types";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
@@ -43,21 +39,23 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
type: Array,
|
type: Array,
|
||||||
attribute: "include-statistics-unit-of-measurement",
|
attribute: "include-statistics-unit-of-measurement",
|
||||||
})
|
})
|
||||||
public includeStatisticsUnitOfMeasurement?: string | string[];
|
public includeStatisticsUnitOfMeasurement?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics with these unit classes.
|
* Show only statistics displayed with these units of measurements.
|
||||||
* @attr include-unit-class
|
* @type {Array}
|
||||||
|
* @attr include-display-unit-of-measurement
|
||||||
*/
|
*/
|
||||||
@property({ attribute: "include-unit-class" })
|
@property({ type: Array, attribute: "include-display-unit-of-measurement" })
|
||||||
public includeUnitClass?: string | string[];
|
public includeDisplayUnitOfMeasurement?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics with these device classes.
|
* Show only statistics with these device classes.
|
||||||
* @attr include-device-class
|
* @type {Array}
|
||||||
|
* @attr include-device-classes
|
||||||
*/
|
*/
|
||||||
@property({ attribute: "include-device-class" })
|
@property({ type: Array, attribute: "include-device-classes" })
|
||||||
public includeDeviceClass?: string | string[];
|
public includeDeviceClasses?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics on entities.
|
* Show only statistics on entities.
|
||||||
@@ -99,9 +97,9 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
private _getStatistics = memoizeOne(
|
private _getStatistics = memoizeOne(
|
||||||
(
|
(
|
||||||
statisticIds: StatisticsMetaData[],
|
statisticIds: StatisticsMetaData[],
|
||||||
includeStatisticsUnitOfMeasurement?: string | string[],
|
includeStatisticsUnitOfMeasurement?: string[],
|
||||||
includeUnitClass?: string | string[],
|
includeDisplayUnitOfMeasurement?: string[],
|
||||||
includeDeviceClass?: string | string[],
|
includeDeviceClasses?: string[],
|
||||||
entitiesOnly?: boolean
|
entitiesOnly?: boolean
|
||||||
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
||||||
if (!statisticIds.length) {
|
if (!statisticIds.length) {
|
||||||
@@ -116,33 +114,19 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeStatisticsUnitOfMeasurement) {
|
if (includeStatisticsUnitOfMeasurement) {
|
||||||
const includeUnits: (string | null)[] = ensureArray(
|
|
||||||
includeStatisticsUnitOfMeasurement
|
|
||||||
);
|
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeUnits.includes(meta.statistics_unit_of_measurement)
|
includeStatisticsUnitOfMeasurement.includes(
|
||||||
|
meta.statistics_unit_of_measurement
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (includeUnitClass) {
|
if (includeDisplayUnitOfMeasurement) {
|
||||||
const includeUnitClasses: (string | null)[] =
|
|
||||||
ensureArray(includeUnitClass);
|
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeUnitClasses.includes(meta.unit_class)
|
includeDisplayUnitOfMeasurement.includes(
|
||||||
|
meta.display_unit_of_measurement
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (includeDeviceClass) {
|
|
||||||
const includeDeviceClasses: (string | null)[] =
|
|
||||||
ensureArray(includeDeviceClass);
|
|
||||||
statisticIds = statisticIds.filter((meta) => {
|
|
||||||
const stateObj = this.hass.states[meta.statistic_id];
|
|
||||||
if (!stateObj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return includeDeviceClasses.includes(
|
|
||||||
stateObj.attributes.device_class || ""
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const output: Array<{
|
const output: Array<{
|
||||||
id: string;
|
id: string;
|
||||||
@@ -155,16 +139,23 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
if (!entitiesOnly) {
|
if (!entitiesOnly) {
|
||||||
output.push({
|
output.push({
|
||||||
id: meta.statistic_id,
|
id: meta.statistic_id,
|
||||||
name: getStatisticLabel(this.hass, meta.statistic_id, meta),
|
name: meta.name || meta.statistic_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!includeDeviceClasses ||
|
||||||
|
includeDeviceClasses.includes(
|
||||||
|
entityState!.attributes.device_class || ""
|
||||||
|
)
|
||||||
|
) {
|
||||||
output.push({
|
output.push({
|
||||||
id: meta.statistic_id,
|
id: meta.statistic_id,
|
||||||
name: getStatisticLabel(this.hass, meta.statistic_id, meta),
|
name: computeStateName(entityState),
|
||||||
state: entityState,
|
state: entityState,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!output.length) {
|
if (!output.length) {
|
||||||
@@ -215,8 +206,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
(this.comboBox as any).items = this._getStatistics(
|
(this.comboBox as any).items = this._getStatistics(
|
||||||
this.statisticIds!,
|
this.statisticIds!,
|
||||||
this.includeStatisticsUnitOfMeasurement,
|
this.includeStatisticsUnitOfMeasurement,
|
||||||
this.includeUnitClass,
|
this.includeDisplayUnitOfMeasurement,
|
||||||
this.includeDeviceClass,
|
this.includeDeviceClasses,
|
||||||
this.entitiesOnly
|
this.entitiesOnly
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -224,8 +215,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
(this.comboBox as any).items = this._getStatistics(
|
(this.comboBox as any).items = this._getStatistics(
|
||||||
this.statisticIds!,
|
this.statisticIds!,
|
||||||
this.includeStatisticsUnitOfMeasurement,
|
this.includeStatisticsUnitOfMeasurement,
|
||||||
this.includeUnitClass,
|
this.includeDisplayUnitOfMeasurement,
|
||||||
this.includeDeviceClass,
|
this.includeDeviceClasses,
|
||||||
this.entitiesOnly
|
this.entitiesOnly
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -22,59 +22,11 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
@property({ attribute: "pick-statistic-label" })
|
@property({ attribute: "pick-statistic-label" })
|
||||||
public pickStatisticLabel?: string;
|
public pickStatisticLabel?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only statistics natively stored with these units of measurements.
|
|
||||||
* @attr include-statistics-unit-of-measurement
|
|
||||||
*/
|
|
||||||
@property({
|
|
||||||
attribute: "include-statistics-unit-of-measurement",
|
|
||||||
})
|
|
||||||
public includeStatisticsUnitOfMeasurement?: string[] | string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only statistics with these unit classes.
|
|
||||||
* @attr include-unit-class
|
|
||||||
*/
|
|
||||||
@property({ attribute: "include-unit-class" })
|
|
||||||
public includeUnitClass?: string | string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only statistics with these device classes.
|
|
||||||
* @attr include-device-class
|
|
||||||
*/
|
|
||||||
@property({ attribute: "include-device-class" })
|
|
||||||
public includeDeviceClass?: string | string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ignore filtering of statistics type and units when only a single statistic is selected.
|
|
||||||
* @type {boolean}
|
|
||||||
* @attr ignore-restrictions-on-first-statistic
|
|
||||||
*/
|
|
||||||
@property({
|
|
||||||
type: Boolean,
|
|
||||||
attribute: "ignore-restrictions-on-first-statistic",
|
|
||||||
})
|
|
||||||
public ignoreRestrictionsOnFirstStatistic = false;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ignoreRestriction =
|
|
||||||
this.ignoreRestrictionsOnFirstStatistic &&
|
|
||||||
this._currentStatistics.length <= 1;
|
|
||||||
|
|
||||||
const includeStatisticsUnitCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.includeStatisticsUnitOfMeasurement;
|
|
||||||
const includeUnitClassCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.includeUnitClass;
|
|
||||||
const includeStatisticTypesCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.statisticTypes;
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this._currentStatistics.map(
|
${this._currentStatistics.map(
|
||||||
(statisticId) => html`
|
(statisticId) => html`
|
||||||
@@ -82,10 +34,8 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.curValue=${statisticId}
|
.curValue=${statisticId}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.includeStatisticsUnitOfMeasurement=${includeStatisticsUnitCurrent}
|
|
||||||
.includeUnitClass=${includeUnitClassCurrent}
|
|
||||||
.value=${statisticId}
|
.value=${statisticId}
|
||||||
.statisticTypes=${includeStatisticTypesCurrent}
|
.statisticTypes=${this.statisticTypes}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickedStatisticLabel}
|
.label=${this.pickedStatisticLabel}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
@@ -96,10 +46,6 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.includeStatisticsUnitOfMeasurement=${this
|
|
||||||
.includeStatisticsUnitOfMeasurement}
|
|
||||||
.includeUnitClass=${this.includeUnitClass}
|
|
||||||
.includeDeviceClass=${this.includeDeviceClass}
|
|
||||||
.statisticTypes=${this.statisticTypes}
|
.statisticTypes=${this.statisticTypes}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickStatisticLabel}
|
.label=${this.pickStatisticLabel}
|
||||||
|
@@ -116,14 +116,16 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async open() {
|
public open() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
await this.comboBox?.open();
|
this.comboBox?.open();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async focus() {
|
public focus() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
await this.comboBox?.focus();
|
this.comboBox?.focus();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getAreas = memoizeOne(
|
private _getAreas = memoizeOne(
|
||||||
@@ -288,7 +290,7 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
(!this._init && this._devices && this._areas && this._entities) ||
|
(!this._init && this._devices && this._areas && this._entities) ||
|
||||||
(this._init && changedProps.has("_opened") && this._opened)
|
(changedProps.has("_opened") && this._opened)
|
||||||
) {
|
) {
|
||||||
this._init = true;
|
this._init = true;
|
||||||
(this.comboBox as any).items = this._getAreas(
|
(this.comboBox as any).items = this._getAreas(
|
||||||
@@ -306,6 +308,9 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
|
if (!this._devices || !this._areas || !this._entities) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@@ -1,426 +0,0 @@
|
|||||||
import "hammerjs";
|
|
||||||
import {
|
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
PropertyValues,
|
|
||||||
TemplateResult,
|
|
||||||
} from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
|
||||||
import { classMap } from "lit/directives/class-map";
|
|
||||||
import { styleMap } from "lit/directives/style-map";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HASSDomEvents {
|
|
||||||
"slider-moved": { value?: number };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const A11Y_KEY_CODES = new Set([
|
|
||||||
"ArrowRight",
|
|
||||||
"ArrowUp",
|
|
||||||
"ArrowLeft",
|
|
||||||
"ArrowDown",
|
|
||||||
"PageUp",
|
|
||||||
"PageDown",
|
|
||||||
"Home",
|
|
||||||
"End",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const getPercentageFromEvent = (e: HammerInput, vertical: boolean) => {
|
|
||||||
if (vertical) {
|
|
||||||
const y = e.center.y;
|
|
||||||
const offset = e.target.getBoundingClientRect().top;
|
|
||||||
const total = e.target.clientHeight;
|
|
||||||
return Math.max(Math.min(1, 1 - (y - offset) / total), 0);
|
|
||||||
}
|
|
||||||
const x = e.center.x;
|
|
||||||
const offset = e.target.getBoundingClientRect().left;
|
|
||||||
const total = e.target.clientWidth;
|
|
||||||
return Math.max(Math.min(1, (x - offset) / total), 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
@customElement("ha-bar-slider")
|
|
||||||
export class HaBarSlider extends LitElement {
|
|
||||||
@property({ type: Boolean })
|
|
||||||
public disabled = false;
|
|
||||||
|
|
||||||
@property()
|
|
||||||
public mode?: "start" | "end" | "indicator" = "start";
|
|
||||||
|
|
||||||
@property({ type: Boolean })
|
|
||||||
public vertical = false;
|
|
||||||
|
|
||||||
@property({ type: Number })
|
|
||||||
public value?: number;
|
|
||||||
|
|
||||||
@property({ type: Number })
|
|
||||||
public step = 1;
|
|
||||||
|
|
||||||
@property({ type: Number })
|
|
||||||
public min = 0;
|
|
||||||
|
|
||||||
@property({ type: Number })
|
|
||||||
public max = 100;
|
|
||||||
|
|
||||||
@property()
|
|
||||||
public label?: string;
|
|
||||||
|
|
||||||
private _mc?: HammerManager;
|
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
|
||||||
public pressed = false;
|
|
||||||
|
|
||||||
valueToPercentage(value: number) {
|
|
||||||
return (value - this.min) / (this.max - this.min);
|
|
||||||
}
|
|
||||||
|
|
||||||
percentageToValue(value: number) {
|
|
||||||
return (this.max - this.min) * value + this.min;
|
|
||||||
}
|
|
||||||
|
|
||||||
steppedValue(value: number) {
|
|
||||||
return Math.round(value / this.step) * this.step;
|
|
||||||
}
|
|
||||||
|
|
||||||
boundedValue(value: number) {
|
|
||||||
return Math.min(Math.max(value, this.min), this.max);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
|
||||||
super.firstUpdated(changedProperties);
|
|
||||||
this.setupListeners();
|
|
||||||
this.setAttribute("role", "slider");
|
|
||||||
if (!this.hasAttribute("tabindex")) {
|
|
||||||
this.setAttribute("tabindex", "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
|
||||||
super.updated(changedProps);
|
|
||||||
if (changedProps.has("value")) {
|
|
||||||
const valuenow = this.steppedValue(this.value ?? 0);
|
|
||||||
this.setAttribute("aria-valuenow", valuenow.toString());
|
|
||||||
}
|
|
||||||
if (changedProps.has("min")) {
|
|
||||||
this.setAttribute("aria-valuemin", this.min.toString());
|
|
||||||
}
|
|
||||||
if (changedProps.has("max")) {
|
|
||||||
this.setAttribute("aria-valuemax", this.max.toString());
|
|
||||||
}
|
|
||||||
if (changedProps.has("vertical")) {
|
|
||||||
const orientation = this.vertical ? "vertical" : "horizontal";
|
|
||||||
this.setAttribute("aria-orientation", orientation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedCallback(): void {
|
|
||||||
super.connectedCallback();
|
|
||||||
this.setupListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnectedCallback(): void {
|
|
||||||
super.disconnectedCallback();
|
|
||||||
this.destroyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@query("#slider")
|
|
||||||
private slider;
|
|
||||||
|
|
||||||
setupListeners() {
|
|
||||||
if (this.slider && !this._mc) {
|
|
||||||
this._mc = new Hammer.Manager(this.slider, {
|
|
||||||
touchAction: this.vertical ? "pan-x" : "pan-y",
|
|
||||||
});
|
|
||||||
this._mc.add(
|
|
||||||
new Hammer.Pan({
|
|
||||||
threshold: 10,
|
|
||||||
direction: Hammer.DIRECTION_ALL,
|
|
||||||
enable: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
this._mc.add(new Hammer.Tap({ event: "singletap" }));
|
|
||||||
|
|
||||||
let savedValue;
|
|
||||||
this._mc.on("panstart", () => {
|
|
||||||
if (this.disabled) return;
|
|
||||||
this.pressed = true;
|
|
||||||
savedValue = this.value;
|
|
||||||
});
|
|
||||||
this._mc.on("pancancel", () => {
|
|
||||||
if (this.disabled) return;
|
|
||||||
this.pressed = false;
|
|
||||||
this.value = savedValue;
|
|
||||||
});
|
|
||||||
this._mc.on("panmove", (e) => {
|
|
||||||
if (this.disabled) return;
|
|
||||||
const percentage = getPercentageFromEvent(e, this.vertical);
|
|
||||||
this.value = this.percentageToValue(percentage);
|
|
||||||
const value = this.steppedValue(this.value);
|
|
||||||
fireEvent(this, "slider-moved", { value });
|
|
||||||
});
|
|
||||||
this._mc.on("panend", (e) => {
|
|
||||||
if (this.disabled) return;
|
|
||||||
this.pressed = false;
|
|
||||||
const percentage = getPercentageFromEvent(e, this.vertical);
|
|
||||||
this.value = this.steppedValue(this.percentageToValue(percentage));
|
|
||||||
fireEvent(this, "slider-moved", { value: undefined });
|
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
|
||||||
});
|
|
||||||
|
|
||||||
this._mc.on("singletap", (e) => {
|
|
||||||
if (this.disabled) return;
|
|
||||||
const percentage = getPercentageFromEvent(e, this.vertical);
|
|
||||||
this.value = this.steppedValue(this.percentageToValue(percentage));
|
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addEventListener("keydown", this._handleKeyDown);
|
|
||||||
this.addEventListener("keyup", this._handleKeyUp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destroyListeners() {
|
|
||||||
if (this._mc) {
|
|
||||||
this._mc.destroy();
|
|
||||||
this._mc = undefined;
|
|
||||||
}
|
|
||||||
this.removeEventListener("keydown", this._handleKeyDown);
|
|
||||||
this.removeEventListener("keyup", this._handleKeyDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
private get _tenPercentStep() {
|
|
||||||
return Math.max(this.step, (this.max - this.min) / 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
_handleKeyDown(e: KeyboardEvent) {
|
|
||||||
if (!A11Y_KEY_CODES.has(e.code)) return;
|
|
||||||
e.preventDefault();
|
|
||||||
switch (e.code) {
|
|
||||||
case "ArrowRight":
|
|
||||||
case "ArrowUp":
|
|
||||||
this.value = this.boundedValue((this.value ?? 0) + this.step);
|
|
||||||
break;
|
|
||||||
case "ArrowLeft":
|
|
||||||
case "ArrowDown":
|
|
||||||
this.value = this.boundedValue((this.value ?? 0) - this.step);
|
|
||||||
break;
|
|
||||||
case "PageUp":
|
|
||||||
this.value = this.steppedValue(
|
|
||||||
this.boundedValue((this.value ?? 0) + this._tenPercentStep)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "PageDown":
|
|
||||||
this.value = this.steppedValue(
|
|
||||||
this.boundedValue((this.value ?? 0) - this._tenPercentStep)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "Home":
|
|
||||||
this.value = this.min;
|
|
||||||
break;
|
|
||||||
case "End":
|
|
||||||
this.value = this.max;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fireEvent(this, "slider-moved", { value: this.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
_handleKeyUp(e: KeyboardEvent) {
|
|
||||||
if (!A11Y_KEY_CODES.has(e.code)) return;
|
|
||||||
e.preventDefault();
|
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<div
|
|
||||||
id="slider"
|
|
||||||
class="slider"
|
|
||||||
style=${styleMap({
|
|
||||||
"--value": `${this.valueToPercentage(this.value ?? 0)}`,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div class="slider-track-background"></div>
|
|
||||||
${this.mode === "indicator"
|
|
||||||
? html`
|
|
||||||
<div
|
|
||||||
class=${classMap({
|
|
||||||
"slider-track-indicator": true,
|
|
||||||
vertical: this.vertical,
|
|
||||||
})}
|
|
||||||
></div>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<div
|
|
||||||
class=${classMap({
|
|
||||||
"slider-track-bar": true,
|
|
||||||
vertical: this.vertical,
|
|
||||||
[this.mode ?? "start"]: true,
|
|
||||||
})}
|
|
||||||
></div>
|
|
||||||
`}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
|
||||||
return css`
|
|
||||||
:host {
|
|
||||||
display: block;
|
|
||||||
--slider-bar-color: rgb(var(--rgb-primary-color));
|
|
||||||
--slider-bar-background: rgba(var(--rgb-disabled-color), 0.2);
|
|
||||||
--slider-bar-thickness: 40px;
|
|
||||||
--slider-bar-border-radius: 12px;
|
|
||||||
height: var(--slider-bar-thickness);
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
:host([vertical]) {
|
|
||||||
width: var(--slider-bar-thickness);
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
.slider {
|
|
||||||
position: relative;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
border-radius: var(--slider-bar-border-radius);
|
|
||||||
transform: translateZ(0);
|
|
||||||
overflow: hidden;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.slider * {
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
.slider .slider-track-background {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
background: var(--slider-bar-background);
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar {
|
|
||||||
--border-radius: calc(var(--slider-bar-border-radius) / 2);
|
|
||||||
--handle-size: 4px;
|
|
||||||
--handle-margin: calc(var(--slider-bar-thickness) / 8);
|
|
||||||
position: absolute;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
background-color: var(--slider-bar-color);
|
|
||||||
transition: transform 180ms ease-in-out;
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar::after {
|
|
||||||
display: block;
|
|
||||||
content: "";
|
|
||||||
position: absolute;
|
|
||||||
margin: auto;
|
|
||||||
border-radius: var(--handle-size);
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar {
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
transform: translate3d(calc((var(--value, 0) - 1) * 100%), 0, 0);
|
|
||||||
border-radius: 0 var(--border-radius) var(--border-radius) 0;
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar:after {
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
right: var(--handle-margin);
|
|
||||||
height: 50%;
|
|
||||||
width: var(--handle-size);
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar.end {
|
|
||||||
right: 0;
|
|
||||||
left: initial;
|
|
||||||
transform: translate3d(calc(var(--value, 0) * 100%), 0, 0);
|
|
||||||
border-radius: var(--border-radius) 0 0 var(--border-radius);
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar.end::after {
|
|
||||||
right: initial;
|
|
||||||
left: var(--handle-margin);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider .slider-track-bar.vertical {
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
transform: translate3d(0, calc((1 - var(--value, 0)) * 100%), 0);
|
|
||||||
border-radius: var(--border-radius) var(--border-radius) 0 0;
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar.vertical:after {
|
|
||||||
top: var(--handle-margin);
|
|
||||||
right: 0;
|
|
||||||
left: 0;
|
|
||||||
bottom: initial;
|
|
||||||
width: 50%;
|
|
||||||
height: var(--handle-size);
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar.vertical.end {
|
|
||||||
top: 0;
|
|
||||||
bottom: initial;
|
|
||||||
transform: translate3d(0, calc((0 - var(--value, 0)) * 100%), 0);
|
|
||||||
border-radius: 0 0 var(--border-radius) var(--border-radius);
|
|
||||||
}
|
|
||||||
.slider .slider-track-bar.vertical.end::after {
|
|
||||||
top: initial;
|
|
||||||
bottom: var(--handle-margin);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider .slider-track-indicator:after {
|
|
||||||
display: block;
|
|
||||||
content: "";
|
|
||||||
background-color: rgb(var(--rgb-secondary-text-color));
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
bottom: 0;
|
|
||||||
right: 0;
|
|
||||||
margin: auto;
|
|
||||||
border-radius: var(--handle-size);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider .slider-track-indicator {
|
|
||||||
--indicator-size: calc(var(--slider-bar-thickness) / 4);
|
|
||||||
--handle-size: 4px;
|
|
||||||
position: absolute;
|
|
||||||
background-color: white;
|
|
||||||
border-radius: var(--handle-size);
|
|
||||||
transition: left 180ms ease-in-out, bottom 180ms ease-in-out;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: calc(var(--value, 0) * (100% - var(--indicator-size)));
|
|
||||||
width: var(--indicator-size);
|
|
||||||
}
|
|
||||||
.slider .slider-track-indicator:after {
|
|
||||||
height: 50%;
|
|
||||||
width: var(--handle-size);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider .slider-track-indicator.vertical {
|
|
||||||
top: initial;
|
|
||||||
right: 0;
|
|
||||||
left: 0;
|
|
||||||
bottom: calc(var(--value, 0) * (100% - var(--indicator-size)));
|
|
||||||
height: var(--indicator-size);
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.slider .slider-track-indicator.vertical:after {
|
|
||||||
height: var(--handle-size);
|
|
||||||
width: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
:host([pressed]) .slider-track-bar,
|
|
||||||
:host([pressed]) .slider-track-indicator {
|
|
||||||
transition: none;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-bar-slider": HaBarSlider;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -139,7 +139,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
.value=${this.days.toFixed()}
|
.value=${this.days.toFixed()}
|
||||||
.label=${this.dayLabel}
|
.label=${this.dayLabel}
|
||||||
name="days"
|
name="days"
|
||||||
@change=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
@focusin=${this._onFocus}
|
@focusin=${this._onFocus}
|
||||||
no-spinner
|
no-spinner
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
@@ -160,7 +160,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
.value=${this.hours.toFixed()}
|
.value=${this.hours.toFixed()}
|
||||||
.label=${this.hourLabel}
|
.label=${this.hourLabel}
|
||||||
name="hours"
|
name="hours"
|
||||||
@change=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
@focusin=${this._onFocus}
|
@focusin=${this._onFocus}
|
||||||
no-spinner
|
no-spinner
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
@@ -179,7 +179,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
inputmode="numeric"
|
inputmode="numeric"
|
||||||
.value=${this._formatValue(this.minutes)}
|
.value=${this._formatValue(this.minutes)}
|
||||||
.label=${this.minLabel}
|
.label=${this.minLabel}
|
||||||
@change=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
@focusin=${this._onFocus}
|
@focusin=${this._onFocus}
|
||||||
name="minutes"
|
name="minutes"
|
||||||
no-spinner
|
no-spinner
|
||||||
@@ -200,7 +200,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
inputmode="numeric"
|
inputmode="numeric"
|
||||||
.value=${this._formatValue(this.seconds)}
|
.value=${this._formatValue(this.seconds)}
|
||||||
.label=${this.secLabel}
|
.label=${this.secLabel}
|
||||||
@change=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
@focusin=${this._onFocus}
|
@focusin=${this._onFocus}
|
||||||
name="seconds"
|
name="seconds"
|
||||||
no-spinner
|
no-spinner
|
||||||
@@ -221,7 +221,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
type="number"
|
type="number"
|
||||||
.value=${this._formatValue(this.milliseconds, 3)}
|
.value=${this._formatValue(this.milliseconds, 3)}
|
||||||
.label=${this.millisecLabel}
|
.label=${this.millisecLabel}
|
||||||
@change=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
@focusin=${this._onFocus}
|
@focusin=${this._onFocus}
|
||||||
name="milliseconds"
|
name="milliseconds"
|
||||||
no-spinner
|
no-spinner
|
||||||
|
@@ -15,7 +15,6 @@ import {
|
|||||||
CAMERA_SUPPORT_STREAM,
|
CAMERA_SUPPORT_STREAM,
|
||||||
computeMJPEGStreamUrl,
|
computeMJPEGStreamUrl,
|
||||||
fetchStreamUrl,
|
fetchStreamUrl,
|
||||||
fetchThumbnailUrlWithCache,
|
|
||||||
STREAM_TYPE_HLS,
|
STREAM_TYPE_HLS,
|
||||||
STREAM_TYPE_WEB_RTC,
|
STREAM_TYPE_WEB_RTC,
|
||||||
} from "../data/camera";
|
} from "../data/camera";
|
||||||
@@ -24,7 +23,7 @@ import "./ha-hls-player";
|
|||||||
import "./ha-web-rtc-player";
|
import "./ha-web-rtc-player";
|
||||||
|
|
||||||
@customElement("ha-camera-stream")
|
@customElement("ha-camera-stream")
|
||||||
export class HaCameraStream extends LitElement {
|
class HaCameraStream extends LitElement {
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public stateObj?: CameraEntity;
|
@property({ attribute: false }) public stateObj?: CameraEntity;
|
||||||
@@ -38,9 +37,6 @@ export class HaCameraStream extends LitElement {
|
|||||||
@property({ type: Boolean, attribute: "allow-exoplayer" })
|
@property({ type: Boolean, attribute: "allow-exoplayer" })
|
||||||
public allowExoPlayer = false;
|
public allowExoPlayer = false;
|
||||||
|
|
||||||
// Video background image before its loaded
|
|
||||||
@state() private _posterUrl?: string;
|
|
||||||
|
|
||||||
// We keep track if we should force MJPEG if there was a failure
|
// We keep track if we should force MJPEG if there was a failure
|
||||||
// to get the HLS stream url. This is reset if we change entities.
|
// to get the HLS stream url. This is reset if we change entities.
|
||||||
@state() private _forceMJPEG?: string;
|
@state() private _forceMJPEG?: string;
|
||||||
@@ -55,16 +51,14 @@ export class HaCameraStream extends LitElement {
|
|||||||
!this._shouldRenderMJPEG &&
|
!this._shouldRenderMJPEG &&
|
||||||
this.stateObj &&
|
this.stateObj &&
|
||||||
(changedProps.get("stateObj") as CameraEntity | undefined)?.entity_id !==
|
(changedProps.get("stateObj") as CameraEntity | undefined)?.entity_id !==
|
||||||
this.stateObj.entity_id
|
this.stateObj.entity_id &&
|
||||||
|
this.stateObj!.attributes.frontend_stream_type === STREAM_TYPE_HLS
|
||||||
) {
|
) {
|
||||||
this._getPosterUrl();
|
|
||||||
if (this.stateObj!.attributes.frontend_stream_type === STREAM_TYPE_HLS) {
|
|
||||||
this._forceMJPEG = undefined;
|
this._forceMJPEG = undefined;
|
||||||
this._url = undefined;
|
this._url = undefined;
|
||||||
this._getStreamUrl();
|
this._getStreamUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
@@ -81,7 +75,7 @@ export class HaCameraStream extends LitElement {
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
if (__DEMO__ || this._shouldRenderMJPEG) {
|
if (__DEMO__ || this._shouldRenderMJPEG) {
|
||||||
return html`<img
|
return html` <img
|
||||||
.src=${__DEMO__
|
.src=${__DEMO__
|
||||||
? this.stateObj.attributes.entity_picture!
|
? this.stateObj.attributes.entity_picture!
|
||||||
: this._connected
|
: this._connected
|
||||||
@@ -100,7 +94,6 @@ export class HaCameraStream extends LitElement {
|
|||||||
.controls=${this.controls}
|
.controls=${this.controls}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.url=${this._url}
|
.url=${this._url}
|
||||||
.posterUrl=${this._posterUrl}
|
|
||||||
></ha-hls-player>`
|
></ha-hls-player>`
|
||||||
: html``;
|
: html``;
|
||||||
}
|
}
|
||||||
@@ -112,7 +105,6 @@ export class HaCameraStream extends LitElement {
|
|||||||
.controls=${this.controls}
|
.controls=${this.controls}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entityid=${this.stateObj.entity_id}
|
.entityid=${this.stateObj.entity_id}
|
||||||
.posterUrl=${this._posterUrl}
|
|
||||||
></ha-web-rtc-player>`;
|
></ha-web-rtc-player>`;
|
||||||
}
|
}
|
||||||
return html``;
|
return html``;
|
||||||
@@ -137,20 +129,6 @@ export class HaCameraStream extends LitElement {
|
|||||||
return !isComponentLoaded(this.hass!, "stream");
|
return !isComponentLoaded(this.hass!, "stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getPosterUrl(): Promise<void> {
|
|
||||||
try {
|
|
||||||
this._posterUrl = await fetchThumbnailUrlWithCache(
|
|
||||||
this.hass!,
|
|
||||||
this.stateObj!.entity_id,
|
|
||||||
this.clientWidth,
|
|
||||||
this.clientHeight
|
|
||||||
);
|
|
||||||
} catch (err: any) {
|
|
||||||
// poster url is optional
|
|
||||||
this._posterUrl = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _getStreamUrl(): Promise<void> {
|
private async _getStreamUrl(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const { url } = await fetchStreamUrl(
|
const { url } = await fetchStreamUrl(
|
||||||
|
@@ -5,7 +5,7 @@ import { customElement, property } from "lit/decorators";
|
|||||||
export class HaCard extends LitElement {
|
export class HaCard extends LitElement {
|
||||||
@property() public header?: string;
|
@property() public header?: string;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public raised = false;
|
@property({ type: Boolean, reflect: true }) public outlined = false;
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
@@ -14,14 +14,12 @@ export class HaCard extends LitElement {
|
|||||||
--ha-card-background,
|
--ha-card-background,
|
||||||
var(--card-background-color, white)
|
var(--card-background-color, white)
|
||||||
);
|
);
|
||||||
box-shadow: var(--ha-card-box-shadow, none);
|
border-radius: var(--ha-card-border-radius, 4px);
|
||||||
box-sizing: border-box;
|
box-shadow: var(
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
--ha-card-box-shadow,
|
||||||
border-width: var(--ha-card-border-width, 1px);
|
0px 2px 1px -1px rgba(0, 0, 0, 0.2),
|
||||||
border-style: solid;
|
0px 1px 1px 0px rgba(0, 0, 0, 0.14),
|
||||||
border-color: var(
|
0px 1px 3px 0px rgba(0, 0, 0, 0.12)
|
||||||
--ha-card-border-color,
|
|
||||||
var(--divider-color, #e0e0e0)
|
|
||||||
);
|
);
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
display: block;
|
display: block;
|
||||||
@@ -29,13 +27,13 @@ export class HaCard extends LitElement {
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([raised]) {
|
:host([outlined]) {
|
||||||
border: none;
|
box-shadow: none;
|
||||||
box-shadow: var(
|
border-width: var(--ha-card-border-width, 1px);
|
||||||
--ha-card-box-shadow,
|
border-style: solid;
|
||||||
0px 2px 1px -1px rgba(0, 0, 0, 0.2),
|
border-color: var(
|
||||||
0px 1px 1px 0px rgba(0, 0, 0, 0.14),
|
--ha-card-border-color,
|
||||||
0px 1px 3px 0px rgba(0, 0, 0, 0.12)
|
var(--divider-color, #e0e0e0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
|
import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
|
||||||
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
|
||||||
import "@vaadin/combo-box/theme/material/vaadin-combo-box-light";
|
import "@vaadin/combo-box/theme/material/vaadin-combo-box-light";
|
||||||
import type {
|
import type {
|
||||||
ComboBoxLight,
|
ComboBoxLight,
|
||||||
@@ -9,21 +8,14 @@ import type {
|
|||||||
ComboBoxLightValueChangedEvent,
|
ComboBoxLightValueChangedEvent,
|
||||||
} from "@vaadin/combo-box/vaadin-combo-box-light";
|
} from "@vaadin/combo-box/vaadin-combo-box-light";
|
||||||
import { registerStyles } from "@vaadin/vaadin-themable-mixin/register-styles";
|
import { registerStyles } from "@vaadin/vaadin-themable-mixin/register-styles";
|
||||||
import {
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
css,
|
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
||||||
CSSResultGroup,
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
PropertyValues,
|
|
||||||
TemplateResult,
|
|
||||||
} from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
import "./ha-textfield";
|
import "./ha-textfield";
|
||||||
import type { HaTextField } from "./ha-textfield";
|
|
||||||
|
|
||||||
registerStyles(
|
registerStyles(
|
||||||
"vaadin-combo-box-item",
|
"vaadin-combo-box-item",
|
||||||
@@ -109,19 +101,18 @@ export class HaComboBox extends LitElement {
|
|||||||
|
|
||||||
@query("vaadin-combo-box-light", true) private _comboBox!: ComboBoxLight;
|
@query("vaadin-combo-box-light", true) private _comboBox!: ComboBoxLight;
|
||||||
|
|
||||||
@query("ha-textfield", true) private _inputElement!: HaTextField;
|
|
||||||
|
|
||||||
private _overlayMutationObserver?: MutationObserver;
|
private _overlayMutationObserver?: MutationObserver;
|
||||||
|
|
||||||
public async open() {
|
public open() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
this._comboBox?.open();
|
this._comboBox?.open();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async focus() {
|
public focus() {
|
||||||
await this.updateComplete;
|
this.updateComplete.then(() => {
|
||||||
await this._inputElement?.updateComplete;
|
this._comboBox?.inputElement?.focus();
|
||||||
this._inputElement?.focus();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
@@ -234,13 +225,11 @@ export class HaComboBox extends LitElement {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, ev.type, ev.detail);
|
fireEvent(this, ev.type, ev.detail);
|
||||||
|
|
||||||
if (opened) {
|
if (
|
||||||
this.removeInertOnOverlay();
|
opened &&
|
||||||
}
|
"MutationObserver" in window &&
|
||||||
}
|
!this._overlayMutationObserver
|
||||||
|
) {
|
||||||
private removeInertOnOverlay() {
|
|
||||||
if ("MutationObserver" in window && !this._overlayMutationObserver) {
|
|
||||||
const overlay = document.querySelector<HTMLElement>(
|
const overlay = document.querySelector<HTMLElement>(
|
||||||
"vaadin-combo-box-overlay"
|
"vaadin-combo-box-overlay"
|
||||||
);
|
);
|
||||||
@@ -279,16 +268,6 @@ export class HaComboBox extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updated(changedProps: PropertyValues) {
|
|
||||||
super.updated(changedProps);
|
|
||||||
if (
|
|
||||||
changedProps.has("filteredItems") ||
|
|
||||||
(changedProps.has("items") && this.opened)
|
|
||||||
) {
|
|
||||||
this.removeInertOnOverlay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _filterChanged(ev: ComboBoxLightFilterChangedEvent) {
|
private _filterChanged(ev: ComboBoxLightFilterChangedEvent) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, ev.type, ev.detail, { composed: false });
|
fireEvent(this, ev.type, ev.detail, { composed: false });
|
||||||
@@ -299,7 +278,7 @@ export class HaComboBox extends LitElement {
|
|||||||
const newValue = ev.detail.value;
|
const newValue = ev.detail.value;
|
||||||
|
|
||||||
if (newValue !== this.value) {
|
if (newValue !== this.value) {
|
||||||
fireEvent(this, "value-changed", { value: newValue || undefined });
|
fireEvent(this, "value-changed", { value: newValue });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +290,6 @@ export class HaComboBox extends LitElement {
|
|||||||
}
|
}
|
||||||
vaadin-combo-box-light {
|
vaadin-combo-box-light {
|
||||||
position: relative;
|
position: relative;
|
||||||
--vaadin-combo-box-overlay-max-height: calc(45vh);
|
|
||||||
}
|
}
|
||||||
ha-textfield {
|
ha-textfield {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@@ -105,7 +105,7 @@ class HaConfigEntryPicker extends LitElement {
|
|||||||
|
|
||||||
private async _getConfigEntries() {
|
private async _getConfigEntries() {
|
||||||
getConfigEntries(this.hass, {
|
getConfigEntries(this.hass, {
|
||||||
type: ["device", "hub", "service"],
|
type: "integration",
|
||||||
domain: this.integration,
|
domain: this.integration,
|
||||||
}).then((configEntries) => {
|
}).then((configEntries) => {
|
||||||
this._configEntries = configEntries
|
this._configEntries = configEntries
|
||||||
|
@@ -3,14 +3,15 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { computeCloseIcon, computeOpenIcon } from "../common/entity/cover_icon";
|
import { computeCloseIcon, computeOpenIcon } from "../common/entity/cover_icon";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
|
||||||
import {
|
import {
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
|
||||||
isClosing,
|
isClosing,
|
||||||
isFullyClosed,
|
isFullyClosed,
|
||||||
isFullyOpen,
|
isFullyOpen,
|
||||||
isOpening,
|
isOpening,
|
||||||
|
supportsClose,
|
||||||
|
supportsOpen,
|
||||||
|
supportsStop,
|
||||||
} from "../data/cover";
|
} from "../data/cover";
|
||||||
import { UNAVAILABLE } from "../data/entity";
|
import { UNAVAILABLE } from "../data/entity";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
@@ -31,7 +32,7 @@ class HaCoverControls extends LitElement {
|
|||||||
<div class="state">
|
<div class="state">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.OPEN),
|
hidden: !supportsOpen(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.open_cover"
|
"ui.dialogs.more_info_control.cover.open_cover"
|
||||||
@@ -43,7 +44,7 @@ class HaCoverControls extends LitElement {
|
|||||||
</ha-icon-button>
|
</ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.STOP),
|
hidden: !supportsStop(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.stop_cover"
|
"ui.dialogs.more_info_control.cover.stop_cover"
|
||||||
@@ -54,7 +55,7 @@ class HaCoverControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.CLOSE),
|
hidden: !supportsClose(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.close_cover"
|
"ui.dialogs.more_info_control.cover.close_cover"
|
||||||
|
@@ -2,12 +2,13 @@ import { mdiArrowBottomLeft, mdiArrowTopRight, mdiStop } from "@mdi/js";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
|
||||||
import {
|
import {
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
|
||||||
isFullyClosedTilt,
|
isFullyClosedTilt,
|
||||||
isFullyOpenTilt,
|
isFullyOpenTilt,
|
||||||
|
supportsCloseTilt,
|
||||||
|
supportsOpenTilt,
|
||||||
|
supportsStopTilt,
|
||||||
} from "../data/cover";
|
} from "../data/cover";
|
||||||
import { UNAVAILABLE } from "../data/entity";
|
import { UNAVAILABLE } from "../data/entity";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
@@ -26,10 +27,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
|
|
||||||
return html` <ha-icon-button
|
return html` <ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsOpenTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.OPEN_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.open_tilt_cover"
|
"ui.dialogs.more_info_control.cover.open_tilt_cover"
|
||||||
@@ -40,10 +38,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsStopTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.STOP_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.stop_cover"
|
"ui.dialogs.more_info_control.cover.stop_cover"
|
||||||
@@ -54,10 +49,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsCloseTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.CLOSE_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.close_tilt_cover"
|
"ui.dialogs.more_info_control.cover.close_tilt_cover"
|
||||||
|
@@ -2,7 +2,6 @@ import { mdiCalendar } from "@mdi/js";
|
|||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { formatDateNumeric } from "../common/datetime/format_date";
|
import { formatDateNumeric } from "../common/datetime/format_date";
|
||||||
import { firstWeekdayIndex } from "../common/datetime/first_weekday";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
@@ -15,7 +14,6 @@ export interface datePickerDialogParams {
|
|||||||
min?: string;
|
min?: string;
|
||||||
max?: string;
|
max?: string;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
firstWeekday?: number;
|
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +67,6 @@ export class HaDateInput extends LitElement {
|
|||||||
value: this.value,
|
value: this.value,
|
||||||
onChange: (value) => this._valueChanged(value),
|
onChange: (value) => this._valueChanged(value),
|
||||||
locale: this.locale.language,
|
locale: this.locale.language,
|
||||||
firstWeekday: firstWeekdayIndex(this.locale),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,7 +14,6 @@ import {
|
|||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { formatDateTime } from "../common/datetime/format_date_time";
|
import { formatDateTime } from "../common/datetime/format_date_time";
|
||||||
import { useAmPm } from "../common/datetime/use_am_pm";
|
import { useAmPm } from "../common/datetime/use_am_pm";
|
||||||
import { firstWeekdayIndex } from "../common/datetime/first_weekday";
|
|
||||||
import { computeRTLDirection } from "../common/util/compute_rtl";
|
import { computeRTLDirection } from "../common/util/compute_rtl";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./date-range-picker";
|
import "./date-range-picker";
|
||||||
@@ -59,7 +58,6 @@ export class HaDateRangePicker extends LitElement {
|
|||||||
start-date=${this.startDate}
|
start-date=${this.startDate}
|
||||||
end-date=${this.endDate}
|
end-date=${this.endDate}
|
||||||
?ranges=${this.ranges !== undefined}
|
?ranges=${this.ranges !== undefined}
|
||||||
first-day=${firstWeekdayIndex(this.hass.locale)}
|
|
||||||
>
|
>
|
||||||
<div slot="input" class="date-range-inputs">
|
<div slot="input" class="date-range-inputs">
|
||||||
<ha-svg-icon .path=${mdiCalendar}></ha-svg-icon>
|
<ha-svg-icon .path=${mdiCalendar}></ha-svg-icon>
|
||||||
@@ -166,7 +164,7 @@ export class HaDateRangePicker extends LitElement {
|
|||||||
ha-textfield {
|
ha-textfield {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
min-width: 220px;
|
min-width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-textfield:last-child {
|
ha-textfield:last-child {
|
||||||
|
@@ -40,7 +40,6 @@ export class HaDialogDatePicker extends LitElement {
|
|||||||
.max=${this._params.max}
|
.max=${this._params.max}
|
||||||
.locale=${this._params.locale}
|
.locale=${this._params.locale}
|
||||||
@datepicker-value-updated=${this._valueChanged}
|
@datepicker-value-updated=${this._valueChanged}
|
||||||
.firstDayOfWeek=${this._params.firstWeekday}
|
|
||||||
></app-datepicker>
|
></app-datepicker>
|
||||||
<mwc-button slot="secondaryAction" @click=${this._setToday}
|
<mwc-button slot="secondaryAction" @click=${this._setToday}
|
||||||
>today</mwc-button
|
>today</mwc-button
|
||||||
@@ -57,8 +56,7 @@ export class HaDialogDatePicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setToday() {
|
private _setToday() {
|
||||||
// en-CA locale used for date format YYYY-MM-DD
|
this._value = new Date().toISOString().split("T")[0];
|
||||||
this._value = new Date().toLocaleDateString("en-CA");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue() {
|
private _setValue() {
|
||||||
|
@@ -55,7 +55,7 @@ export class HaDialog extends DialogBase {
|
|||||||
flex: var(--primary-action-button-flex, unset);
|
flex: var(--primary-action-button-flex, unset);
|
||||||
}
|
}
|
||||||
.mdc-dialog__container {
|
.mdc-dialog__container {
|
||||||
align-items: var(--vertical-align-dialog, center);
|
align-items: var(--vertial-align-dialog, center);
|
||||||
}
|
}
|
||||||
.mdc-dialog__title {
|
.mdc-dialog__title {
|
||||||
padding: 24px 24px 0 24px;
|
padding: 24px 24px 0 24px;
|
||||||
@@ -91,7 +91,7 @@ export class HaDialog extends DialogBase {
|
|||||||
.header_button {
|
.header_button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
top: 14px;
|
top: 10px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ export class HaExpansionPanel extends LitElement {
|
|||||||
--ha-card-border-color,
|
--ha-card-border-color,
|
||||||
var(--divider-color, #e0e0e0)
|
var(--divider-color, #e0e0e0)
|
||||||
);
|
);
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
border-radius: var(--ha-card-border-radius, 4px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-icon {
|
.summary-icon {
|
||||||
|
@@ -39,11 +39,11 @@ export const computeInitialHaFormData = (
|
|||||||
const selector: Selector = field.selector;
|
const selector: Selector = field.selector;
|
||||||
|
|
||||||
if ("device" in selector) {
|
if ("device" in selector) {
|
||||||
data[field.name] = selector.device?.multiple ? [] : "";
|
data[field.name] = selector.device.multiple ? [] : "";
|
||||||
} else if ("entity" in selector) {
|
} else if ("entity" in selector) {
|
||||||
data[field.name] = selector.entity?.multiple ? [] : "";
|
data[field.name] = selector.entity.multiple ? [] : "";
|
||||||
} else if ("area" in selector) {
|
} else if ("area" in selector) {
|
||||||
data[field.name] = selector.area?.multiple ? [] : "";
|
data[field.name] = selector.area.multiple ? [] : "";
|
||||||
} else if ("boolean" in selector) {
|
} else if ("boolean" in selector) {
|
||||||
data[field.name] = false;
|
data[field.name] = false;
|
||||||
} else if (
|
} else if (
|
||||||
@@ -56,9 +56,9 @@ export const computeInitialHaFormData = (
|
|||||||
) {
|
) {
|
||||||
data[field.name] = "";
|
data[field.name] = "";
|
||||||
} else if ("number" in selector) {
|
} else if ("number" in selector) {
|
||||||
data[field.name] = selector.number?.min ?? 0;
|
data[field.name] = selector.number.min ?? 0;
|
||||||
} else if ("select" in selector) {
|
} else if ("select" in selector) {
|
||||||
if (selector.select?.options.length) {
|
if (selector.select.options.length) {
|
||||||
data[field.name] = selector.select.options[0][0];
|
data[field.name] = selector.select.options[0][0];
|
||||||
}
|
}
|
||||||
} else if ("duration" in selector) {
|
} else if ("duration" in selector) {
|
||||||
@@ -75,7 +75,7 @@ export const computeInitialHaFormData = (
|
|||||||
} else if ("color_rgb" in selector) {
|
} else if ("color_rgb" in selector) {
|
||||||
data[field.name] = [0, 0, 0];
|
data[field.name] = [0, 0, 0];
|
||||||
} else if ("color_temp" in selector) {
|
} else if ("color_temp" in selector) {
|
||||||
data[field.name] = selector.color_temp?.min_mireds ?? 153;
|
data[field.name] = selector.color_temp.min_mireds ?? 153;
|
||||||
} else if (
|
} else if (
|
||||||
"action" in selector ||
|
"action" in selector ||
|
||||||
"media" in selector ||
|
"media" in selector ||
|
||||||
|
@@ -1,87 +0,0 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|
||||||
import { customElement, property } from "lit/decorators";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
|
||||||
import "./ha-form";
|
|
||||||
import type {
|
|
||||||
HaFormDataContainer,
|
|
||||||
HaFormElement,
|
|
||||||
HaFormExpandableSchema,
|
|
||||||
HaFormSchema,
|
|
||||||
} from "./types";
|
|
||||||
|
|
||||||
@customElement("ha-form-expandable")
|
|
||||||
export class HaFormExpendable extends LitElement implements HaFormElement {
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public data!: HaFormDataContainer;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public schema!: HaFormExpandableSchema;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property() public computeLabel?: (
|
|
||||||
schema: HaFormSchema,
|
|
||||||
data?: HaFormDataContainer
|
|
||||||
) => string;
|
|
||||||
|
|
||||||
@property() public computeHelper?: (schema: HaFormSchema) => string;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<ha-expansion-panel outlined .expanded=${Boolean(this.schema.expanded)}>
|
|
||||||
<div
|
|
||||||
slot="header"
|
|
||||||
role="heading"
|
|
||||||
aria-level=${this.schema.headingLevel?.toString() ?? "3"}
|
|
||||||
>
|
|
||||||
${this.schema.icon
|
|
||||||
? html` <ha-icon .icon=${this.schema.icon}></ha-icon> `
|
|
||||||
: this.schema.iconPath
|
|
||||||
? html` <ha-svg-icon .path=${this.schema.iconPath}></ha-svg-icon> `
|
|
||||||
: null}
|
|
||||||
${this.schema.title}
|
|
||||||
</div>
|
|
||||||
<div class="content">
|
|
||||||
<ha-form
|
|
||||||
.hass=${this.hass}
|
|
||||||
.data=${this.data}
|
|
||||||
.schema=${this.schema.schema}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.computeLabel=${this.computeLabel}
|
|
||||||
.computeHelper=${this.computeHelper}
|
|
||||||
></ha-form>
|
|
||||||
</div>
|
|
||||||
</ha-expansion-panel>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
|
||||||
return css`
|
|
||||||
:host {
|
|
||||||
display: flex !important;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
:host ha-form {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.content {
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
ha-expansion-panel {
|
|
||||||
display: block;
|
|
||||||
--expansion-panel-content-padding: 0;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
ha-svg-icon,
|
|
||||||
ha-icon {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-form-expandable": HaFormExpendable;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,9 +11,7 @@ export class HaFormFloat extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public data!: HaFormFloatData;
|
@property({ attribute: false }) public data!: HaFormFloatData;
|
||||||
|
|
||||||
@property() public label?: string;
|
@property() public label!: string;
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@@ -28,11 +26,8 @@ export class HaFormFloat extends LitElement implements HaFormElement {
|
|||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
type="numeric"
|
|
||||||
inputMode="decimal"
|
inputMode="decimal"
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
|
||||||
helperPersistent
|
|
||||||
.value=${this.data !== undefined ? this.data : ""}
|
.value=${this.data !== undefined ? this.data : ""}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.schema.required}
|
.required=${this.schema.required}
|
||||||
@@ -60,11 +55,6 @@ export class HaFormFloat extends LitElement implements HaFormElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow user to start typing a negative value
|
|
||||||
if (rawValue === "-") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rawValue !== "") {
|
if (rawValue !== "") {
|
||||||
value = parseFloat(rawValue);
|
value = parseFloat(rawValue);
|
||||||
if (isNaN(value)) {
|
if (isNaN(value)) {
|
||||||
|
@@ -33,6 +33,11 @@ export class HaFormGrid extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property() public computeHelper?: (schema: HaFormSchema) => string;
|
@property() public computeHelper?: (schema: HaFormSchema) => string;
|
||||||
|
|
||||||
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
this.setAttribute("own-margin", "");
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues): void {
|
protected updated(changedProps: PropertyValues): void {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
if (changedProps.has("schema")) {
|
if (changedProps.has("schema")) {
|
||||||
@@ -73,11 +78,11 @@ export class HaFormGrid extends LitElement implements HaFormElement {
|
|||||||
var(--form-grid-column-count, auto-fit),
|
var(--form-grid-column-count, auto-fit),
|
||||||
minmax(var(--form-grid-min-width, 200px), 1fr)
|
minmax(var(--form-grid-min-width, 200px), 1fr)
|
||||||
);
|
);
|
||||||
grid-column-gap: 8px;
|
grid-gap: 8px;
|
||||||
grid-row-gap: 24px;
|
|
||||||
}
|
}
|
||||||
:host > ha-form {
|
:host > ha-form {
|
||||||
display: block;
|
display: block;
|
||||||
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@@ -21,8 +21,6 @@ export class HaFormInteger extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@query("ha-textfield ha-slider") private _input?:
|
@query("ha-textfield ha-slider") private _input?:
|
||||||
@@ -76,8 +74,6 @@ export class HaFormInteger extends LitElement implements HaFormElement {
|
|||||||
type="number"
|
type="number"
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
|
||||||
helperPersistent
|
|
||||||
.value=${this.data !== undefined ? this.data : ""}
|
.value=${this.data !== undefined ? this.data : ""}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.schema.required}
|
.required=${this.schema.required}
|
||||||
|
@@ -19,9 +19,7 @@ export class HaFormSelect extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property() public data!: HaFormSelectData;
|
@property() public data!: HaFormSelectData;
|
||||||
|
|
||||||
@property() public label?: string;
|
@property() public label!: string;
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ export class HaFormSelect extends LitElement implements HaFormElement {
|
|||||||
.schema=${this.schema}
|
.schema=${this.schema}
|
||||||
.value=${this.data}
|
.value=${this.data}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.schema.required}
|
.required=${this.schema.required}
|
||||||
.selector=${this._selectSchema(this.schema.options)}
|
.selector=${this._selectSchema(this.schema.options)}
|
||||||
|
@@ -60,8 +60,6 @@ export class HaFormString extends LitElement implements HaFormElement {
|
|||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.schema.required}
|
.required=${this.schema.required}
|
||||||
.autoValidate=${this.schema.required}
|
.autoValidate=${this.schema.required}
|
||||||
.name=${this.schema.name}
|
|
||||||
.autocomplete=${this.schema.autocomplete}
|
|
||||||
.suffix=${isPassword
|
.suffix=${isPassword
|
||||||
? // reserve some space for the icon.
|
? // reserve some space for the icon.
|
||||||
html`<div style="width: 24px"></div>`
|
html`<div style="width: 24px"></div>`
|
||||||
|
@@ -1,27 +1,34 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import {
|
||||||
|
css,
|
||||||
|
CSSResultGroup,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
PropertyValues,
|
||||||
|
TemplateResult,
|
||||||
|
} from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { HomeAssistant } from "../../types";
|
|
||||||
import "../ha-alert";
|
import "../ha-alert";
|
||||||
import "../ha-selector/ha-selector";
|
|
||||||
import "./ha-form-boolean";
|
import "./ha-form-boolean";
|
||||||
import "./ha-form-constant";
|
import "./ha-form-constant";
|
||||||
import "./ha-form-float";
|
|
||||||
import "./ha-form-grid";
|
import "./ha-form-grid";
|
||||||
import "./ha-form-expandable";
|
import "./ha-form-float";
|
||||||
import "./ha-form-integer";
|
import "./ha-form-integer";
|
||||||
import "./ha-form-multi_select";
|
import "./ha-form-multi_select";
|
||||||
import "./ha-form-positive_time_period_dict";
|
import "./ha-form-positive_time_period_dict";
|
||||||
import "./ha-form-select";
|
import "./ha-form-select";
|
||||||
import "./ha-form-string";
|
import "./ha-form-string";
|
||||||
import { HaFormDataContainer, HaFormElement, HaFormSchema } from "./types";
|
import { HaFormElement, HaFormDataContainer, HaFormSchema } from "./types";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
const getValue = (obj, item) =>
|
const getValue = (obj, item) =>
|
||||||
obj ? (!item.name ? obj : obj[item.name]) : null;
|
obj ? (!item.name ? obj : obj[item.name]) : null;
|
||||||
|
|
||||||
const getError = (obj, item) => (obj && item.name ? obj[item.name] : null);
|
const getError = (obj, item) => (obj && item.name ? obj[item.name] : null);
|
||||||
|
|
||||||
|
let selectorImported = false;
|
||||||
|
|
||||||
@customElement("ha-form")
|
@customElement("ha-form")
|
||||||
export class HaForm extends LitElement implements HaFormElement {
|
export class HaForm extends LitElement implements HaFormElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -56,6 +63,18 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
willUpdate(changedProperties: PropertyValues) {
|
||||||
|
super.willUpdate(changedProperties);
|
||||||
|
if (
|
||||||
|
!selectorImported &&
|
||||||
|
changedProperties.has("schema") &&
|
||||||
|
this.schema?.some((item) => "selector" in item)
|
||||||
|
) {
|
||||||
|
selectorImported = true;
|
||||||
|
import("../ha-selector/ha-selector");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="root" part="root">
|
<div class="root" part="root">
|
||||||
@@ -81,7 +100,6 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
? html`<ha-selector
|
? html`<ha-selector
|
||||||
.schema=${item}
|
.schema=${item}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.name=${item.name}
|
|
||||||
.selector=${item.selector}
|
.selector=${item.selector}
|
||||||
.value=${getValue(this.data, item)}
|
.value=${getValue(this.data, item)}
|
||||||
.label=${this._computeLabel(item, this.data)}
|
.label=${this._computeLabel(item, this.data)}
|
||||||
@@ -94,7 +112,6 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
schema: item,
|
schema: item,
|
||||||
data: getValue(this.data, item),
|
data: getValue(this.data, item),
|
||||||
label: this._computeLabel(item, this.data),
|
label: this._computeLabel(item, this.data),
|
||||||
helper: this._computeHelper(item),
|
|
||||||
disabled: this.disabled,
|
disabled: this.disabled,
|
||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
computeLabel: this.computeLabel,
|
computeLabel: this.computeLabel,
|
||||||
@@ -157,10 +174,14 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
|
.root {
|
||||||
|
margin-bottom: -24px;
|
||||||
|
overflow: clip visible;
|
||||||
|
}
|
||||||
.root > * {
|
.root > * {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
.root > *:not([own-margin]):not(:last-child) {
|
.root > *:not([own-margin]) {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
ha-alert[own-margin] {
|
ha-alert[own-margin] {
|
||||||
|
@@ -12,8 +12,7 @@ export type HaFormSchema =
|
|||||||
| HaFormMultiSelectSchema
|
| HaFormMultiSelectSchema
|
||||||
| HaFormTimeSchema
|
| HaFormTimeSchema
|
||||||
| HaFormSelector
|
| HaFormSelector
|
||||||
| HaFormGridSchema
|
| HaFormGridSchema;
|
||||||
| HaFormExpandableSchema;
|
|
||||||
|
|
||||||
export interface HaFormBaseSchema {
|
export interface HaFormBaseSchema {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -35,17 +34,6 @@ export interface HaFormGridSchema extends HaFormBaseSchema {
|
|||||||
schema: readonly HaFormSchema[];
|
schema: readonly HaFormSchema[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HaFormExpandableSchema extends HaFormBaseSchema {
|
|
||||||
type: "expandable";
|
|
||||||
name: "";
|
|
||||||
title: string;
|
|
||||||
icon?: string;
|
|
||||||
iconPath?: string;
|
|
||||||
expanded?: boolean;
|
|
||||||
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
||||||
schema: readonly HaFormSchema[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface HaFormSelector extends HaFormBaseSchema {
|
export interface HaFormSelector extends HaFormBaseSchema {
|
||||||
type?: never;
|
type?: never;
|
||||||
selector: Selector;
|
selector: Selector;
|
||||||
@@ -83,7 +71,6 @@ export interface HaFormFloatSchema extends HaFormBaseSchema {
|
|||||||
export interface HaFormStringSchema extends HaFormBaseSchema {
|
export interface HaFormStringSchema extends HaFormBaseSchema {
|
||||||
type: "string";
|
type: "string";
|
||||||
format?: string;
|
format?: string;
|
||||||
autocomplete?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HaFormBooleanSchema extends HaFormBaseSchema {
|
export interface HaFormBooleanSchema extends HaFormBaseSchema {
|
||||||
@@ -98,9 +85,7 @@ export interface HaFormTimeSchema extends HaFormBaseSchema {
|
|||||||
export type SchemaUnion<
|
export type SchemaUnion<
|
||||||
SchemaArray extends readonly HaFormSchema[],
|
SchemaArray extends readonly HaFormSchema[],
|
||||||
Schema = SchemaArray[number]
|
Schema = SchemaArray[number]
|
||||||
> = Schema extends HaFormGridSchema | HaFormExpandableSchema
|
> = Schema extends HaFormGridSchema ? SchemaUnion<Schema["schema"]> : Schema;
|
||||||
? SchemaUnion<Schema["schema"]>
|
|
||||||
: Schema;
|
|
||||||
|
|
||||||
export interface HaFormDataContainer {
|
export interface HaFormDataContainer {
|
||||||
[key: string]: HaFormData;
|
[key: string]: HaFormData;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user