1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-22 07:00:12 +01:00

Thermostat: get the 1st decimal place (#772)

This commit is contained in:
irsl 2024-04-09 21:06:38 +02:00 committed by GitHub
parent 634370d878
commit d7ed9855b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

25
broadlink/climate.py Normal file → Executable file
View File

@ -43,15 +43,28 @@ class hysen(Device):
return payload[0x02:p_len] return payload[0x02:p_len]
def _room_or_ext_temp_logic(self, payload, base_index):
base_temp = payload[base_index] / 2.0
add_offset = (payload[4] >> 3) & 1 # should offset be added?
offset_raw_value = (payload[17] >> 4) & 3 # offset value
offset = (offset_raw_value + 1) / 10 if add_offset else 0.0
return base_temp + offset
def _room_temp_logic(self, payload):
return self._room_or_ext_temp_logic(payload, 5)
def _ext_temp_logic(self, payload):
return self._room_or_ext_temp_logic(payload, 18)
def get_temp(self) -> float: def get_temp(self) -> float:
"""Return the room temperature in degrees celsius.""" """Return the room temperature in degrees celsius."""
payload = self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08]) payload = self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08])
return payload[0x05] / 2.0 return self._room_temp_logic(payload)
def get_external_temp(self) -> float: def get_external_temp(self) -> float:
"""Return the external temperature in degrees celsius.""" """Return the external temperature in degrees celsius."""
payload = self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08]) payload = self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08])
return payload[18] / 2.0 return self._ext_temp_logic(payload)
def get_full_status(self) -> dict: def get_full_status(self) -> dict:
"""Return the state of the device. """Return the state of the device.
@ -65,7 +78,7 @@ class hysen(Device):
data["active"] = (payload[4] >> 4) & 1 data["active"] = (payload[4] >> 4) & 1
data["temp_manual"] = (payload[4] >> 6) & 1 data["temp_manual"] = (payload[4] >> 6) & 1
data["heating_cooling"] = (payload[4] >> 7) & 1 data["heating_cooling"] = (payload[4] >> 7) & 1
data["room_temp"] = payload[5] / 2.0 data["room_temp"] = self._room_temp_logic(payload)
data["thermostat_temp"] = payload[6] / 2.0 data["thermostat_temp"] = payload[6] / 2.0
data["auto_mode"] = payload[7] & 0xF data["auto_mode"] = payload[7] & 0xF
data["loop_mode"] = payload[7] >> 4 data["loop_mode"] = payload[7] >> 4
@ -80,7 +93,7 @@ class hysen(Device):
data["fre"] = payload[15] data["fre"] = payload[15]
data["poweron"] = payload[16] data["poweron"] = payload[16]
data["unknown"] = payload[17] data["unknown"] = payload[17]
data["external_temp"] = payload[18] / 2.0 data["external_temp"] = self._ext_temp_logic(payload)
data["hour"] = payload[19] data["hour"] = payload[19]
data["min"] = payload[20] data["min"] = payload[20]
data["sec"] = payload[21] data["sec"] = payload[21]
@ -187,7 +200,9 @@ class hysen(Device):
# Set device on(1) or off(0), does not deactivate Wifi connectivity. # Set device on(1) or off(0), does not deactivate Wifi connectivity.
# Remote lock disables control by buttons on thermostat. # Remote lock disables control by buttons on thermostat.
# heating_cooling: heating(0) cooling(1) # heating_cooling: heating(0) cooling(1)
def set_power(self, power: int = 1, remote_lock: int = 0, heating_cooling: int = 0) -> None: def set_power(
self, power: int = 1, remote_lock: int = 0, heating_cooling: int = 0
) -> None:
"""Set the power state of the device.""" """Set the power state of the device."""
state = (heating_cooling << 7) + power state = (heating_cooling << 7) + power
self.send_request([0x01, 0x06, 0x00, 0x00, remote_lock, state]) self.send_request([0x01, 0x06, 0x00, 0x00, remote_lock, state])