Skip to content

Commit

Permalink
Merge pull request #243 from carlos-sarmiento/patch-1
Browse files Browse the repository at this point in the history
Add Fahrenheit to Celsius and Celsius to Fahrenheit formatter
  • Loading branch information
benct authored May 30, 2023
2 parents 996354c + 6a787a1 commit c0dbcfe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ for more detailed descriptions and examples.

The `format` option supports the following values:

| Value | Type | Description |
| -------------- | ----------- | ---------------------------------------------------------------- |
| relative | `timestamp` | Convert value to relative time (`5 minutes ago`) |
| total | `timestamp` | Convert value to relative time (`5 minutes`) |
| date | `timestamp` | Convert timestamp value to date |
| time | `timestamp` | Convert timestamp value to time |
| datetime | `timestamp` | Convert timestamp value to date and time |
| brightness | `number` | Convert brightness value to percentage |
| duration | `number` | Convert number of seconds to duration (`5:38:50`) |
| duration-m | `number` | Convert number of milliseconds to duration (`5:38:50`) |
| invert | `number` | Convert number from positive to negative or vice versa |
| kilo | `number` | Divide number value by 1000 (ex. `1500 W` -> `1.5 kW`) |
| position | `number` | Reverses a position percentage (ex. `70%` open -> `30%` closed) |
| precision<0-9> | `number` | Set decimal precision of number value (`precision3` -> `18.123`) |
| Value | Type | Description |
| --------------------- | ----------- | ---------------------------------------------------------------- |
| relative | `timestamp` | Convert value to relative time (`5 minutes ago`) |
| total | `timestamp` | Convert value to relative time (`5 minutes`) |
| date | `timestamp` | Convert timestamp value to date |
| time | `timestamp` | Convert timestamp value to time |
| datetime | `timestamp` | Convert timestamp value to date and time |
| brightness | `number` | Convert brightness value to percentage |
| duration | `number` | Convert number of seconds to duration (`5:38:50`) |
| duration-m | `number` | Convert number of milliseconds to duration (`5:38:50`) |
| invert | `number` | Convert number from positive to negative or vice versa |
| kilo | `number` | Divide number value by 1000 (ex. `1500 W` -> `1.5 kW`) |
| position | `number` | Reverses a position percentage (ex. `70%` open -> `30%` closed) |
| precision<0-9> | `number` | Set decimal precision of number value (`precision3` -> `18.123`) |
| celsius_to_fahrenheit | `number` | Converts a Celsius temperature to its Fahrenheit equivalent |
| fahrenheit_to_celsius | `number` | Converts a Fahrenheit temperature to its Celsius equivalent |

### Hiding

Expand Down
4 changes: 4 additions & 0 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const entityStateDisplay = (hass, stateObj, config) => {
value = formatNumber(value - value * 2, hass.locale);
} else if (config.format === 'position') {
value = formatNumber(100 - value, hass.locale);
} else if (config.format === 'celsius_to_fahrenheit') {
value = formatNumber(value * 1.8 + 32, hass.locale, { maximumFractionDigits: 0 });
} else if (config.format === 'fahrenheit_to_celsius') {
value = formatNumber((value - 32) * 5 / 9, hass.locale, { maximumFractionDigits: 1 });
}
return `${value}${unit ? ` ${unit}` : ''}`;
}
Expand Down

0 comments on commit c0dbcfe

Please sign in to comment.