Skip to content

Commit

Permalink
Cosmetic changes after contribution of new humidity feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pkissling committed Mar 13, 2024
1 parent 7e3e456 commit b29a8e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ time_format: 24
date_pattern: ccc, d.MM.yy
hide_today_section: false
hide_forecast_section: false
hide_humidity: false
show_humidty: false
hide_clock: false
hide_date: false
hourly_forecast: false
Expand All @@ -126,15 +126,15 @@ time_zone: null
| title | string | **Optional** | Title of the card | `''` |
| sun_entity | boolean | **Optional** | ID of the sun entity. Used to determine whether to show a day or night icon. If sun integration is not enabled, day icon will be shown | `sun.sun` |
| temperature_sensor | string | **Optional** | ID of the temperature sensor entity. Used to show the current temperature based on a sensor value instead of the weather forecast | `''` |
| humidity_sensor | string | **Optional** | ID of the humidity sensor entity. Used to show the current humidity based on a sensor value | `''` |
| humidity_sensor | string | **Optional** | ID of the humidity sensor entity. Used to show the current humidity based on a sensor value, if `show_humidity` is set to `true` | `''` |
| weather_icon_type | `line` \| `fill` | **Optional** | Appearance of the large weather icon | `line` |
| animated_icon | boolean | **Optional** | Whether the large weather icon should be animated | `true` |
| forecast_rows | number | **Optional** | The amount of weather forecast rows to show. Depending on `hourly_forecast` each row either corresponds to a day or an hour | `5` |
| locale | string[^2] | **Optional** | Language to use for language specific text and date/time formatting. If not provided, falls back to the locale set in HA or, if not set in HA, to `en-GB` | `en-GB` |
| time_format | `24` \| `12` | **Optional** | Format used to display the time. If not provided, falls back to the default time format of the configured `locale`. This option is ignored if `time_pattern` is set. | `24` |
| time_pattern | string | **Optional** | Pattern to use for time formatting. See [luxon](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) for valid tokens. If not provided, falls back to time_format option. | `null` |
| date_pattern | string | **Optional** | Pattern to use for date formatting. If not provided, falls back to a localized default date formatting. See [luxon](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) for valid tokens | `D` |
| show_humidity | boolean | **Optional** | Shows the humidity in the today section | `false` |
| show_humidity | boolean | **Optional** | Shows the humidity in the today section | `false` |
| hide_today_section | boolean | **Optional** | Hides the cards today section (upper section), containing the large weather icon, clock and current date | `false` |
| hide_forecast_section | boolean | **Optional** | Hides the cards forecast section (lower section),containing the weather forecast | `false` |
| hide_clock | boolean | **Optional** | Hides the clock from the today section and prominently displays the current temperature instead | `false` |
Expand Down
12 changes: 5 additions & 7 deletions src/clock-weather-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ export class ClockWeatherCard extends LitElement {

private getCurrentTemperature (): number | null {
if (this.config.temperature_sensor) {
const temperatueSensor = this.hass.states[this.config.temperature_sensor] as TemperatureSensor | undefined
const temp = temperatueSensor?.state ? parseFloat(temperatueSensor.state) : undefined
const unit = temperatueSensor?.attributes.unit_of_measurement ?? this.getConfiguredTemperatureUnit()
const temperatureSensor = this.hass.states[this.config.temperature_sensor] as TemperatureSensor | undefined
const temp = temperatureSensor?.state ? parseFloat(temperatureSensor.state) : undefined
const unit = temperatureSensor?.attributes.unit_of_measurement ?? this.getConfiguredTemperatureUnit()
if (temp !== undefined && !isNaN(temp)) {
return this.toConfiguredTempWithoutUnit(unit, temp)
}
Expand All @@ -460,11 +460,9 @@ export class ClockWeatherCard extends LitElement {

private getCurrentHumidity (): number | null {
if (this.config.humidity_sensor) {
const humiditeeSensor = this.hass.states[this.config.humidity_sensor] as HumiditySensor | undefined
const humid = humiditeeSensor?.state ? parseFloat(humiditeeSensor.state) : undefined
// Removed the unit handling as it's not needed for humidity
const humiditySensor = this.hass.states[this.config.humidity_sensor] as HumiditySensor | undefined
const humid = humiditySensor?.state ? parseFloat(humiditySensor.state) : undefined
if (humid !== undefined && !isNaN(humid)) {
// Directly return the humidity value without converting based on unit
return humid
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface MergedClockWeatherCardConfig extends LovelaceCardConfig {
date_pattern: string
hide_today_section: boolean
hide_forecast_section: boolean
show_humidity?: boolean
show_humidity: boolean
hourly_forecast: boolean
hide_clock: boolean
hide_date: boolean
Expand Down Expand Up @@ -89,7 +89,6 @@ export interface MergedWeatherForecast {
datetime: DateTime
condition: string
temperature: number
humidity?: number
precipitation: number
precipitation_probability: number
templow: number
Expand Down

0 comments on commit b29a8e4

Please sign in to comment.