Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Commit

Permalink
Climate fix
Browse files Browse the repository at this point in the history
Fix issue in setting temperature for some devices (issue #49)
  • Loading branch information
ollo69 committed Dec 8, 2020
1 parent bf20a0c commit ddb72f6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ but all selected devices must be of the same type.

- **Current Temperature value divider**: `current temperature` reported by device will be divided by this value.

- **Set Temperature value divided**: when checked use temperature value previously divided in set command.

- **Min target temperature**: set the minimum allowed `target temperature` for the entity.

- **Max target temperature**: set the maximum allowed `target temperature` for the entity.
Expand Down
7 changes: 6 additions & 1 deletion custom_components/tuya_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CONF_EXT_TEMP_SENSOR,
CONF_MAX_TEMP,
CONF_MIN_TEMP,
CONF_SET_TEMP_DIVIDED,
CONF_TEMP_DIVIDER,
DOMAIN,
SIGNAL_CONFIG_ENTITY,
Expand Down Expand Up @@ -112,6 +113,7 @@ def __init__(self, tuya, platform):
self._def_hvac_mode = HVAC_MODE_AUTO
self._min_temp = None
self._max_temp = None
self._set_temp_divided = False
self._temp_entity = None
self._temp_entity_error = False

Expand All @@ -126,6 +128,7 @@ def _process_config(self):
self._tuya.set_unit("FAHRENHEIT" if unit == TEMP_FAHRENHEIT else "CELSIUS")
self._tuya.temp_divider = config.get(CONF_TEMP_DIVIDER, 0)
self._tuya.curr_temp_divider = config.get(CONF_CURR_TEMP_DIVIDER, 0)
self._set_temp_divided = config.get(CONF_SET_TEMP_DIVIDED, False)
min_temp = config.get(CONF_MIN_TEMP, 0)
max_temp = config.get(CONF_MAX_TEMP, 0)
if min_temp >= max_temp:
Expand Down Expand Up @@ -224,7 +227,9 @@ def fan_modes(self):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
if ATTR_TEMPERATURE in kwargs:
self._tuya.set_temperature(kwargs[ATTR_TEMPERATURE])
self._tuya.set_temperature(
kwargs[ATTR_TEMPERATURE], self._set_temp_divided
)

def set_fan_mode(self, fan_mode):
"""Set new target fan mode."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/tuya_custom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CONF_QUERY_DEVICE,
CONF_QUERY_INTERVAL,
CONF_SUPPORT_COLOR,
CONF_SET_TEMP_DIVIDED,
CONF_TEMP_DIVIDER,
CONF_TUYA_MAX_COLTEMP,
DEFAULT_DISCOVERY_INTERVAL,
Expand Down Expand Up @@ -386,6 +387,10 @@ def _get_climate_schema(curr_conf, device, entities_list):
CONF_CURR_TEMP_DIVIDER,
default=curr_conf.get(CONF_CURR_TEMP_DIVIDER, 0),
): vol.All(vol.Coerce(int), vol.Clamp(min=0)),
vol.Optional(
CONF_SET_TEMP_DIVIDED,
default=curr_conf.get(CONF_SET_TEMP_DIVIDED, False),
): bool,
vol.Optional(
CONF_MIN_TEMP, default=curr_conf.get(CONF_MIN_TEMP, 0),
): int,
Expand Down
1 change: 1 addition & 0 deletions custom_components/tuya_custom/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CONF_MIN_TEMP = "min_temp"
CONF_QUERY_DEVICE = "query_device"
CONF_QUERY_INTERVAL = "query_interval"
CONF_SET_TEMP_DIVIDED = "set_temp_divided"
CONF_SUPPORT_COLOR = "support_color"
CONF_TEMP_DIVIDER = "temp_divider"
CONF_TUYA_MAX_COLTEMP = "tuya_max_coltemp"
Expand Down
1 change: 1 addition & 0 deletions custom_components/tuya_custom/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"unit_of_measurement": "Temperature unit used by device",
"temp_divider": "Temperature values divider (0 = use default)",
"curr_temp_divider": "Current Temperature value divider (0 = use default)",
"set_temp_divided": "Use Temperature value previous divided in set command",
"min_temp": "Min target temperature (use min and max = 0 for default)",
"max_temp": "Max target temperature (use min and max = 0 for default)",
"ext_temp_sensor": "Sensor for current temperature"
Expand Down
1 change: 1 addition & 0 deletions custom_components/tuya_custom/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"min_temp": "Min target temperature (use min and max = 0 for default)",
"support_color": "Force color support",
"temp_divider": "Temperature values divider (0 = use default)",
"set_temp_divided": "Use Temperature value previous divided in set command",
"tuya_max_coltemp": "Max color temperature reported by device",
"unit_of_measurement": "Temperature unit used by device",
"ext_temp_sensor": "Sensor for current temperature"
Expand Down
11 changes: 7 additions & 4 deletions custom_components/tuya_custom/tuyaha/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ def min_humidity(self):
def max_humidity(self):
pass

def set_temperature(self, temperature):
def set_temperature(self, temperature, use_divider=False):
"""Set new target temperature."""

# the value used to set temperature is scaled based on the configured divider
divider = self._divider or 1

if not self.has_decimal():
temp_val = round(float(temperature))
set_val = temp_val * divider
if use_divider:
if self.has_decimal():
temp_val = round(float(temperature), 1)
else:
temp_val = round(float(temperature))
set_val = round(temp_val * divider)
else:
temp_val = set_val = round(float(temperature) * divider)
if self._control_device("temperatureSet", {"value": temp_val}):
Expand Down

0 comments on commit ddb72f6

Please sign in to comment.