Skip to content

Commit

Permalink
20230801.0 (#17450)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Aug 1, 2023
2 parents 626b511 + f792e70 commit a181189
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 222 deletions.
30 changes: 14 additions & 16 deletions demo/src/stubs/config_entries.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";

export const mockConfigEntries = (hass: MockHomeAssistant) => {
hass.mockWS("config_entries/get_matching", () => [
{
entry_id: "co2signal",
domain: "co2signal",
title: "CO2 Signal",
source: "user",
state: "loaded",
supports_options: false,
supports_remove_device: false,
supports_unload: true,
pref_disable_new_entities: false,
pref_disable_polling: false,
disabled_by: null,
reason: null,
},
]);
hass.mockWS("config_entries/get", () => ({
entry_id: "co2signal",
domain: "co2signal",
title: "Electricity Maps",
source: "user",
state: "loaded",
supports_options: false,
supports_remove_device: false,
supports_unload: true,
pref_disable_new_entities: false,
pref_disable_polling: false,
disabled_by: null,
reason: null,
}));
};
26 changes: 15 additions & 11 deletions demo/src/stubs/persistent_notification.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { PersistentNotification } from "../../../src/data/persistent_notification";
import { PersistentNotificationMessage } from "../../../src/data/persistent_notification";
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";

export const mockPersistentNotification = (hass: MockHomeAssistant) => {
hass.mockWS("persistent_notification/get", () =>
Promise.resolve([
{
created_at: new Date().toISOString(),
message: "There was motion detected in the backyard.",
notification_id: "demo-1",
title: "Motion Detected!",
status: "unread",
hass.mockWS("persistent_notification/subscribe", (_msg, _hass, onChange) => {
onChange!({
type: "added",
notifications: {
"demo-1": {
created_at: new Date().toISOString(),
message: "There was motion detected in the backyard.",
notification_id: "demo-1",
title: "Motion Detected!",
status: "unread",
},
},
] as PersistentNotification[])
);
} as PersistentNotificationMessage);
return () => {};
});
};
6 changes: 4 additions & 2 deletions demo/src/stubs/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const generateSumStatistics = (
min: null,
max: null,
last_reset: 0,
change: add,
state: initValue + sum,
sum,
});
Expand Down Expand Up @@ -103,15 +104,16 @@ const generateCurvedStatistics = (
let half = false;
const now = new Date();
while (end > currentDate && currentDate < now) {
const add = Math.random() * maxDiff;
sum += i * add;
const add = i * (Math.random() * maxDiff);
sum += add;
statistics.push({
start: currentDate.getTime(),
end: currentDate.getTime(),
mean: null,
min: null,
max: null,
last_reset: 0,
change: add,
state: initValue + sum,
sum: metered ? sum : null,
});
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@
"@types/sortablejs": "1.15.1",
"@types/tar": "6.1.5",
"@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "6.1.0",
"@typescript-eslint/parser": "6.1.0",
"@typescript-eslint/eslint-plugin": "6.2.0",
"@typescript-eslint/parser": "6.2.0",
"@web/dev-server": "0.1.38",
"@web/dev-server-rollup": "0.4.1",
"babel-loader": "9.1.3",
"babel-plugin-template-html-minifier": "4.1.0",
"chai": "4.3.7",
"del": "7.0.0",
"eslint": "8.45.0",
"eslint": "8.46.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "8.8.0",
"eslint-config-prettier": "8.9.0",
"eslint-import-resolver-webpack": "0.13.2",
"eslint-plugin-disable": "2.0.3",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-lit": "1.8.3",
"eslint-plugin-lit-a11y": "3.0.0",
"eslint-plugin-unused-imports": "3.0.0",
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 = "20230725.0"
version = "20230801.0"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
6 changes: 5 additions & 1 deletion src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ export const DOMAINS_TOGGLE = new Set([
]);

/** Domains that have a dynamic entity image / picture. */
export const DOMAINS_WITH_DYNAMIC_PICTURE = new Set(["camera", "media_player"]);
export const DOMAINS_WITH_DYNAMIC_PICTURE = new Set([
"camera",
"image",
"media_player",
]);

/** Temperature units. */
export const UNIT_C = "°C";
Expand Down
5 changes: 4 additions & 1 deletion src/common/entity/compute_attribute_display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export const computeAttributeValueDisplay = (
// If invalid URL, exception will be raised
const url = new URL(attributeValue);
if (url.protocol === "http:" || url.protocol === "https:")
return html`<a target="_blank" rel="noreferrer" href=${attributeValue}
return html`<a
target="_blank"
rel="noopener noreferrer"
href=${attributeValue}
>${attributeValue}</a
>`;
} catch (_) {
Expand Down
10 changes: 9 additions & 1 deletion src/common/entity/get_states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ export const FIXED_DOMAIN_STATES = {
input_button: [],
light: ["on", "off"],
lock: ["jammed", "locked", "locking", "unlocked", "unlocking"],
media_player: ["idle", "off", "paused", "playing", "standby"],
media_player: [
"off",
"on",
"idle",
"playing",
"paused",
"standby",
"buffering",
],
person: ["home", "not_home"],
plant: ["ok", "problem"],
remote: ["on", "off"],
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-selector/ha-selector-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HaNumberSelector extends LitElement {
${!isBox
? html`
${this.label
? html`${this.label}${this.required ? " *" : ""}`
? html`${this.label}${this.required ? "*" : ""}`
: ""}
<ha-slider
.min=${this.selector.number?.min}
Expand Down
4 changes: 1 addition & 3 deletions src/components/ha-selector/ha-selector-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export class HaTemplateSelector extends LitElement {

protected render() {
return html`
${this.label
? html`<p>${this.label}${this.required ? " *" : ""}</p>`
: ""}
${this.label ? html`<p>${this.label}${this.required ? "*" : ""}</p>` : ""}
<ha-code-editor
mode="jinja2"
.hass=${this.hass}
Expand Down
27 changes: 16 additions & 11 deletions src/data/logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export const createHistoricState = (
attributes: {
// Rebuild the historical state by copying static attributes only
device_class: currentStateObj?.attributes.device_class,
event_type: currentStateObj?.attributes.event_type,
source_type: currentStateObj?.attributes.source_type,
has_date: currentStateObj?.attributes.has_date,
has_time: currentStateObj?.attributes.has_time,
Expand Down Expand Up @@ -346,16 +345,22 @@ export const localizeStateMessage = (
break;

case "event": {
const event_type =
computeAttributeValueDisplay(
hass!.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
"event_type"
)?.toString() ||
localize(`${LOGBOOK_LOCALIZE_PATH}.detected_unknown_event`);
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_event_no_type`);

// TODO: This is not working yet, as we don't get historic attribute values

const event_type = computeAttributeValueDisplay(
hass!.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
"event_type"
)?.toString();

if (!event_type) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_unknown_event`);
}

return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_event`, {
event_type: autoCaseNoun(event_type, hass.language),
Expand Down
47 changes: 27 additions & 20 deletions src/dialogs/more-info/controls/more-info-weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
mdiWeatherWindy,
} from "@mdi/js";
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
css,
html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
Expand All @@ -19,13 +19,13 @@ import { formatTimeWeekday } from "../../../common/datetime/format_time";
import { formatNumber } from "../../../common/number/format_number";
import "../../../components/ha-svg-icon";
import {
ForecastEvent,
WeatherEntity,
getDefaultForecastType,
getForecast,
getWeatherUnit,
getWind,
subscribeForecast,
ForecastEvent,
WeatherEntity,
weatherIcons,
} from "../../../data/weather";
import { HomeAssistant } from "../../../types";
Expand Down Expand Up @@ -122,6 +122,7 @@ class MoreInfoWeather extends LitElement {
);
const forecast = forecastData?.forecast;
const hourly = forecastData?.type === "hourly";
const dayNight = forecastData?.type === "twice_daily";

return html`
${this._showValue(this.stateObj.attributes.temperature)
Expand Down Expand Up @@ -225,28 +226,34 @@ class MoreInfoWeather extends LitElement {
></ha-svg-icon>
`
: ""}
${hourly
? html`
<div class="main">
<div class="main">
${dayNight
? html`
${formatDateWeekdayDay(
new Date(item.datetime),
this.hass!.locale,
this.hass!.config
)}
(${item.is_daytime !== false
? this.hass!.localize("ui.card.weather.day")
: this.hass!.localize("ui.card.weather.night")})
`
: hourly
? html`
${formatTimeWeekday(
new Date(item.datetime),
this.hass.locale,
this.hass.config
this.hass!.locale,
this.hass!.config
)}
</div>
`
: html`
<div class="main">
`
: html`
${formatDateWeekdayDay(
new Date(item.datetime),
this.hass.locale,
this.hass.config
this.hass!.locale,
this.hass!.config
)}
${item.is_daytime !== false
? this.hass!.localize("ui.card.weather.day")
: this.hass!.localize("ui.card.weather.night")}
</div>
`}
`}
</div>
<div class="templow">
${this._showValue(item.templow)
? `${formatNumber(item.templow!, this.hass.locale)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
}

private _getDescription(option, idx: number) {
if (option.alias) {
return option.alias;
}
if (this.isExpanded(idx)) {
return "";
}
Expand Down
7 changes: 4 additions & 3 deletions src/panels/lovelace/cards/hui-weather-forecast-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,10 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
<div>
${dayNight
? html`
${new Date(item.datetime).toLocaleDateString(
this.hass!.language,
{ weekday: "short" }
${formatDateWeekdayShort(
new Date(item.datetime),
this.hass!.locale,
this.hass!.config
)}
<div class="daynight">
${item.is_daytime !== false
Expand Down
29 changes: 10 additions & 19 deletions src/panels/lovelace/entity-rows/hui-event-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ class HuiEventEntityRow extends LitElement implements LovelaceRow {
})}
>
<div class="what">
${computeStateDisplay(
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div>
<div class="when">
${isUnavailableState(stateObj.state)
? computeStateDisplay(
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)
? ``
: computeAttributeValueDisplay(
this.hass!.localize,
stateObj,
Expand All @@ -86,18 +89,6 @@ class HuiEventEntityRow extends LitElement implements LovelaceRow {
"event_type"
)}
</div>
<div class="when">
${isUnavailableState(stateObj.state)
? ``
: html`
<hui-timestamp-display
.hass=${this.hass}
.ts=${new Date(stateObj.state)}
.format=${this._config.format}
capitalize
></hui-timestamp-display>
`}
</div>
</div>
</hui-generic-entity-row>
`;
Expand Down
Loading

0 comments on commit a181189

Please sign in to comment.