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

climate: Add halves when divider is at least 2 #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion tuyaha/devices/climate.py
Expand Up @@ -76,6 +76,10 @@ def has_decimal(self):
"""Return if temperature values support decimal"""
return self._divider >= 10

def has_halves(self):
"""Return if temperature values support halves"""
return self._divider % 2 == 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Divider can be overridden by home assistant.
If someone wants to divide by 3, he will not have halves.
What the reason behind using this divider to know that the device support halves?


def temperature_unit(self):
"""Return the temperature unit for the device"""
if not self._unit:
Expand Down Expand Up @@ -110,6 +114,8 @@ def target_temperature(self):

def target_temperature_step(self):
if self.has_decimal():
return 0.1
elif self.has_halves():
return 0.5
return 1.0

Expand Down Expand Up @@ -157,7 +163,10 @@ def set_temperature(self, temperature):
divider = self._divider or 1

if not self.has_decimal():
temp_val = round(float(temperature))
if self.has_halves():
temp_val = round(float(temperature) * 20.0) / 20.0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the magic number 20 mean?
I don't understand what you're doing here, at the end you'll have some decimal values here. So It's the same as round(number, 1).

For example: temperature=17.7
round(float(17.7) * 20.0) / 20.0 = 17.7

else
temp_val = round(float(temperature))
set_val = temp_val * divider
else:
temp_val = set_val = round(float(temperature) * divider)
Expand Down