|
2 | 2 | from typing import List, Any, Optional
|
3 | 3 |
|
4 | 4 | from gehomesdk import ErdConvertableDrawerMode
|
| 5 | +from homeassistant.const import TEMP_FAHRENHEIT |
| 6 | +from homeassistant.util.unit_system import UnitSystem |
5 | 7 | from ..common import OptionsConverter
|
6 | 8 |
|
7 | 9 | _LOGGER = logging.getLogger(__name__)
|
8 | 10 |
|
| 11 | +_TEMP_MAP = { |
| 12 | + ErdConvertableDrawerMode.MEAT: 29, |
| 13 | + ErdConvertableDrawerMode.BEVERAGE: 33, |
| 14 | + ErdConvertableDrawerMode.SNACK: 37, |
| 15 | + ErdConvertableDrawerMode.WINE: 42 |
| 16 | +} |
| 17 | + |
9 | 18 | class ConvertableDrawerModeOptionsConverter(OptionsConverter):
|
10 |
| - def __init__(self): |
| 19 | + def __init__(self, units: UnitSystem): |
11 | 20 | super().__init__()
|
12 | 21 | self._excluded_options = [
|
13 | 22 | ErdConvertableDrawerMode.UNKNOWN0,
|
14 | 23 | ErdConvertableDrawerMode.UNKNOWN1,
|
15 | 24 | ErdConvertableDrawerMode.NA
|
16 | 25 | ]
|
| 26 | + self._units = units |
17 | 27 |
|
18 | 28 | @property
|
19 | 29 | def options(self) -> List[str]:
|
20 |
| - return [i.stringify() for i in ErdConvertableDrawerMode if i not in self._excluded_options] |
| 30 | + return [self.to_option_string(i) for i in ErdConvertableDrawerMode if i not in self._excluded_options] |
| 31 | + |
21 | 32 | def from_option_string(self, value: str) -> Any:
|
22 | 33 | try:
|
23 |
| - return ErdConvertableDrawerMode[value.upper()] |
| 34 | + v = value.split(" ")[0] |
| 35 | + return ErdConvertableDrawerMode[v.upper()] |
24 | 36 | except:
|
25 | 37 | _LOGGER.warn(f"Could not set hood light level to {value.upper()}")
|
26 | 38 | return ErdConvertableDrawerMode.NA
|
27 | 39 | def to_option_string(self, value: ErdConvertableDrawerMode) -> Optional[str]:
|
28 | 40 | try:
|
29 | 41 | if value is not None:
|
30 |
| - return value.stringify() |
| 42 | + v = value.stringify() |
| 43 | + t = _TEMP_MAP.get(value, None) |
| 44 | + |
| 45 | + if t and self._units.is_metric: |
| 46 | + t = self._units.temperature(float(t), TEMP_FAHRENHEIT) |
| 47 | + t = round(t,1) |
| 48 | + |
| 49 | + if t: |
| 50 | + return f"{v} ({t}{self._units.temperature_unit})" |
| 51 | + return v |
31 | 52 | except:
|
32 | 53 | pass
|
| 54 | + |
33 | 55 | return ErdConvertableDrawerMode.NA.stringify()
|
34 | 56 |
|
0 commit comments