diff --git a/src/data/weather.ts b/src/data/weather.ts index 34fc4da252..62a4ed423d 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -1,21 +1,24 @@ import { HomeAssistant } from "../types"; -export const weatherIcons = { +export const weatherImages = { "clear-night": "/static/images/weather/night.png", cloudy: "/static/images/weather/cloudy.png", - exceptional: "hass:alert-circle-outline", - fog: "hass:weather-fog", - hail: "hass:weather-hail", + fog: "/static/images/weather/cloudy.png", + hail: "/static/images/weather/rainy.png", lightning: "/static/images/weather/lightning.png", "lightning-rainy": "/static/images/weather/lightning-rainy.png", partlycloudy: "/static/images/weather/partly-cloudy.png", pouring: "/static/images/weather/pouring.png", rainy: "/static/images/weather/rainy.png", snowy: "/static/images/weather/snowy.png", - "snowy-rainy": "hass:weather-snowy-rainy", + "snowy-rainy": "/static/images/weather/rainy.png", sunny: "/static/images/weather/sunny.png", windy: "/static/images/weather/windy.png", - "windy-variant": "hass:weather-windy-variant", + "windy-variant": "/static/images/weather/windy.png", +}; + +export const weatherIcons = { + exceptional: "hass:alert-circle-outline", }; export const cardinalDirections = [ diff --git a/src/panels/lovelace/entity-rows/hui-weather-entity-row.ts b/src/panels/lovelace/entity-rows/hui-weather-entity-row.ts index 24262065a6..0bdb3786af 100644 --- a/src/panels/lovelace/entity-rows/hui-weather-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-weather-entity-row.ts @@ -8,8 +8,6 @@ import { customElement, PropertyValues, } from "lit-element"; -import { ifDefined } from "lit-html/directives/if-defined"; -import { classMap } from "lit-html/directives/class-map"; import "../../../components/entity/state-badge"; import "../components/hui-warning"; @@ -18,15 +16,11 @@ import { LovelaceRow } from "./types"; import { HomeAssistant, WeatherEntity } from "../../../types"; import { EntitiesCardEntityConfig } from "../cards/types"; import { hasConfigOrEntityChanged } from "../common/has-changed"; -import { UNAVAILABLE } from "../../../data/entity"; -import { weatherIcons, getWeatherUnit } from "../../../data/weather"; -import { DOMAINS_HIDE_MORE_INFO } from "../../../common/const"; -import { computeDomain } from "../../../common/entity/compute_domain"; -import { actionHandler } from "../common/directives/action-handler-directive"; -import { hasAction } from "../common/has-action"; -import { computeStateName } from "../../../common/entity/compute_state_name"; -import { ActionHandlerEvent } from "../../../data/lovelace"; -import { handleAction } from "../common/handle-action"; +import { + weatherIcons, + getWeatherUnit, + weatherImages, +} from "../../../data/weather"; @customElement("hui-weather-entity-row") class HuiWeatherEntityRow extends LitElement implements LovelaceRow { @@ -52,7 +46,7 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow { const stateObj = this.hass.states[this._config.entity] as WeatherEntity; - if (!stateObj || stateObj.state === UNAVAILABLE) { + if (!stateObj) { return html` ${this.hass.localize( @@ -64,58 +58,24 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow { `; } - const pointer = - (this._config.tap_action && this._config.tap_action.action !== "none") || - (this._config.entity && - !DOMAINS_HIDE_MORE_INFO.includes(computeDomain(this._config.entity))); - - const secondaryAttribute = this._getSecondaryAttribute(stateObj); + const weatherRowConfig = { + ...this._config, + icon: weatherIcons[stateObj.state], + image: weatherImages[stateObj.state], + }; return html` -
- -
-
-
-
- ${this._config.name || computeStateName(stateObj)} -
-
- ${this.hass.localize(`state.weather.${stateObj.state}`) || - stateObj.state} -
-
-
- ${stateObj.attributes.temperature}${getWeatherUnit(this.hass, "temperature")} -
+ +
+
+ ${stateObj.attributes.temperature} + ${getWeatherUnit(this.hass, "temperature")} +
+
+ ${this._getSecondaryAttribute(stateObj)}
- ${secondaryAttribute - ? html` -
- - ${secondaryAttribute} - -
- ` - : ""}
-
+ `; } @@ -146,7 +106,7 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow { return ` ${this.hass!.localize( `ui.card.weather.attributes.${attribute}` - )} ${value}${getWeatherUnit(this.hass!, attribute)} + )} ${value} ${getWeatherUnit(this.hass!, attribute)} `; } @@ -184,7 +144,7 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow { ${ tempHigh ? ` - ${this.hass!.localize(`ui.card.weather.high`)} ${tempHigh}${unit} + ${this.hass!.localize(`ui.card.weather.high`)} ${tempHigh} ${unit} ` : "" } @@ -192,82 +152,25 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow { ${ tempLow ? ` - ${this.hass!.localize(`ui.card.weather.low`)} ${tempLow}${unit} + ${this.hass!.localize(`ui.card.weather.low`)} ${tempLow} ${unit} ` : "" } `; } - private _handleAction(ev: ActionHandlerEvent) { - handleAction(this, this.hass!, this._config!, ev.detail.action!); - } - static get styles(): CSSResult { return css` - .pointer { - cursor: pointer; - } - - .main { + .attributes { display: flex; - align-items: center; - justify-content: flex-end; - width: 100%; - } - - .name { - font-weight: 500; - } - - .state { - color: var(--secondary-text-color); - } - - .temperature { - font-size: 28px; - margin-right: 16px; - } - - .temperature span { - font-size: 18px; - position: absolute; - } - - .container { - flex: 1 0; - display: flex; - flex-flow: column; - } - - .info { - display: flex; - flex-flow: column; + flex-direction: column; justify-content: center; + text-align: right; } - .info, - .attributes { - flex: 1 0; - margin-left: 16px; - overflow: hidden; - } - - .info > *, - .attributes > * { - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - } - - .attributes { - padding-top: 1px; + .secondary { color: var(--secondary-text-color); } - - .attributes > *:not(:first-child) { - padding-left: 4px; - } `; } }