Skip to content

Commit

Permalink
20231208.1 (#18962)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Dec 8, 2023
2 parents fce4e5e + 61117bb commit aa38e2d
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 237 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@webcomponents/scoped-custom-element-registry": "0.0.9",
"@webcomponents/webcomponentsjs": "2.8.0",
"app-datepicker": "5.1.1",
"chart.js": "4.4.0",
"chart.js": "4.4.1",
"comlink": "4.4.1",
"core-js": "3.33.3",
"cropperjs": "1.6.1",
Expand Down Expand Up @@ -176,16 +176,16 @@
"@types/js-yaml": "4.0.9",
"@types/leaflet": "1.9.8",
"@types/leaflet-draw": "1.0.11",
"@types/luxon": "3.3.6",
"@types/luxon": "3.3.7",
"@types/mocha": "10.0.6",
"@types/qrcode": "1.5.5",
"@types/serve-handler": "6.1.4",
"@types/sortablejs": "1.15.7",
"@types/tar": "6.1.10",
"@types/ua-parser-js": "0.7.39",
"@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "6.13.1",
"@typescript-eslint/parser": "6.13.1",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"@web/dev-server": "0.1.38",
"@web/dev-server-rollup": "0.4.1",
"babel-loader": "9.1.3",
Expand Down Expand Up @@ -216,7 +216,7 @@
"husky": "8.0.3",
"instant-mocha": "1.5.2",
"jszip": "3.10.1",
"lint-staged": "15.1.0",
"lint-staged": "15.2.0",
"lit-analyzer": "2.0.1",
"lodash.template": "4.5.0",
"magic-string": "0.30.5",
Expand All @@ -229,7 +229,7 @@
"rollup": "2.79.1",
"rollup-plugin-string": "3.0.0",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-visualizer": "5.9.3",
"rollup-plugin-visualizer": "5.10.0",
"serve-handler": "6.1.5",
"sinon": "17.0.1",
"source-map-url": "0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "home-assistant-frontend"
version = "20231206.0"
version = "20231208.1"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
17 changes: 8 additions & 9 deletions src/common/entity/compute_attribute_display.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HassConfig, HassEntity } from "home-assistant-js-websocket";
import {
DOMAIN_ATTRIBUTES_FORMATERS,
DOMAIN_ATTRIBUTES_UNITS,
TEMPERATURE_ATTRIBUTES,
} from "../../data/entity_attributes";
Expand All @@ -14,11 +15,10 @@ import { formatNumber } from "../number/format_number";
import { capitalizeFirstLetter } from "../string/capitalize-first-letter";
import { isDate } from "../string/is_date";
import { isTimestamp } from "../string/is_timestamp";
import { blankBeforePercent } from "../translations/blank_before_percent";
import { blankBeforeUnit } from "../translations/blank_before_unit";
import { LocalizeFunc } from "../translations/localize";
import { computeDomain } from "./compute_domain";
import { computeStateDomain } from "./compute_state_domain";
import { blankBeforeUnit } from "../translations/blank_before_unit";

export const computeAttributeValueDisplay = (
localize: LocalizeFunc,
Expand All @@ -39,19 +39,18 @@ export const computeAttributeValueDisplay = (

// Number value, return formatted number
if (typeof attributeValue === "number") {
const formattedValue = formatNumber(attributeValue, locale);

const domain = computeStateDomain(stateObj);

const formatter = DOMAIN_ATTRIBUTES_FORMATERS[domain]?.[attribute];

const formattedValue = formatter
? formatter(attributeValue, locale)
: formatNumber(attributeValue, locale);

let unit = DOMAIN_ATTRIBUTES_UNITS[domain]?.[attribute] as
| string
| undefined;

if (domain === "light" && attribute === "brightness") {
const percentage = Math.round((attributeValue / 255) * 100);
return `${percentage}${blankBeforePercent(locale)}%`;
}

if (domain === "weather") {
unit = getWeatherUnit(config, stateObj as WeatherEntity, attribute);
}
Expand Down
11 changes: 4 additions & 7 deletions src/components/device/ha-device-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ScorableTextItem,
fuzzyFilterSort,
} from "../../common/string/filter/sequence-matching";
import { AreaRegistryEntry } from "../../data/area_registry";
import {
DeviceEntityDisplayLookup,
DeviceRegistryEntry,
Expand Down Expand Up @@ -102,7 +101,7 @@ export class HaDevicePicker extends LitElement {
private _getDevices = memoizeOne(
(
devices: DeviceRegistryEntry[],
areas: AreaRegistryEntry[],
areas: HomeAssistant["areas"],
entities: EntityRegistryDisplayEntry[],
includeDomains: this["includeDomains"],
excludeDomains: this["excludeDomains"],
Expand Down Expand Up @@ -133,8 +132,6 @@ export class HaDevicePicker extends LitElement {
deviceEntityLookup = getDeviceEntityDisplayLookup(entities);
}

const areaLookup = areas;

let inputDevices = devices.filter(
(device) => device.id === this.value || !device.disabled_by
);
Expand Down Expand Up @@ -224,8 +221,8 @@ export class HaDevicePicker extends LitElement {
id: device.id,
name: name,
area:
device.area_id && areaLookup[device.area_id]
? areaLookup[device.area_id].name
device.area_id && areas[device.area_id]
? areas[device.area_id].name
: this.hass.localize("ui.components.device-picker.no_area"),
strings: [name || ""],
};
Expand Down Expand Up @@ -267,7 +264,7 @@ export class HaDevicePicker extends LitElement {
this._init = true;
const devices = this._getDevices(
Object.values(this.hass.devices),
Object.values(this.hass.areas),
this.hass.areas,
Object.values(this.hass.entities),
this.includeDomains,
this.excludeDomains,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-selector/ha-selector-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class HaNumberSelector extends LitElement {

protected willUpdate(changedProps: PropertyValues) {
if (changedProps.has("value")) {
if (this.value !== Number(this._valueStr)) {
if (this._valueStr === "" || this.value !== Number(this._valueStr)) {
this._valueStr =
!this.value || isNaN(this.value) ? "" : this.value.toString();
this.value == null || isNaN(this.value) ? "" : this.value.toString();
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/data/entity_attributes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { formatDuration } from "../common/datetime/duration";
import { FrontendLocaleData } from "./translation";

export const STATE_ATTRIBUTES = [
"entity_id",
"assumed_state",
Expand Down Expand Up @@ -64,6 +67,7 @@ export const DOMAIN_ATTRIBUTES_UNITS = {
color_temp_kelvin: "K",
min_color_temp_kelvin: "K",
max_color_temp_kelvin: "K",
brightness: "%",
},
sun: {
elevation: "°",
Expand All @@ -74,4 +78,22 @@ export const DOMAIN_ATTRIBUTES_UNITS = {
sensor: {
battery_level: "%",
},
media_player: {
volume_level: "%",
},
} as const satisfies Record<string, Record<string, string>>;

type Formatter = (value: number, locale: FrontendLocaleData) => string;

export const DOMAIN_ATTRIBUTES_FORMATERS: Record<
string,
Record<string, Formatter>
> = {
light: {
brightness: (value) => Math.round((value / 255) * 100).toString(),
},
media_player: {
volume_level: (value) => Math.round(value * 100).toString(),
media_duration: (value) => formatDuration(value.toString(), "s"),
},
};
7 changes: 0 additions & 7 deletions src/dialogs/config-flow/dialog-data-entry-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,6 @@ class DataEntryFlowDialog extends LitElement {
);
}
);
if (this._step?.flow_id) {
await this._unsubDataEntryFlowProgressed;
// fetch flow after we subscribe to the event, so we don't miss the first event
this._processStep(
this._params!.flowConfig.fetchFlow(this.hass, this._step.flow_id)
);
}
}

static get styles(): CSSResultGroup {
Expand Down
9 changes: 2 additions & 7 deletions src/html/authorize.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
width: 100%;
max-width: 400px;
margin: 0 auto;
box-sizing: border-box;
padding: 0 16px;
box-sizing: content-box;
}

.header {
Expand All @@ -40,12 +41,6 @@
height: 56px;
width: 56px;
}

@media (max-width: 592px) {
.content {
margin: 0 16px;
}
}
</style>
</head>
<body>
Expand Down
9 changes: 2 additions & 7 deletions src/html/onboarding.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
.content {
max-width: 560px;
margin: 0 auto;
box-sizing: border-box;
padding: 0 16px;
box-sizing: content-box;
}

.header {
Expand All @@ -36,12 +37,6 @@
height: 56px;
width: 56px;
}

@media (max-width: 592px) {
.content {
margin: 0 16px;
}
}
</style>
</head>
<body id="particles">
Expand Down
Loading

0 comments on commit aa38e2d

Please sign in to comment.