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

Conversation

3v1n0
Copy link

@3v1n0 3v1n0 commented Nov 26, 2020

Various climate devices use a temperature divider of 2, and they do
allow use of halves values, however current tuyaha doesn't allow this.

As per this, add an has_halves function that will return true for
multiple of 2, while fix target_temperature_step() so that it returns
the proper value depending we support decimals or halves

@3v1n0 3v1n0 changed the title climate: Enable decimals when divider is at least 2 climate: Add halves when divider is at least 2 Nov 26, 2020
3v1n0 added a commit to 3v1n0/ha-core that referenced this pull request Nov 26, 2020
Devices may use a temperature divider of 2, in such case tuyah won't
properly handle its halves values using whole precision.

Fix this by checking if the device supports halves, and in such case to
return such precision

This needs PaulAnnekov/tuyaha#54
3v1n0 added a commit to 3v1n0/ha-core that referenced this pull request Nov 26, 2020
Devices may use a temperature divider of 2, in such case tuyah won't
properly handle its halves values using whole precision.

Fix this by checking if the device supports halves, and in such case to
return such precision

This needs PaulAnnekov/tuyaha#54
Various climate devices use a temperature divider of 2, and they do
allow use of halves values, however current tuyaha doesn't allow this.

As per this, add an has_halves function that will return true for
multiple of 2, while fix target_temperature_step() so that it returns
the proper value depending we support decimals or halves
@@ -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

@@ -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?

@ollo69
Copy link
Contributor

ollo69 commented Feb 17, 2021

I think that this PR should be closed because obsolete.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants