diff --git a/README.md b/README.md index 81320b87..e07a55e4 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ hide_clock: false hide_date: false hourly_forecast: false use_browser_time: true +time_zone: null ``` ### Options @@ -129,6 +130,7 @@ use_browser_time: true | hide_date | boolean | **Optional** | Hides the date from the today section | `false` | | hourly_forecast | boolean | **Optional** | Displays an hourly forecast instead of daily | `false` | | use_browser_time | boolean | **Optional** | Uses the time from your browser to indicate the current time. If not provided, falls back to the [`time_zone`](https://www.home-assistant.io/blog/2015/05/09/utc-time-zone-awareness/#setting-up-your-time-zone) configured in HA | `true` | +| time_zone | string | **Optional** | Uses the given [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to indicate the current date and time. If not provided, uses the time zone configured in HA | `null` | ## Footnotes diff --git a/src/clock-weather-card.ts b/src/clock-weather-card.ts index 02959c17..df26c7cf 100644 --- a/src/clock-weather-card.ts +++ b/src/clock-weather-card.ts @@ -126,7 +126,7 @@ export class ClockWeatherCard extends LitElement { const oldHass = changedProps.get('hass') as HomeAssistant | undefined if (oldHass) { const oldSun = oldHass.states[this.config.sun_entity] - const newSun = this.hass?.states[this.config.sun_entity] + const newSun = this.hass.states[this.config.sun_entity] if (oldSun !== newSun) { return true } @@ -394,7 +394,8 @@ export class ClockWeatherCard extends LitElement { hide_clock: config.hide_clock ?? false, hide_date: config.hide_date ?? false, date_pattern: config.date_pattern ?? 'P', - use_browser_time: config.use_browser_time ?? true + use_browser_time: config.use_browser_time ?? true, + time_zone: config.time_zone ?? undefined } } @@ -549,7 +550,7 @@ export class ClockWeatherCard extends LitElement { private toZonedDate (date: Date): Date { if (this.config.use_browser_time) return date - const timeZone = this.hass?.config?.time_zone + 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.`) diff --git a/src/types.ts b/src/types.ts index 9290b894..df449643 100644 --- a/src/types.ts +++ b/src/types.ts @@ -24,6 +24,7 @@ export interface ClockWeatherCardConfig extends LovelaceCardConfig { hide_clock?: boolean hide_date?: boolean use_browser_time?: boolean + time_zone?: string } export interface MergedClockWeatherCardConfig extends LovelaceCardConfig { @@ -43,6 +44,7 @@ export interface MergedClockWeatherCardConfig extends LovelaceCardConfig { hide_clock: boolean hide_date: boolean use_browser_time: boolean + time_zone?: string } export const enum WeatherEntityFeature {