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

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

Open
3v1n0 wants to merge 1 commit intoPaulAnnekov:masterfrom
3v1n0:fix-decimals
Open

climate: Add halves when divider is at least 2#54
3v1n0 wants to merge 1 commit intoPaulAnnekov:masterfrom
3v1n0:fix-decimals

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

@matitalatina matitalatina Dec 8, 2020

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


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.

3 participants