diff --git a/README.md b/README.md index 746efd0f..29c82b9d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Credits go to [basmilius](https://github.com/basmilius) for the awesome [weather ## Migrating from v1 to v2 * Configuration property `forecast_days` was renamed to `forecast_rows` to indicate that this attribute does not only work for daily, but also for hourly forecasts. +* `date-fns` has been replaced by `luxon` for date/time formatting. If you configure `date_pattern`, make sure to migrate your pattern to comply with [luxon](https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Additionally, the weekday is now [_not_ hardcoded](https://github.com/pkissling/clock-weather-card/issues/89) anymore. ## FAQ @@ -124,9 +125,9 @@ time_zone: null | weather_icon_type | `line` \| `fill` | **Optional** | Appearance of the large weather icon | `line` | | animated_icon | boolean | **Optional** | Whether the large weather icon should be animated | `true` | | forecast_rows | number | **Optional** | The amount of weather forecast rows to show. Depending on `hourly_forecast` each row either corresponds to a day or an hour | `5` | -| locale | string[^2] | **Optional** | Language to use for language specific text. If not provided, falls back to the locale set in HA | `en-GB` | -| time_format | `24` \| `12` | **Optional** | Format used to display the time. If not provided, falls back to the time format set in HA | `24` | -| date_pattern | string | **Optional** | Pattern to use for time formatting. If not provided, falls back to the default date formatting of the configured language. See [date-fns](https://date-fns.org/v2.29.3/docs/format) for valid patterns | `P` | +| locale | string[^2] | **Optional** | Language to use for language specific text and date/time formatting. If not provided, falls back to the locale set in HA or, if not set in HA, to `en-GB` | `en-GB` | +| time_format | `24` \| `12` | **Optional** | Format used to display the time. If not provided, falls back to the default time format of the configured `locale` | `24` | +| date_pattern | string | **Optional** | Pattern to use for date formatting. If not provided, falls back to a localized default date formatting. See [luxon](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) for valid tokens | `D` | | hide_today_section | boolean | **Optional** | Hides the cards today section (upper section), containing the large weather icon, clock and current date | `false` | | hide_forecast_section | boolean | **Optional** | Hides the cards forecast section (lower section),containing the weather forecast | `false` | | hide_clock | boolean | **Optional** | Hides the clock from the today section and prominently displays the current temperature instead | `false` | diff --git a/package.json b/package.json index 35f4ea06..d2e9624c 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,9 @@ "dependencies": { "@lit-labs/scoped-registry-mixin": "^1.0.0", "custom-card-helpers": "^1.8.0", - "date-fns": "^2.29.3", "home-assistant-js-websocket": "^8.0.0", "lit": "^2.0.0", - "luxon": "^3.3.0" + "luxon": "^3.4.3" }, "devDependencies": { "@babel/core": "^7.15.0", @@ -28,7 +27,7 @@ "@babel/plugin-proposal-decorators": "^7.14.5", "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^5.0.0", - "@types/luxon": "^3.3.0", + "@types/luxon": "^3.3.2", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^4.33.0", "eslint": "^8.0.1", diff --git a/src/clock-weather-card.ts b/src/clock-weather-card.ts index 5f44e862..34fa959c 100644 --- a/src/clock-weather-card.ts +++ b/src/clock-weather-card.ts @@ -30,8 +30,6 @@ import { extractMostOccuring, max, min, round, roundDown, roundIfNotNull, roundU import { svg, png } from './images' import { version } from '../package.json' import { safeRender } from './helpers' -import { format, type Locale } from 'date-fns' -import * as locales from 'date-fns/locale' import { DateTime } from 'luxon' console.info( @@ -63,16 +61,16 @@ export class ClockWeatherCard extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant @state() private config!: MergedClockWeatherCardConfig - @state() private currentDate!: Date + @state() private currentDate!: DateTime @state() private forecastSubscriber?: Promise<() => void> @state() private forecasts?: WeatherForecast[] constructor () { super() - this.currentDate = new Date() - const msToNextMinute = (60 - this.currentDate.getSeconds()) * 1000 - setTimeout(() => setInterval(() => { this.currentDate = new Date() }, 1000 * 60), msToNextMinute) - setTimeout(() => { this.currentDate = new Date() }, msToNextMinute) + this.currentDate = DateTime.now() + const msToNextMinute = (60 - this.currentDate.second) * 1000 + setTimeout(() => setInterval(() => { this.currentDate = DateTime.now() }, 1000 * 60), msToNextMinute) + setTimeout(() => { this.currentDate = DateTime.now() }, msToNextMinute) } public static getStubConfig (_hass: HomeAssistant, entities: string[], entitiesFallback: string[]): Record { @@ -85,7 +83,7 @@ export class ClockWeatherCard extends LitElement { } public getCardSize (): number { - return 3 + roundUp(this.config.forecast_days / 2) + return 3 + roundUp(this.config.forecast_rows / 2) } // https://lit.dev/docs/components/properties/#accessors-custom @@ -98,8 +96,8 @@ export class ClockWeatherCard extends LitElement { throw new Error('Attribute "entity" must be present.') } - if (config.forecast_days && config.forecast_days < 1) { - throw new Error('Attribute "forecast_days" must be greater than 0.') + if (config.forecast_rows && config.forecast_rows < 1) { + throw new Error('Attribute "forecast_rows" mst be greater than 0.') } if (config.time_format && config.time_format.toString() !== '24' && config.time_format.toString() !== '12') { @@ -240,22 +238,25 @@ export class ClockWeatherCard extends LitElement { const maxTemp = Math.round(max(maxTemps)) const gradientRange = this.gradientRange(minTemp, maxTemp, temperatureUnit) - return forecasts.map((forecast) => safeRender(() => this.renderForecastItem(forecast, gradientRange, minTemp, maxTemp, currentTemp, hourly))) + + const displayTexts = forecasts + .map(f => f.datetime) + .map(d => hourly ? this.time(d) : this.localize(`day.${d.weekday}`)) + const maxColOneChars = displayTexts.length ? max(displayTexts.map(t => t.length)) : 0 + + return forecasts.map((forecast, i) => safeRender(() => this.renderForecastItem(forecast, gradientRange, minTemp, maxTemp, currentTemp, hourly, displayTexts[i], maxColOneChars))) } - private renderForecastItem (forecast: MergedWeatherForecast, gradientRange: Rgb[], minTemp: number, maxTemp: number, currentTemp: number | null, hourly: boolean): TemplateResult { - const twelveHour = this.getTimeFormat() === '12' - const displayText = !hourly ? this.localize('day.' + forecast.datetime.getDay()) : this.time(forecast.datetime) + private renderForecastItem (forecast: MergedWeatherForecast, gradientRange: Rgb[], minTemp: number, maxTemp: number, currentTemp: number | null, hourly: boolean, displayText: string, maxColOneChars: number): TemplateResult { const weatherState = forecast.condition === 'pouring' ? 'raindrops' : forecast.condition === 'rainy' ? 'raindrop' : forecast.condition const weatherIcon = this.toIcon(weatherState, 'fill', true, 'static') const tempUnit = this.getWeather().attributes.temperature_unit - const isNow = !hourly ? new Date().getDate() === forecast.datetime.getDate() : new Date().getHours() === forecast.datetime.getHours() + const isNow = hourly ? DateTime.now().hour === forecast.datetime.hour : DateTime.now().day === forecast.datetime.day const minTempDay = Math.round(isNow && currentTemp !== null ? Math.min(currentTemp, forecast.templow) : forecast.templow) const maxTempDay = Math.round(isNow && currentTemp !== null ? Math.max(currentTemp, forecast.temperature) : forecast.temperature) - const colOneSize = hourly && twelveHour ? '3rem' : hourly ? '2.5rem' : '2rem' return html` - + ${this.renderText(displayText)} ${this.renderIcon(weatherIcon)} ${this.renderText(this.toConfiguredTempWithUnit(tempUnit, minTempDay), 'right')} @@ -393,7 +394,7 @@ export class ClockWeatherCard extends LitElement { hide_today_section: config.hide_today_section ?? false, hide_clock: config.hide_clock ?? false, hide_date: config.hide_date ?? false, - date_pattern: config.date_pattern ?? 'P', + date_pattern: config.date_pattern ?? 'D', use_browser_time: config.use_browser_time ?? true, time_zone: config.time_zone ?? undefined } @@ -431,39 +432,27 @@ export class ClockWeatherCard extends LitElement { } private getLocale (): string { - return this.config.locale ?? this.hass.locale?.language ?? 'en-GB' - } - - private getDateFnsLocale (): Locale { - const locale = this.getLocale() - const localeParts = locale - .replace('_', '-') - .split('-') - const localeOne = localeParts[0].toLowerCase() - const localeTwo = localeParts[1]?.toUpperCase() || '' - const dateFnsLocale = localeOne + localeTwo - // HA provides en-US as en - if (dateFnsLocale === 'en') { - return locales.enUS - } - const importedLocale = locales[dateFnsLocale] - if (!importedLocale) { - console.error('clock-weather-card - Locale not supported: ' + dateFnsLocale) - return locales.enGB - } - return importedLocale + return this.config.locale ?? this.hass.locale.language ?? 'en-GB' } private date (): string { - const zonedDate = this.toZonedDate(this.currentDate) - const weekday = this.localize(`day.${zonedDate.getDay()}`) - const date = format(zonedDate, this.config.date_pattern, { locale: this.getDateFnsLocale() }) - return `${weekday}, ${date}` + return this.toZonedDate(this.currentDate).toFormat(this.config.date_pattern) } - private time (date: Date = this.currentDate): string { - const withTimeZone = this.toZonedDate(date) - return format(withTimeZone, this.getTimeFormat() === '24' ? 'HH:mm' : 'h:mm aa') + private time (date: DateTime = this.currentDate): string { + if (this.config.time_format) { + return this.toZonedDate(date) + .toFormat(this.config.time_format === '24' ? 'HH:mm' : 'h:mm a') + } + if (this.hass.locale.time_format === TimeFormat.am_pm) { + return this.toZonedDate(date).toFormat('h:mm a') + } + + if (this.hass.locale.time_format === TimeFormat.twenty_four) { + return this.toZonedDate(date).toFormat('HH:mm') + } + + return this.toZonedDate(date).toFormat('t') } private getIconAnimationKind (): 'static' | 'animated' { @@ -498,16 +487,6 @@ export class ClockWeatherCard extends LitElement { : this.toCelsius(unit, temp) } - private getTimeFormat (): '12' | '24' { - if (this.config.time_format) { - return this.config.time_format - } - - if (this.hass.locale?.time_format === TimeFormat.twenty_four) return '24' - if (this.hass.locale?.time_format === TimeFormat.am_pm) return '12' - return '24' - } - private calculateBarRangePercents (minTemp: number, maxTemp: number, minTempDay: number, maxTempDay: number): { startPercent: number, endPercent: number } { if (maxTemp === minTemp) { // avoid division by 0 @@ -531,7 +510,7 @@ export class ClockWeatherCard extends LitElement { const forecasts = this.getWeather().attributes.forecast ?? this.forecasts ?? [] const agg = forecasts.reduce>((forecasts, forecast) => { const d = new Date(forecast.datetime) - const unit = !hourly ? d.getDate() : `${d.getMonth()}-${d.getDate()}-${+d.getHours()}` + const unit = hourly ? `${d.getMonth()}-${d.getDate()}-${+d.getHours()}` : d.getDate() forecasts[unit] = forecasts[unit] || [] forecasts[unit].push(forecast) return forecasts @@ -544,19 +523,20 @@ export class ClockWeatherCard extends LitElement { agg.push(avg) return agg }, []) - .sort((a, b) => a.datetime.getTime() - b.datetime.getTime()) + .sort((a, b) => a.datetime.toMillis() - b.datetime.toMillis()) .slice(0, maxRowsCount) } - private toZonedDate (date: Date): Date { - if (this.config.use_browser_time) return date + private toZonedDate (date: DateTime): DateTime { + const localizedDate = date.setLocale(this.getLocale()) + if (this.config.use_browser_time) return localizedDate const timeZone = this.config.time_zone ?? this.hass?.config?.time_zone - const withTimeZone = DateTime.fromJSDate(date).setZone(timeZone) - if (!withTimeZone.isValid) { - console.error(`clock-weather-card - Time Zone [${timeZone}] not supported. Falling back to browser time.`) - return date + const withTimeZone = localizedDate.setZone(timeZone) + if (withTimeZone.isValid) { + return withTimeZone } - return new Date(withTimeZone.year, withTimeZone.month - 1, withTimeZone.day, withTimeZone.hour, withTimeZone.minute, withTimeZone.second, withTimeZone.millisecond) + console.error(`clock-weather-card - Time Zone [${timeZone}] not supported. Falling back to browser time.`) + return localizedDate } private calculateAverageForecast (forecasts: WeatherForecast[]): MergedWeatherForecast { @@ -578,7 +558,7 @@ export class ClockWeatherCard extends LitElement { return { temperature: maxTemp, templow: minTemp, - datetime: new Date(forecasts[0].datetime), + datetime: DateTime.fromISO(forecasts[0].datetime), condition, precipitation_probability: precipitationProbability, precipitation @@ -621,7 +601,7 @@ export class ClockWeatherCard extends LitElement { return (this.getWeather().attributes.forecast?.length ?? 0) > 0 } - private supportsFeature(feature: WeatherEntityFeature): boolean { + private supportsFeature (feature: WeatherEntityFeature): boolean { return (this.getWeather().attributes.supported_features & feature) !== 0 } } diff --git a/src/localize/languages/bg.json b/src/localize/languages/bg.json index c685a01e..2f4d1c9e 100644 --- a/src/localize/languages/bg.json +++ b/src/localize/languages/bg.json @@ -17,12 +17,12 @@ "exceptional": "Изключително" }, "day": { - "0": "Нд", "1": "Пн", "2": "Вт", "3": "Ср", "4": "Чт", "5": "Пт", - "6": "Сб" + "6": "Сб", + "7": "Нд" } } \ No newline at end of file diff --git a/src/localize/languages/ca.json b/src/localize/languages/ca.json index e0446ed4..bef3abb6 100644 --- a/src/localize/languages/ca.json +++ b/src/localize/languages/ca.json @@ -17,12 +17,12 @@ "exceptional": "Excepcional" }, "day": { - "0": "Dg.", "1": "Dl.", "2": "Dt.", "3": "Dc.", "4": "Dj.", "5": "Dv.", - "6": "Ds." + "6": "Ds.", + "7": "Dg." } } diff --git a/src/localize/languages/cs.json b/src/localize/languages/cs.json index 2e2e2988..afb46a72 100644 --- a/src/localize/languages/cs.json +++ b/src/localize/languages/cs.json @@ -17,12 +17,12 @@ "exceptional": "Chaos" }, "day": { - "0": "Ne", "1": "Po", "2": "Út", "3": "St", "4": "Čt", "5": "Pá", - "6": "So" + "6": "So", + "7": "Ne" } } \ No newline at end of file diff --git a/src/localize/languages/da.json b/src/localize/languages/da.json index 764ce0e4..55ee1ffe 100644 --- a/src/localize/languages/da.json +++ b/src/localize/languages/da.json @@ -17,12 +17,12 @@ "exceptional": "Kaos" }, "day": { - "0": "Søn", "1": "Man", "2": "Tir", "3": "Ons", "4": "Tor", "5": "Fre", - "6": "Lør" + "6": "Lør", + "7": "Søn" } } diff --git a/src/localize/languages/de.json b/src/localize/languages/de.json index 005f3f4b..f1ce6c8a 100644 --- a/src/localize/languages/de.json +++ b/src/localize/languages/de.json @@ -17,12 +17,12 @@ "exceptional": "Unwetter" }, "day": { - "0": "So", "1": "Mo", "2": "Di", "3": "Mi", "4": "Do", "5": "Fr", - "6": "Sa" + "6": "Sa", + "7": "So" } } \ No newline at end of file diff --git a/src/localize/languages/el.json b/src/localize/languages/el.json index c994356e..e293def6 100644 --- a/src/localize/languages/el.json +++ b/src/localize/languages/el.json @@ -17,12 +17,12 @@ "exceptional": "Εξαιρετικός" }, "day": { - "0": "Κυρ", "1": "Δευ", "2": "Τρί", "3": "Τετ", "4": "Πεμ", "5": "Παρ", - "6": "Σαβ" + "6": "Σαβ", + "7": "Κυρ" } } diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index e93707f5..6289b918 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -17,12 +17,12 @@ "exceptional": "Exceptional" }, "day": { - "0": "Sun", "1": "Mon", "2": "Tue", "3": "Wed", "4": "Thu", "5": "Fri", - "6": "Sat" + "6": "Sat", + "7": "Sun" } } diff --git a/src/localize/languages/es.json b/src/localize/languages/es.json index 9b219556..b9e122de 100644 --- a/src/localize/languages/es.json +++ b/src/localize/languages/es.json @@ -17,12 +17,12 @@ "exceptional": "Caos" }, "day": { - "0": "Dom", "1": "Lun", "2": "Mar", "3": "Mie", "4": "Jue", "5": "Vie", - "6": "Sab" + "6": "Sab", + "7": "Dom" } } diff --git a/src/localize/languages/et.json b/src/localize/languages/et.json index 84ed7d6d..44222153 100644 --- a/src/localize/languages/et.json +++ b/src/localize/languages/et.json @@ -17,12 +17,12 @@ "exceptional": "Äärmuslik" }, "day": { - "0": "P", "1": "E", "2": "T", "3": "K", "4": "N", "5": "R", - "6": "L" + "6": "L", + "7": "P" } } diff --git a/src/localize/languages/fi.json b/src/localize/languages/fi.json index 4ca4a051..8a3309c8 100644 --- a/src/localize/languages/fi.json +++ b/src/localize/languages/fi.json @@ -17,12 +17,12 @@ "exceptional": "Poikkeuksellista" }, "day": { - "0": "Su", "1": "Ma", "2": "Ti", "3": "Ke", "4": "To", "5": "Pe", - "6": "La" + "6": "La", + "7": "Su" } } \ No newline at end of file diff --git a/src/localize/languages/fr.json b/src/localize/languages/fr.json index 48e31ef5..2df7faf8 100644 --- a/src/localize/languages/fr.json +++ b/src/localize/languages/fr.json @@ -17,12 +17,12 @@ "exceptional": "Exceptionnelle" }, "day": { - "0": "Dim", "1": "Lun", "2": "Mar", "3": "Mer", "4": "Jeu", "5": "Ven", - "6": "Sam" + "6": "Sam", + "7": "Dim" } } diff --git a/src/localize/languages/he.json b/src/localize/languages/he.json index 8d08d441..b7c70329 100644 --- a/src/localize/languages/he.json +++ b/src/localize/languages/he.json @@ -17,12 +17,12 @@ "exceptional": "חריג" }, "day": { - "0": "ראשון", "1": "שני", "2": "שלישי", "3": "רביעי", "4": "חמישי", "5": "שישי", - "6": "שבת" + "6": "שבת", + "7": "ראשון" } } diff --git a/src/localize/languages/hu.json b/src/localize/languages/hu.json index 02c975d5..0fe63147 100644 --- a/src/localize/languages/hu.json +++ b/src/localize/languages/hu.json @@ -17,12 +17,12 @@ "exceptional": "Kivételes" }, "day": { - "0": "V", "1": "H", "2": "K", "3": "Sze", "4": "Cs", "5": "P", - "6": "Szo" + "6": "Szo", + "7": "V" } } \ No newline at end of file diff --git a/src/localize/languages/it.json b/src/localize/languages/it.json index de2d45f2..46b43db1 100644 --- a/src/localize/languages/it.json +++ b/src/localize/languages/it.json @@ -17,12 +17,12 @@ "exceptional": "Tempesta" }, "day": { - "0": "Dom", "1": "Lun", "2": "Mar", "3": "Mer", "4": "Gio", "5": "Ven", - "6": "Sab" + "6": "Sab", + "7": "Dom" } } diff --git a/src/localize/languages/ko.json b/src/localize/languages/ko.json index 60b6f8da..a2ba22ec 100644 --- a/src/localize/languages/ko.json +++ b/src/localize/languages/ko.json @@ -17,12 +17,12 @@ "exceptional": "예외" }, "day": { - "0": "일", "1": "월", "2": "화", "3": "수", "4": "목", "5": "금", - "6": "토" + "6": "토", + "7": "일" } } diff --git a/src/localize/languages/nb.json b/src/localize/languages/nb.json index fe02eaaa..385a8827 100644 --- a/src/localize/languages/nb.json +++ b/src/localize/languages/nb.json @@ -17,12 +17,12 @@ "exceptional": "Storm" }, "day": { - "0": "Søn", "1": "Man", "2": "Tir", "3": "Ons", "4": "Tor", "5": "Fre", - "6": "Lør" + "6": "Lør", + "7": "Søn" } } diff --git a/src/localize/languages/nl.json b/src/localize/languages/nl.json index f7260c07..7b54561a 100644 --- a/src/localize/languages/nl.json +++ b/src/localize/languages/nl.json @@ -17,12 +17,12 @@ "exceptional": "Chaos" }, "day": { - "0": "Zo", "1": "Ma", "2": "Di", "3": "Wo", "4": "Do", "5": "Vr", - "6": "Za" + "6": "Za", + "7": "Zo" } } \ No newline at end of file diff --git a/src/localize/languages/pl.json b/src/localize/languages/pl.json index 70c7b42e..e59eceab 100644 --- a/src/localize/languages/pl.json +++ b/src/localize/languages/pl.json @@ -17,12 +17,12 @@ "exceptional": "warunki nadzwyczajne" }, "day": { - "0": "niedz.", "1": "pon.", "2": "wt.", "3": "śr.", "4": "czw.", "5": "pt.", - "6": "sob." + "6": "sob.", + "7": "niedz." } } diff --git a/src/localize/languages/pt-br.json b/src/localize/languages/pt-br.json index 8214ae40..27f40ca4 100644 --- a/src/localize/languages/pt-br.json +++ b/src/localize/languages/pt-br.json @@ -17,12 +17,12 @@ "exceptional": "Excepcional" }, "day": { - "0": "Dom", "1": "Seg", "2": "Ter", "3": "Qua", "4": "Qui", "5": "Sex", - "6": "Sáb" + "6": "Sáb", + "7": "Dom" } } diff --git a/src/localize/languages/pt.json b/src/localize/languages/pt.json index e72a2856..469e21bf 100644 --- a/src/localize/languages/pt.json +++ b/src/localize/languages/pt.json @@ -17,12 +17,12 @@ "exceptional": "Excepcional" }, "day": { - "0": "Dom", "1": "Seg", "2": "Ter", "3": "Qua", "4": "Qui", "5": "Sex", - "6": "Sáb" + "6": "Sáb", + "7": "Dom" } } diff --git a/src/localize/languages/ro.json b/src/localize/languages/ro.json index 502f6518..788a9db3 100644 --- a/src/localize/languages/ro.json +++ b/src/localize/languages/ro.json @@ -17,12 +17,12 @@ "exceptional": "Furtuna" }, "day": { - "0": "Dum", "1": "Lun", "2": "Mar", "3": "Mie", "4": "Joi", "5": "Vin", - "6": "Sam" + "6": "Sam", + "7": "Dum" } } diff --git a/src/localize/languages/ru.json b/src/localize/languages/ru.json index c01313f8..71903ba9 100644 --- a/src/localize/languages/ru.json +++ b/src/localize/languages/ru.json @@ -17,12 +17,12 @@ "exceptional": "Буря" }, "day": { - "0": "Вс", "1": "Пн", "2": "Вт", "3": "Ср", "4": "Чт", "5": "Пт", - "6": "Сб" + "6": "Сб", + "7": "Вс" } } \ No newline at end of file diff --git a/src/localize/languages/sk.json b/src/localize/languages/sk.json index c6aba977..120ce4e6 100644 --- a/src/localize/languages/sk.json +++ b/src/localize/languages/sk.json @@ -17,12 +17,12 @@ "exceptional": "Neobyčajné počasie (Chaos)" }, "day": { - "0": "Ned", "1": "Pon", "2": "Uto", "3": "Str", "4": "Štv", "5": "Pia", - "6": "Sob" + "6": "Sob", + "7": "Ned" } } diff --git a/src/localize/languages/sl.json b/src/localize/languages/sl.json index f751aae4..0396481d 100644 --- a/src/localize/languages/sl.json +++ b/src/localize/languages/sl.json @@ -17,12 +17,12 @@ "exceptional": "Izjemno vreme" }, "day": { - "0": "Ned", "1": "Pon", "2": "Tor", "3": "Sre", "4": "Čet", "5": "Pet", - "6": "Sob" + "6": "Sob", + "7": "Ned" } } diff --git a/src/localize/languages/sv.json b/src/localize/languages/sv.json index 58b8992f..cbc1e2c6 100644 --- a/src/localize/languages/sv.json +++ b/src/localize/languages/sv.json @@ -17,12 +17,12 @@ "exceptional": "Exceptionellt" }, "day": { - "0": "Sön", "1": "Mån", "2": "Tis", "3": "Ons", "4": "Tor", "5": "Fre", - "6": "Lör" + "6": "Lör", + "7": "Sön" } } \ No newline at end of file diff --git a/src/localize/languages/th.json b/src/localize/languages/th.json index a94ef011..ca307806 100644 --- a/src/localize/languages/th.json +++ b/src/localize/languages/th.json @@ -17,12 +17,12 @@ "exceptional": "Exceptional" }, "day": { - "0": "อา.", "1": "จ.", "2": "อ.", "3": "พ.", "4": "พฤ.", "5": "ศ.", - "6": "ส." + "6": "ส.", + "7": "อา." } } diff --git a/src/localize/languages/uk.json b/src/localize/languages/uk.json index aa3dc42c..31706d27 100644 --- a/src/localize/languages/uk.json +++ b/src/localize/languages/uk.json @@ -17,12 +17,12 @@ "exceptional": "Буря" }, "day": { - "0": "Нд", "1": "Пн", "2": "Вт", "3": "Ср", "4": "Чт", "5": "Пт", - "6": "Сб" + "6": "Сб", + "7": "Нд" } } \ No newline at end of file diff --git a/src/localize/languages/vi.json b/src/localize/languages/vi.json index 3f28ac51..a6cf893a 100644 --- a/src/localize/languages/vi.json +++ b/src/localize/languages/vi.json @@ -17,12 +17,12 @@ "exceptional": "Khắc Nghiệt" }, "day": { - "0": "CN", "1": "T2", "2": "T3", "3": "T4", "4": "T5", "5": "T6", - "6": "T7" + "6": "T7", + "7": "CN" } } diff --git a/src/localize/languages/zh-cn.json b/src/localize/languages/zh-cn.json index e0545c5d..d8ffe9ab 100644 --- a/src/localize/languages/zh-cn.json +++ b/src/localize/languages/zh-cn.json @@ -1,28 +1,28 @@ { - "weather": { - "clear-night": "夜间晴朗", - "cloudy": "阴", - "fog": "雾", - "hail": "冰雹", - "lightning": "雷", - "lightning-rainy": "雷阵雨", - "partlycloudy": "多云", - "pouring": "大雨", - "rainy": "雨", - "snowy": "雪", - "snowy-rainy": "雨夹雪", - "sunny": "晴", - "windy": "有风", - "windy-variant": "强风", - "exceptional": "特殊" - }, - "day": { - "0": "周日", - "1": "周一", - "2": "周二", - "3": "周三", - "4": "周四", - "5": "周五", - "6": "周六" - } -} + "weather": { + "clear-night": "夜间晴朗", + "cloudy": "阴", + "fog": "雾", + "hail": "冰雹", + "lightning": "雷", + "lightning-rainy": "雷阵雨", + "partlycloudy": "多云", + "pouring": "大雨", + "rainy": "雨", + "snowy": "雪", + "snowy-rainy": "雨夹雪", + "sunny": "晴", + "windy": "有风", + "windy-variant": "强风", + "exceptional": "特殊" + }, + "day": { + "1": "周一", + "2": "周二", + "3": "周三", + "4": "周四", + "5": "周五", + "6": "周六", + "7": "周日" + } +} \ No newline at end of file diff --git a/src/localize/languages/zh-tw.json b/src/localize/languages/zh-tw.json index 73892fd5..e50628df 100644 --- a/src/localize/languages/zh-tw.json +++ b/src/localize/languages/zh-tw.json @@ -1,29 +1,28 @@ { - "weather": { - "clear-night": "晴夜", - "cloudy": "多雲", - "fog": "霧", - "hail": "冰雹", - "lightning": "雷", - "lightning-rainy": "雷雨", - "partlycloudy": "局部多雲", - "pouring": "大雨", - "rainy": "雨", - "snowy": "雪", - "snowy-rainy": "雪雨", - "sunny": "晴", - "windy": "有風", - "windy-variant": "有風", - "exceptional": "惡劣" - }, - "day": { - "0": "週日", - "1": "週一", - "2": "週二", - "3": "週三", - "4": "週四", - "5": "週五", - "6": "週六" - } + "weather": { + "clear-night": "晴夜", + "cloudy": "多雲", + "fog": "霧", + "hail": "冰雹", + "lightning": "雷", + "lightning-rainy": "雷雨", + "partlycloudy": "局部多雲", + "pouring": "大雨", + "rainy": "雨", + "snowy": "雪", + "snowy-rainy": "雪雨", + "sunny": "晴", + "windy": "有風", + "windy-variant": "有風", + "exceptional": "惡劣" + }, + "day": { + "1": "週一", + "2": "週二", + "3": "週三", + "4": "週四", + "5": "週五", + "6": "週六", + "7": "週日" } - \ No newline at end of file +} \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 25da491f..47c932dc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ import { type LovelaceCard, type LovelaceCardConfig, type LovelaceCardEditor } from 'custom-card-helpers' import { type HassEntity } from 'home-assistant-js-websocket/dist/types' +import { type DateTime } from 'luxon' declare global { interface HTMLElementTagNameMap { @@ -12,7 +13,7 @@ export interface ClockWeatherCardConfig extends LovelaceCardConfig { entity: string title?: string sun_entity?: string - temperature_sensor?: string; + temperature_sensor?: string weather_icon_type?: 'fill' | 'line' animated_icon?: boolean forecast_rows?: number @@ -77,7 +78,7 @@ export interface WeatherForecast { } export interface MergedWeatherForecast { - datetime: Date + datetime: DateTime condition: string temperature: number precipitation: number diff --git a/yarn.lock b/yarn.lock index 18d6f83f..7826db44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -271,13 +271,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.22.5" -"@babel/runtime@^7.21.0": - version "7.23.1" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.1.tgz#72741dc4d413338a91dcb044a86f3c0bc402646d" - integrity sha512-hC2v6p8ZSI/W0HUzh3V8C5g+NwSKzKPtJwSpTjwl0o297GP9+ZLQSkdvHz46CM3LqyoXxq+5G9komY+eSqSO0g== - dependencies: - regenerator-runtime "^0.14.0" - "@babel/template@^7.22.15": version "7.22.15" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" @@ -560,7 +553,7 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ== -"@types/luxon@^3.3.0": +"@types/luxon@^3.3.2": version "3.3.2" resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.3.2.tgz#f6e3524c2486b949a4db445e85d93c8e9886dfe2" integrity sha512-l5cpE57br4BIjK+9BSkFBOsWtwv6J9bJpC7gdXIzZyI0vuKvNTk0wZZrkQxMGsUAuGW9+WMNWF2IJMD7br2yeQ== @@ -994,13 +987,6 @@ custom-card-helpers@^1.8.0: superstruct "^0.15.3" typescript "^4.5.4" -date-fns@^2.29.3: - version "2.30.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0" - integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw== - dependencies: - "@babel/runtime" "^7.21.0" - debug@^3.2.7: version "3.2.7" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" @@ -2024,7 +2010,7 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -luxon@^3.3.0: +luxon@^3.4.3: version "3.4.3" resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.4.3.tgz#8ddf0358a9492267ffec6a13675fbaab5551315d" integrity sha512-tFWBiv3h7z+T/tDaoxA8rqTxy1CHV6gHS//QdaH4pulbq/JuBSGgQspQQqcgnwdAx6pNI7cmvz5Sv/addzHmUg== @@ -2294,11 +2280,6 @@ randombytes@^2.1.0: dependencies: safe-buffer "^5.1.0" -regenerator-runtime@^0.14.0: - version "0.14.0" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45" - integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA== - regexp.prototype.flags@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz#90ce989138db209f81492edd734183ce99f9677e"