-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix, cleanup and add units of measurement on entity weather card * Move to units component * Add unit of measurement to state
- Loading branch information
Showing
3 changed files
with
110 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { HassConfig } from 'home-assistant-js-websocket'; | ||
|
||
export const weatherMap: { [item: string]: string } = { | ||
'clear-night': 'weather-night', | ||
cloudy: 'weather-cloudy', | ||
fog: 'weather-fog', | ||
hail: 'weather-hail', | ||
lightning: 'weather-lightning', | ||
'lightning-rainy': 'weather-lightning-rainy', | ||
partlycloudy: 'weather-partly-cloudy', | ||
pouring: 'weather-pouring', | ||
rainy: 'weather-rainy', | ||
snowy: 'weather-snowy', | ||
'snowy-rainy': 'weather-snowy-rainy', | ||
sunny: 'weather-sunny', | ||
windy: 'weather-windy', | ||
'windy-variant': 'weather-windy-variant', | ||
}; | ||
|
||
export const weatherNameMap: { [item: string]: string } = { | ||
'clear-night': 'Clear', | ||
cloudy: 'Cloudy', | ||
fog: 'Fog', | ||
hail: 'Hail', | ||
lightning: 'Lightning', | ||
'lightning-rainy': 'Lightning & Rain', | ||
partlycloudy: 'Partly Cloudy', | ||
pouring: 'Rain', | ||
rainy: 'Rain', | ||
snowy: 'Snow', | ||
'snowy-rainy': 'Snow & Rain', | ||
sunny: 'Sunny', | ||
windy: 'Windy', | ||
'windy-variant': 'Windy', | ||
}; | ||
|
||
export function getUnit( | ||
measure: string, | ||
hassConfig?: HassConfig | ||
): string | null { | ||
if (hassConfig) { | ||
const lengthUnit = hassConfig.unit_system.length || ''; | ||
switch (measure) { | ||
case 'length': | ||
case 'mass': | ||
case 'volume': | ||
case 'temperature': | ||
return hassConfig.unit_system[measure]; | ||
case 'pressure': | ||
return lengthUnit === 'km' ? ' hPa' : ' inHg'; | ||
case 'precipitation': | ||
return lengthUnit === 'km' ? ' mm' : ' in'; | ||
case 'wind_speed': | ||
return lengthUnit === 'km' ? ' km/h' : ' mph'; | ||
case 'wind_bearing': | ||
return '°'; | ||
case 'humidity': | ||
return '%'; | ||
default: | ||
return ''; | ||
} | ||
} else return null; | ||
} |