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

feat: add support for wind barbs when wind_bearing is a string #785

Merged
merged 5 commits into from
Jan 13, 2025
Merged
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
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ decimal by 1). Otherwise, the integration may complain of a duplicate unique ID.
## Options

| Name | Type | Requirement | Description | Default |
|----------------------------------|------------------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|
| -------------------------------- | ---------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `type` | string | **Required** | `custom:hourly-weather` | |
| `entity` | string | **Required** | Home Assistant weather entity ID. | |
| `forecast_type` | string | **Optional** | The type of forecast data to use. One of `hourly`, `daily`, or `twice-daily`. If not specified, the card will attempt to use the finest-grained data available. | |
Expand Down Expand Up @@ -125,7 +125,7 @@ label_spacing: |
## Action Options

| Name | Type | Requirement | Description | Default |
|-------------------|--------|--------------|----------------------------------------------------------------------------------------------------|-------------|
| ----------------- | ------ | ------------ | -------------------------------------------------------------------------------------------------- | ----------- |
| `action` | string | **Required** | Action to perform (more-info, toggle, call-service, navigate url, none) | `more-info` |
| `navigation_path` | string | **Optional** | Path to navigate to (e.g. /lovelace/0/) when action defined as navigate | `none` |
| `url` | string | **Optional** | URL to open on click when action is url. The URL will open in a new tab | `none` |
Expand Down Expand Up @@ -155,7 +155,7 @@ Some conditions will default to whatever the value is of some other condition. F
whatever `cloudy` is.

| Key | Default |
|-------------------|------------------------|
| ----------------- | ---------------------- |
| `clear-night` | `#000` |
| `cloudy` | `#777` |
| `fog` | same as `cloudy` |
Expand Down Expand Up @@ -189,23 +189,23 @@ colors:
`icon_map` can be used to customize the icon used for each weather condition. It is specified as an object containing
one or more of the keys listed below and values that are valid icons installed in Home Assistant.

| Key | Default |
|-------------------|--------------------------------|
| `clear-night` | `mdi:weather-night` |
| `cloudy` | `mdi:weather-cloudy` |
| `fog` | `mdi:weather-fog` |
| `hail` | `mdi:weather-hail` |
| `lightning` | `mdi:weather-lightning` |
| `lightning-rainy` | `mdi:weather-lightning-rainy` |
| `partlycloudy` | `mdi:weather-partly-cloudy` |
| `pouring` | `mdi:weather-pouring` |
| `rainy` | `mdi:weather-rainy` |
| `snowy` | `mdi:weather-snowy` |
| `snowy-rainy` | `mdi:weather-snowy-rainy` |
| `sunny` | `mdi:weather-sunny` |
| `windy` | `mdi:weather-windy` |
| `windy-variant` | `mdi:weather-windy-variant` |
| `exceptional` | `mdi:alert-outline` |
| Key | Default |
| ----------------- | ----------------------------- |
| `clear-night` | `mdi:weather-night` |
| `cloudy` | `mdi:weather-cloudy` |
| `fog` | `mdi:weather-fog` |
| `hail` | `mdi:weather-hail` |
| `lightning` | `mdi:weather-lightning` |
| `lightning-rainy` | `mdi:weather-lightning-rainy` |
| `partlycloudy` | `mdi:weather-partly-cloudy` |
| `pouring` | `mdi:weather-pouring` |
| `rainy` | `mdi:weather-rainy` |
| `snowy` | `mdi:weather-snowy` |
| `snowy-rainy` | `mdi:weather-snowy-rainy` |
| `sunny` | `mdi:weather-sunny` |
| `windy` | `mdi:weather-windy` |
| `windy-variant` | `mdi:weather-windy-variant` |
| `exceptional` | `mdi:alert-outline` |

### Sample icon map configuration

Expand All @@ -228,9 +228,6 @@ icon_map:
- `barb-and-speed` Show wind direction as a wind barb arrow and also show speed
- `barb-speed-and-direction` Show wind direction as a wind barb arrow and also show speed and textual direction

> Note: If your weather entity uses cardinal directions (e.g. 'N', 'SW', etc.) rather than numeric degrees for
> `wind_bearing`, the `barb` option is not supported and will result in an error.

### Date Options

`show_date` can be one of the following values:
Expand Down Expand Up @@ -274,7 +271,6 @@ structure.
[maintenance-shield]: https://img.shields.io/maintenance/yes/2024.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/decompil3d/lovelace-hourly-weather.svg?style=for-the-badge
[releases]: https://github.com/decompil3d/lovelace-hourly-weather/releases

[icon_map]: #icon-map-options
[color]: #color-options
[wind]: #wind-options
Expand Down
232 changes: 29 additions & 203 deletions cypress/e2e/config.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,180 +68,6 @@ describe('Config', () => {
}
});
});
it('errors for wind barbs when entity uses cardinal directions for wind bearing', () => {
cy.addEntity({
'weather.wind_bearing_string': {
attributes: {
forecast: [
{
"datetime": "2022-07-21T17:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 4.67,
"wind_bearing": 'WSW',
"condition": "cloudy",
"clouds": 60,
"temperature": 84
},
{
"datetime": "2022-07-21T18:00:00+00:00",
"precipitation": 0.35,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.07,
"wind_bearing": 'WSW',
"condition": "cloudy",
"clouds": 75,
"temperature": 85
},
{
"datetime": "2022-07-21T19:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.16,
"wind_bearing": 'W',
"condition": "cloudy",
"clouds": 60,
"temperature": 85
},
{
"datetime": "2022-07-21T20:00:00+00:00",
"precipitation": 1.3,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.9,
"wind_bearing": 'W',
"condition": "partlycloudy",
"clouds": 49,
"temperature": 84
},
{
"datetime": "2022-07-21T21:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.78,
"wind_bearing": 'WNW',
"condition": "partlycloudy",
"clouds": 34,
"temperature": 84
},
{
"datetime": "2022-07-21T22:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1008,
"wind_speed": 5.06,
"wind_bearing": 'WNW',
"condition": "partlycloudy",
"clouds": 19,
"temperature": 83
}
]
}
}
});

cy.configure({
entity: 'weather.wind_bearing_string',
num_segments: '6',
show_wind: 'barb'
});

cy.get('hui-error-card')
.shadow()
.find('p')
.should('have.text', 'Wind barbs are not supported when weather entity uses cardinal directions for wind bearing.');
});
it('errors for wind barbs when entity uses cardinal directions for wind bearing and bars are shown with speed', () => {
cy.addEntity({
'weather.wind_bearing_string': {
attributes: {
forecast: [
{
"datetime": "2022-07-21T17:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 4.67,
"wind_bearing": 'WSW',
"condition": "cloudy",
"clouds": 60,
"temperature": 84
},
{
"datetime": "2022-07-21T18:00:00+00:00",
"precipitation": 0.35,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.07,
"wind_bearing": 'WSW',
"condition": "cloudy",
"clouds": 75,
"temperature": 85
},
{
"datetime": "2022-07-21T19:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.16,
"wind_bearing": 'W',
"condition": "cloudy",
"clouds": 60,
"temperature": 85
},
{
"datetime": "2022-07-21T20:00:00+00:00",
"precipitation": 1.3,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.9,
"wind_bearing": 'W',
"condition": "partlycloudy",
"clouds": 49,
"temperature": 84
},
{
"datetime": "2022-07-21T21:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.78,
"wind_bearing": 'WNW',
"condition": "partlycloudy",
"clouds": 34,
"temperature": 84
},
{
"datetime": "2022-07-21T22:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1008,
"wind_speed": 5.06,
"wind_bearing": 'WNW',
"condition": "partlycloudy",
"clouds": 19,
"temperature": 83
}
]
}
}
});

cy.configure({
entity: 'weather.wind_bearing_string',
num_segments: '6',
show_wind: 'barb-and-speed'
});

cy.get('hui-error-card')
.shadow()
.find('p')
.should('have.text', 'Wind barbs are not supported when weather entity uses cardinal directions for wind bearing.');
});
it('warns for invalid colors', () => {
cy.configure({
colors: {
Expand Down Expand Up @@ -383,8 +209,8 @@ describe('Config', () => {
expect(stub).has.been.called;
expect(stub.lastCall.lastArg.template).eqls('{{ offset_template }}');
});
});
});
});
describe('Forecast events from subscription', () => {
beforeEach(() => {
cy.enableForecastSubscriptions();
Expand Down Expand Up @@ -541,13 +367,13 @@ describe('Config', () => {

// Legacy attributes will have other conditions, but the subscription-based forecast will be snowy
cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});
});

it('uses forecast from subscription even when forecast attribute is not on entity', () => {
Expand Down Expand Up @@ -631,13 +457,13 @@ describe('Config', () => {
});

cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});
});

it('handles forecast updates via subscription', () => {
Expand Down Expand Up @@ -721,13 +547,13 @@ describe('Config', () => {
});

cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Snow')
});

cy.updateLastForecastSubscription([
{
Expand Down Expand Up @@ -799,13 +625,13 @@ describe('Config', () => {
]);

cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Rain')
});
.shadow()
.find('div.bar > div')
.each((el) => {
cy.wrap(el).invoke('attr', 'data-tippy-content')
.should('exist')
.and('eq', 'Rain')
});
});
});
});
Loading
Loading