const LitElement = Object.getPrototypeOf(customElements.get("hui-view"));
const html = LitElement.prototype.html;
const locale = {
da: {
temp: "Temperatur",
tempHi: "Temperatur maks",
tempLo: "Temperatur nat",
precip: "Nedbør",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NØ', 'NØ', 'Ø-NØ', 'Ø', 'Ø-SØ', 'SØ', 'S-SØ',
'S', 'S-SV', 'SV', 'V-SV', 'V', 'V-NV', 'NV', 'N-NV', 'N'
]
},
de: {
temp: "temperatur",
tempHi: "Höchsttemperatur",
tempLo: "Tiefsttemperatur",
precip: "Niederschlag",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NO', 'NO', 'O-NO', 'O', 'O-SO', 'SO', 'S-SO',
'S', 'S-SW', 'SW', 'W-SW', 'W', 'W-NW', 'NW', 'N-NW', 'N'
]
},
en: {
temp: "Temperature",
tempHi: "Temperature max",
tempLo: "Temperature min",
precip: "Precipitations",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NE', 'NE', 'E-NE', 'E', 'E-SE', 'SE', 'S-SE',
'S', 'S-SW', 'SW', 'W-SW', 'W', 'W-NW', 'NW', 'N-NW', 'N'
]
},
es: {
temp: "Temperatura",
tempHi: "Temperatura máxima",
tempLo: "Temperatura mínima",
precip: "Precipitations",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NE', 'NE', 'E-NE', 'E', 'E-SE', 'SE', 'S-SE',
'S', 'S-SO', 'SO', 'O-SO', 'O', 'O-NO', 'NO', 'N-NO', 'N'
]
},
fr: {
temp: "Température",
tempHi: "Température max",
tempLo: "Température min",
precip: "Précipitations",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NE', 'NE', 'E-NE', 'E', 'E-SE', 'SE', 'S-SE',
'S', 'S-SO', 'SO', 'O-SO', 'O', 'O-NO', 'NO', 'N-NO', 'N'
]
},
nl: {
temp: "temperatuur",
tempHi: "Maximum temperatuur",
tempLo: "Minimum temperatuur",
precip: "Neerslag",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NO', 'NO', 'O-NO', 'O', 'O-ZO', 'ZO', 'Z-ZO',
'Z', 'Z-ZW', 'ZW', 'W-ZW', 'W', 'W-NW', 'NW', 'N-NW', 'N'
]
},
ru: {
temp: "Температура",
tempHi: "Температура макси",
tempLo: "Температура ночью",
precip: "Осадки",
uPress: "гПа",
uSpeed: "м/с",
uPrecip: "мм",
cardinalDirections: [
'С', 'С-СВ', 'СВ', 'В-СВ', 'В', 'В-ЮВ', 'ЮВ', 'Ю-ЮВ',
'Ю', 'Ю-ЮЗ', 'ЮЗ', 'З-ЮЗ', 'З', 'З-СЗ', 'СЗ', 'С-СЗ', 'С'
]
},
sv: {
temp: "Temperatur",
tempHi: "Max temperatur",
tempLo: "Min temperatur",
precip: "Nederbörd",
uPress: "hPa",
uSpeed: "m/s",
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NO', 'NO', 'O-NO', 'O', 'O-SO', 'SO', 'S-SO',
'S', 'S-SV', 'SV', 'V-SV', 'V', 'V-NV', 'NV', 'N-NV', 'N'
]
}
};
const cardinalDirectionsIcon = [
'mdi:arrow-down', 'mdi:arrow-bottom-left', 'mdi:arrow-left',
'mdi:arrow-top-left', 'mdi:arrow-up', 'mdi:arrow-top-right',
'mdi:arrow-right', 'mdi:arrow-bottom-right', 'mdi:arrow-down'
];
const weatherIconsDay = {
clear: "day",
"clear-night": "night",
cloudy: "cloudy",
fog: "cloudy",
hail: "rainy-7",
lightning: "thunder",
"lightning-rainy": "thunder",
partlycloudy: "cloudy-day-3",
pouring: "rainy-6",
rainy: "rainy-5",
snowy: "snowy-6",
"snowy-rainy": "rainy-7",
sunny: "day",
windy: "cloudy",
"windy-variant": "cloudy-day-3",
exceptional: "!!"
};
const weatherIconsNight = {
...weatherIconsDay,
clear: "night",
sunny: "night",
partlycloudy: "cloudy-night-3",
"windy-variant": "cloudy-night-3"
};
const fireEvent = (node, type, detail, options) => {
options = options || {};
detail = detail === null || detail === undefined ? {} : detail;
const event = new Event(type, {
bubbles: options.bubbles === undefined ? true : options.bubbles,
cancelable: Boolean(options.cancelable),
composed: options.composed === undefined ? true : options.composed
});
event.detail = detail;
node.dispatchEvent(event);
return event;
};
function hasConfigOrEntityChanged(element, changedProps) {
if (changedProps.has("_config")) {
return true;
}
const oldHass = changedProps.get("hass");
if (oldHass) {
return (
oldHass.states[element._config.entity] !==
element.hass.states[element._config.entity] ||
oldHass.states["sun.sun"] !== element.hass.states["sun.sun"]
);
}
return true;
}
class WeatherCard extends LitElement {
static get properties() {
return { _config: {}, hass: {} };
}
static async getConfigElement() {
await import("./weather-card-editor.js");
return document.createElement("weather-card-editor");
}
static getStubConfig() {
return {};
}
setConfig(config) {
if (!config.entity) {
throw new Error("Please define a weather entity");
}
this._config = config;
if (this._config.forecast_max_Column)
this._config.forecast_max_Column = parseInt(this._config.forecast_max_Column);
this.setWeatherObj();
}
setWeatherObj() {
if (!this.hass)
return;
this.weatherObj = this._config.entity in this.hass.states ? this.hass.states[this._config.entity] : null;
if (!this.weatherObj)
return;
if (!this._config.forecast_max_Column
|| this._config.forecast_max_Column < 2)
this.forecast = this.weatherObj.attributes.forecast.slice(0,9);
else
this.forecast = this.weatherObj.attributes.forecast.slice(0,this._config.forecast_max_Column);
//determine if the weather is hourly or daily
var diffHours = Math.abs(new Date(this.forecast[0].datetime) - new Date(this.forecast[1].datetime)) / 36e5;
if (diffHours === 1)
this.mode = 'hourly';
else
this.mode = 'daily';
}
shouldUpdate(changedProps) {
return hasConfigOrEntityChanged(this, changedProps);
}
updated(param) {
this.setWeatherObj();
var chart = this.shadowRoot.getElementById("Chart");
if (chart)
chart.data = this.ChartData;
}
render() {
if (!this._config || !this.hass) {
return html``;
}
this.setWeatherObj();
this.numberElements = 0;
this.lang = this.hass.selectedLanguage || this.hass.language;
if (!this.weatherObj) {
return html`