Skip to content

Commit 8aab0d3

Browse files
committed
Polish towel rail helper and docs
1 parent a2730a7 commit 8aab0d3

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

tinytuya/Contrib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ The mode is mapped as follows:
254254
* "auto" is the scheduler, I could not find a way to set or configure the schedule through Tuya, only physically on the device
255255
* "hot" is the user configured temperature (`set_target_temperature`)
256256
* "cold" is the hard-coded 50 degrees C
257-
* "eco" is the heat for a defined duration and then switch back off again.
257+
* "eco" is the heat for a defined duration and then switches back off.
258258

259259
```python
260260
from tinytuya.Contrib import TowelRailHeaterDevice

tinytuya/Contrib/TowelRailHeaterDevice.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
set_timer() # expects number of minutes
2222
Inherited
2323
json = status() # returns json payload
24-
set_version(version) # 3.1 [default] or 3.3
24+
set_version(version) # protocol version (defaults to 3.4 for this device)
2525
set_socketPersistent(False/True) # False [default] or True
2626
set_socketNODELAY(False/True) # False or True [default]
2727
set_socketRetryLimit(integer) # retry count limit [default 5]
@@ -63,7 +63,7 @@ def __init__(self, *args, **kwargs):
6363
super(TowelRailHeaterDevice, self).__init__(*args, **kwargs)
6464

6565
def status_json(self):
66-
"""Wrapper around status() that replace DPS indices with human readable labels."""
66+
"""Wrapper around status() that replaces DPS indices with human readable labels."""
6767
status = self.status()["dps"]
6868
return {
6969
"Power On": status[self.DPS_POWER],
@@ -74,10 +74,10 @@ def status_json(self):
7474
}
7575

7676
def tuya_temperature_to_celsius(self, temperature):
77-
return int(temperature / 10)
77+
return round(float(temperature) / 10, 1)
7878

7979
def celsius_to_tuya_temperature(self, temperature):
80-
return int(temperature * 10)
80+
return int(round(float(temperature) * 10))
8181

8282
def get_current_temperature(self):
8383
status = self.status()["dps"]
@@ -99,7 +99,8 @@ def is_float(f):
9999
if not is_float(t):
100100
return
101101

102-
self.set_value(self.DPS_SET_TEMP, self.celsius_to_tuya_temperature(t))
102+
target = float(t)
103+
self.set_value(self.DPS_SET_TEMP, self.celsius_to_tuya_temperature(target))
103104

104105
def get_operating_mode(self):
105106
status = self.status()["dps"]

0 commit comments

Comments
 (0)