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

Feature: Add option to show current weather as the first segment #493

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class HourlyWeatherCardEditor extends ScopedRegistryHost(LitElement) impl
return this._config?.icons ?? false;
}

get _show_current(): boolean {
return this._config?.show_current ?? false;
}

get _show_wind(): WindType {
return this._config?.show_wind ?? 'false';
}
Expand Down Expand Up @@ -180,6 +184,13 @@ export class HourlyWeatherCardEditor extends ScopedRegistryHost(LitElement) impl
@change=${this._valueChanged}
></mwc-switch>
</mwc-formfield>
<mwc-formfield .label=${localize('editor.show_current_weather')}>
<mwc-switch
.checked=${this._show_current === true}
.configValue=${'show_current'}
@change=${this._valueChanged}
></mwc-switch>
</mwc-formfield>
`;
}

Expand Down
14 changes: 13 additions & 1 deletion src/hourly-weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,19 @@ export class HourlyWeatherCard extends LitElement {

const entityId: string = config.entity;
const state = this.hass.states[entityId];
const { forecast } = state.attributes as { forecast: ForecastSegment[] };
const forecast_only = state.attributes.forecast as ForecastSegment[];
const current: ForecastSegment = {
clouds: state.attributes.clouds, // 100
condition: state.state as string, // "cloudy"
datetime: state.last_updated, // "2022-06-03T22:00:00+00:00"
precipitation: state.attributes.precipitation, // 0
precipitation_probability: state.attributes.precipitation_probability, // 85
pressure: state.attributes.pressure, // 1007
temperature: state.attributes.temperature, // 61
wind_bearing: state.attributes.wind_bearing, // 153 | 'SSW'
wind_speed: state.attributes.wind_speed, // 3.06
};
const forecast = config.show_current === true ? [current, ...forecast_only] : forecast_only;
const windSpeedUnit = state.attributes.wind_speed_unit ?? '';
const precipitationUnit = state.attributes.precipitation_unit ?? '';
const numSegments = parseInt(config.num_segments ?? config.num_hours ?? '12', 10);
Expand Down
3 changes: 2 additions & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"barb": "As wind barb",
"barb_and_speed": "As wind barb and speed",
"barb_and_direction": "As wind barb and direction",
"barb_speed_and_direction": "As wind barb, speed, and direction"
"barb_speed_and_direction": "As wind barb, speed, and direction",
"show_current_weather": "Show current weather"
},
"errors": {
"missing_entity": "entity is missing in configuration",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface HourlyWeatherCardConfig extends LovelaceCardConfig {
icons?: boolean;
offset?: string; // number
colors?: ColorConfig;
show_current?: boolean;
hide_bar?: boolean;
hide_hours?: boolean;
hide_temperatures?: boolean;
Expand Down