Skip to content

Commit 70ee123

Browse files
committed
turn fan_speed to property
It will allow use constructions like tion = tion.s3(mac) tion.fan_speed = 4 i.e. don't use set/get functions directly
1 parent 8ff7abf commit 70ee123

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tion/s3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def process_mode(mode_code: int) -> str:
6565

6666
result = {}
6767
try:
68+
self.fan_speed = int(list("{:02x}".format(response[2]))[1])
6869
result = {"code": 200,
6970
"mode": process_mode(int(list("{:02x}".format(response[2]))[0])),
70-
"fan_speed": int(list("{:02x}".format(response[2]))[1]),
71+
"fan_speed": self.fan_speed,
7172
"heater_temp": response[3],
7273
"heater": self._process_status(response[4] & 1),
7374
"status": self._process_status(response[4] >> 1 & 1),

tion/tion.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, mac: str):
4343
self._mac = mac
4444
self._btle: btle.Peripheral = btle.Peripheral(None)
4545
self._delegation = TionDelegation()
46+
self._fan_speed = 0
4647

4748
@abc.abstractmethod
4849
def _send_request(self, request: bytearray) -> bytearray:
@@ -184,3 +185,18 @@ def _enable_notifications(self):
184185
self._btle.withDelegate(self._delegation)
185186
self.notify.read()
186187
return result
188+
189+
@property
190+
def fan_speed(self):
191+
return self._fan_speed
192+
193+
@fan_speed.setter
194+
def fan_speed(self, new_speed: int):
195+
if 0 <= new_speed <= 6:
196+
self._fan_speed = new_speed
197+
198+
else:
199+
_LOGGER.warning("Incorrect new fan speed. Will use 1 instead")
200+
self._fan_speed = 1
201+
202+
# self.set({"fan_speed": new_speed})

0 commit comments

Comments
 (0)