Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor the time display preference of the user set in HA #122

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions dist/meteofrance-weather-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class MeteofranceWeatherCard extends LitElement {
next_rising = new Date(sun.attributes.next_rising);
next_setting = new Date(sun.attributes.next_setting);
}
const hour12 = this.hass.locale.time_format == "12" ? true : this.hass.locale.time_format == "24" ? false : undefined;

this.numberElements++;

Expand Down Expand Up @@ -345,15 +346,19 @@ class MeteofranceWeatherCard extends LitElement {
<!-- Sunset up -->
${next_rising
? this.renderDetail(
next_rising.toLocaleTimeString(),
next_rising.toLocaleTimeString([], {
hour12: hour12,
}),
"Heure de lever",
"mdi:weather-sunset-up"
)
: ""}
<!-- Sunset down -->
${next_setting
? this.renderDetail(
next_setting.toLocaleTimeString(),
next_setting.toLocaleTimeString([], {
hour12: hour12,
}),
"Heure de coucher",
"mdi:weather-sunset-down"
)
Expand Down Expand Up @@ -457,6 +462,7 @@ class MeteofranceWeatherCard extends LitElement {

const lang = this.hass.selectedLanguage || this.hass.language;
const isDaily = this.isDailyForecast(forecast);
const hour12 = this.hass.locale.time_format == "12" ? true : this.hass.locale.time_format == "24" ? false : undefined;

this.numberElements++;
return html` <ul
Expand All @@ -469,11 +475,11 @@ class MeteofranceWeatherCard extends LitElement {
? this._config.number_of_forecasts
: 5
)
.map((daily) => this.renderDailyForecast(daily, lang, isDaily))}
.map((daily) => this.renderDailyForecast(daily, lang, isDaily, hour12))}
</ul>`;
}

renderDailyForecast(daily, lang, isDaily) {
renderDailyForecast(daily, lang, isDaily, hour12) {
return html` <li>
<ul class="flow-column day">
<li>
Expand All @@ -484,6 +490,7 @@ class MeteofranceWeatherCard extends LitElement {
: new Date(daily.datetime).toLocaleTimeString(lang, {
hour: "2-digit",
minute: "2-digit",
hour12: hour12,
})}
</li>
<li
Expand Down Expand Up @@ -601,14 +608,17 @@ class MeteofranceWeatherCard extends LitElement {
let rainForecastTimeRef = new Date(
rainForecastEntity.attributes["forecast_time_ref"]
);
const hour12 = this.hass.locale.time_format == "12" ? true : this.hass.locale.time_format == "24" ? false : undefined;
let rainForecastStartTime = rainForecastTimeRef.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
hour12: hour12,
});
rainForecastTimeRef.setHours(rainForecastTimeRef.getHours() + 1);
let rainForecastEndTime = rainForecastTimeRef.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
hour12: hour12,
});

return [rainForecastStartTime, rainForecastEndTime];
Expand Down