Skip to content

Commit

Permalink
Fix sensor_value_translation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Jun 23, 2022
1 parent 09e7832 commit 2940963
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions custom_components/home_connect_alt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CONF_LANG = "language"
CONF_CACHE = "cache"
CONF_SENSORS_TRANSLATION = "sensor_value_translation"
CONF_SENSORS_TRANSLATION_SERVER = "server"
CONF_NAME_TEMPLATE = "name_template"
CONF_LOG_MODE = "log_mode"

Expand Down
12 changes: 6 additions & 6 deletions custom_components/home_connect_alt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.helpers.typing import ConfigType

from .common import Configuration, EntityBase, EntityManager
from .const import CONF_NAME_TEMPLATE, DEVICE_ICON_MAP, DOMAIN, CONF_SENSORS_TRANSLATION, HOME_CONNECT_DEVICE, SPECIAL_ENTITIES
from .const import CONF_NAME_TEMPLATE, CONF_SENSORS_TRANSLATION_SERVER, DEVICE_ICON_MAP, DOMAIN, CONF_SENSORS_TRANSLATION, HOME_CONNECT_DEVICE, SPECIAL_ENTITIES

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,7 +109,7 @@ def native_value(self):
"""Return the state of the sensor."""
prog = self._appliance.selected_program if self._conf['program_type'] == 'selected' else self._appliance.active_program
if prog:
if prog.name and self._conf[CONF_SENSORS_TRANSLATION]:
if prog.name and self._conf[CONF_SENSORS_TRANSLATION] == CONF_SENSORS_TRANSLATION_SERVER:
return prog.name
else:
return prog.key
Expand Down Expand Up @@ -187,9 +187,9 @@ def native_value(self):
return f"{h}:{m:02d}"
if self.internal_unit=="gram":
return round(option.value/1000, 1)
if option.displayvalue and self._conf[CONF_SENSORS_TRANSLATION]:
if option.displayvalue and self._conf[CONF_SENSORS_TRANSLATION] == CONF_SENSORS_TRANSLATION_SERVER:
return option.displayvalue
if isinstance(option.value, str) and self._conf[CONF_SENSORS_TRANSLATION]:
if isinstance(option.value, str) and self._conf[CONF_SENSORS_TRANSLATION] == CONF_SENSORS_TRANSLATION_SERVER:
if option.value.endswith(".Off"):
return "Off"
if option.value.endswith(".On"):
Expand Down Expand Up @@ -223,7 +223,7 @@ def native_value(self):
"""Return the state of the sensor."""
status = self._appliance.status.get(self._key)
if status:
if status.displayvalue and self._conf[CONF_SENSORS_TRANSLATION]:
if status.displayvalue and self._conf[CONF_SENSORS_TRANSLATION] == CONF_SENSORS_TRANSLATION_SERVER:
return status.displayvalue
return status.value
return None
Expand Down Expand Up @@ -255,7 +255,7 @@ def native_value(self):
"""Return the state of the sensor."""
setting = self._appliance.settings.get(self._key)
if setting:
if setting.displayvalue and self._conf[CONF_SENSORS_TRANSLATION]:
if setting.displayvalue and self._conf[CONF_SENSORS_TRANSLATION] == CONF_SENSORS_TRANSLATION_SERVER:
return setting.displayvalue
return setting.value
return None
Expand Down

0 comments on commit 2940963

Please sign in to comment.