Skip to content

Commit

Permalink
Disable night partly cloudy rendering for now due to bug
Browse files Browse the repository at this point in the history
  • Loading branch information
decompil3d committed Jun 17, 2024
1 parent ea933ac commit 362ffc1
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 199 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,23 @@ color in your Home Assistant theme.
Some conditions will default to whatever the value is of some other condition. For example, `fog` will default to
whatever `cloudy` is.

| Key | Default |
|-----------------------|------------------------|
| `clear-night` | `#111` |
| `cloudy` | `#777` |
| `fog` | same as `cloudy` |
| `hail` | `#2b5174` |
| `lightning` | same as `rainy` |
| `lightning-rainy` | same as `rainy` |
| `partlycloudy` | `#b3dbff` |
| `night-partly-cloudy` | `#333` |
| `pouring` | same as `rainy` |
| `rainy` | `#44739d` |
| `snowy` | `#fff` |
| `snowy-rainy` | same as `partlycloudy` |
| `sunny` | `#90cbff` |
| `windy` | same as `sunny` |
| `windy-variant` | same as `sunny` |
| `exceptional` | `#ff9d00` |
| Key | Default |
|-------------------|------------------------|
| `clear-night` | `#000` |
| `cloudy` | `#777` |
| `fog` | same as `cloudy` |
| `hail` | `#2b5174` |
| `lightning` | same as `rainy` |
| `lightning-rainy` | same as `rainy` |
| `partlycloudy` | `#b3dbff` |
| `pouring` | same as `rainy` |
| `rainy` | `#44739d` |
| `snowy` | `#fff` |
| `snowy-rainy` | same as `partlycloudy` |
| `sunny` | `#90cbff` |
| `windy` | same as `sunny` |
| `windy-variant` | same as `sunny` |
| `exceptional` | `#ff9d00` |

### Sample colors configuration

Expand Down
33 changes: 11 additions & 22 deletions cypress/e2e/weather-bar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ describe('Weather bar', () => {
.find('div.axes')
.should('exist');
});
it('has the correct number of condition blocks', () => {
it('has the current number of condition blocks', () => {
cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.should('have.length', 5);
.should('have.length', 4);
});
const expectedConditions = [
'Cloudy',
'Partly cloudy',
'Partly cloudy (night)',
'Sunny',
'Clear'
];
Expand All @@ -49,15 +48,13 @@ describe('Weather bar', () => {

const expectedWidths = [
6,
2,
4,
6,
10,
2
];
const expectedColors = [
'rgb(119, 119, 119)',
'rgb(179, 219, 255)',
'rgb(51, 51, 51)',
'rgb(144, 203, 255)',
'rgb(17, 17, 17)'
];
Expand All @@ -80,9 +77,8 @@ describe('Weather bar', () => {
const expectedCustomColors = [
'rgb(255, 0, 0)',
'rgb(0, 255, 0)',
'rgb(0, 255, 255)',
'rgb(0, 0, 255)',
'rgb(34, 34, 34)'
'rgb(0, 255, 255)'
];

it('uses custom colors when specified', () => {
Expand All @@ -91,8 +87,7 @@ describe('Weather bar', () => {
cloudy: '#FF0000',
partlycloudy: 'rgb(0, 255, 0)',
sunny: 'hsl(240, 100%, 50%)',
"night-partly-cloudy": 'cyan',
"clear-night": '#222',
"clear-night": 'cyan'
}
});
cy.get('weather-bar')
Expand All @@ -107,9 +102,8 @@ describe('Weather bar', () => {
const expectedCustomObjectColors = [
{ bg: 'rgb(18, 52, 86)', fg: 'rgb(0, 0, 0)' },
{ bg: 'rgb(179, 219, 255)', fg: 'rgb(123, 45, 6)' },
{ bg: 'rgb(50, 205, 50)', fg: 'rgb(0, 0, 0)' },
{ bg: 'rgb(0, 255, 0)', fg: 'rgb(255, 0, 255)' },
{ bg: 'rgb(34, 34, 34)', fg: 'rgb(255, 255, 255)' }
{ bg: 'rgb(50, 205, 50)', fg: 'rgb(0, 0, 0)' }
];

it('uses custom colors when specified as color objects', () => {
Expand All @@ -125,11 +119,7 @@ describe('Weather bar', () => {
background: 'hsl(120, 100%, 50%)',
foreground: 'magenta'
},
"night-partly-cloudy": 'limegreen',
"clear-night": {
background: '#222',
foreground: 'white'
}
"clear-night": 'limegreen'
}
});
cy.get('weather-bar')
Expand All @@ -146,7 +136,7 @@ describe('Weather bar', () => {
cy.get('weather-bar')
.shadow()
.find('div.bar > div > span.condition-label')
.should('have.length', 5)
.should('have.length', 4)
.each((el, i) => {
cy.wrap(el).should('have.text', expectedConditions[i]);
});
Expand All @@ -166,7 +156,7 @@ describe('Weather bar', () => {
cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.its(3)
.its(2)
.find('span.condition-label')
.should(label => {
const cs = window.getComputedStyle(label.get(0));
Expand All @@ -184,7 +174,6 @@ describe('Weather bar', () => {
const expectedIcons = [
'mdi:weather-cloudy',
'mdi:weather-partly-cloudy',
'mdi:weather-night-partly-cloudy',
'mdi:weather-sunny',
'mdi:weather-night'
];
Expand All @@ -193,7 +182,7 @@ describe('Weather bar', () => {
cy.get('weather-bar')
.shadow()
.find('div.bar > div > span.condition-icon')
.should('have.length', 5)
.should('have.length', 4)
.find('ha-icon')
.each((el, i) => {
cy.wrap(el).invoke('attr', 'icon')
Expand All @@ -205,7 +194,7 @@ describe('Weather bar', () => {
cy.get('weather-bar')
.shadow()
.find('div.bar > div')
.its(1)
.its(3)
.find('span.condition-icon')
.should(icon => {
const cs = window.getComputedStyle(icon.get(0));
Expand Down
4 changes: 0 additions & 4 deletions cypress/fixtures/harness.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
}
},
},
config: {
latitude: 51.48346270,
longitude: 0.05862020,
},
states: {
'weather.mock': {
attributes: {
Expand Down
26 changes: 10 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"home-assistant-js-websocket": "^9.3.0",
"is-valid-css-color": "^2.0.3",
"lit": "^3.1.4",
"solar-calculator": "^0.3.0",
"tippy.js": "^6.3.7"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions src/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const LABELS = {
'lightning': 'conditions.thunderstorm',
'lightning-rainy': 'conditions.thunderstorm',
'partlycloudy': 'conditions.partlyCloudy',
'night-partly-cloudy': 'conditions.partlyCloudyNight',
'pouring': 'conditions.heavyRain',
'rainy': 'conditions.rain',
'snowy': 'conditions.snow',
Expand All @@ -23,7 +22,6 @@ export const ICONS = {
'hail': 'hail',
'lightning': 'lightning',
'lightning-rainy': 'lightning-rainy',
'night-partly-cloudy': 'weather-night-partly-cloudy',
'partlycloudy': 'weather-partly-cloudy',
'pouring': 'pouring',
'rainy': 'rainy',
Expand Down
19 changes: 2 additions & 17 deletions src/hourly-weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
formatDateShort,
} from 'custom-card-helpers'; // This is a community maintained npm module with common helper functions/types. https://github.com/custom-cards/custom-card-helpers
import { isValidColorName, isValidHSL, isValidRGB } from 'is-valid-css-color';
import { rise as sunrise, set as sunset } from 'solar-calculator';

import type {
ColorConfig,
Expand Down Expand Up @@ -414,11 +413,11 @@ export class HourlyWeatherCard extends LitElement {
}

private getConditionListFromForecast(forecast: ForecastSegment[], numSegments: number, offset: number): ConditionSpan[] {
let lastCond: string = this.getAdjustedConditionForForecastSegment(forecast[offset]);
let lastCond: string = forecast[offset].condition;
let j = 0;
const res: ConditionSpan[] = [[lastCond, 1]];
for (let i = offset + 1; i < numSegments + offset; i++) {
const cond: string = this.getAdjustedConditionForForecastSegment(forecast[i]);
const cond: string = forecast[i].condition;
if (cond === lastCond) {
res[j][1]++;
} else {
Expand All @@ -430,20 +429,6 @@ export class HourlyWeatherCard extends LitElement {
return res;
}

private getAdjustedConditionForForecastSegment(fs: ForecastSegment): string {
const when = new Date(fs.datetime);
const { latitude, longitude } = this.hass.config;
const noonUTCOnDay = new Date(when.toLocaleDateString());
noonUTCOnDay.setUTCHours(12, 0, 0, 0);
const rise = sunrise(noonUTCOnDay, latitude, longitude);
const set = sunset(noonUTCOnDay, latitude, longitude);
const isDay = when >= rise && when <= set;
if (!isDay && fs.condition === 'partlycloudy') {
return 'night-partly-cloudy';
}
return fs.condition;
}

private getTemperatures(forecast: ForecastSegment[], numSegments: number, offset: number): SegmentTemperature[] {
const temperatures: SegmentTemperature[] = [];
for (let i = offset; i < numSegments + offset; i++) {
Expand Down
Loading

0 comments on commit 362ffc1

Please sign in to comment.