Skip to content

Commit

Permalink
Bumpless... Celsius to Fahrenheit!
Browse files Browse the repository at this point in the history
  • Loading branch information
plmilord authored Sep 6, 2021
1 parent 23211dd commit 3a12565
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
27 changes: 23 additions & 4 deletions custom_components/spaclient/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_HEAT, HVAC_MODE_OFF)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.util.temperature import convert as convert_temperature

from datetime import timedelta
Expand Down Expand Up @@ -65,15 +65,32 @@ def supported_features(self):
@property
def current_temperature(self):
"""Return the current temperature."""
return self._spaclient.get_current_temp()
if self._spaclient.get_current_temp() != None:
if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Fahrenheit":
return round(convert_temperature(self._spaclient.get_current_temp(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Celsius":
return self._spaclient.get_current_temp() / 2
if self.hass.config.units.temperature_unit == TEMP_FAHRENHEIT and self._spaclient.temp_scale == "Celsius":
return round(convert_temperature(self._spaclient.get_current_temp() / 2, TEMP_CELSIUS, TEMP_FAHRENHEIT) * 2) / 2
return self._spaclient.get_current_temp()
return None

@property
def target_temperature(self):
"""Return the target temperature."""
if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Fahrenheit":
return round(convert_temperature(self._spaclient.get_set_temp(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Celsius":
return self._spaclient.get_set_temp() / 2
if self.hass.config.units.temperature_unit == TEMP_FAHRENHEIT and self._spaclient.temp_scale == "Celsius":
return round(convert_temperature(self._spaclient.get_set_temp() / 2, TEMP_CELSIUS, TEMP_FAHRENHEIT) * 2) / 2
return self._spaclient.get_set_temp()

async def async_set_temperature(self, **kwargs):
#_LOGGER.info("Setting Temperature")
self._spaclient.set_temperature(kwargs.get(ATTR_TEMPERATURE))
temperature = kwargs[ATTR_TEMPERATURE]
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
temperature = round(convert_temperature(temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT))
await self._spaclient.set_temperature(temperature)

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target HVAC mode."""
Expand All @@ -98,4 +115,6 @@ def max_temp(self):
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
return TEMP_CELSIUS
return TEMP_FAHRENHEIT
12 changes: 3 additions & 9 deletions custom_components/spaclient/spaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, host_ip):
self.pump4 = "Off"
self.pump5 = "Off"
self.pump6 = "Off"
self.circ_pump = False
self.circ_pump = 0
self.blower = "Off"
self.light1 = 0
self.light2 = 0
Expand Down Expand Up @@ -228,11 +228,6 @@ def parse_status_update(self, byte_array):
self.aux2 = flag6 & 0x10
self.set_temp = byte_array[20]

if self.temp_scale == "Celsius":
self.set_temp = round(convert_temperature(self.set_temp / 2, TEMP_CELSIUS, TEMP_FAHRENHEIT) * 2) / 2
if self.current_temp != None:
self.current_temp = round(convert_temperature(self.current_temp / 2, TEMP_CELSIUS, TEMP_FAHRENHEIT) * 2) / 2

def parse_filter_cycles_response(self, byte_array):
""" Parse filter cycles response.
Expand Down Expand Up @@ -734,10 +729,9 @@ async def keep_alive_call(self):
def send_toggle_message(self, item):
self.send_message(b'\x0a\xbf\x11', bytes([item]) + b'\x00')

def set_temperature(self, temp):
self.set_temp = int(temp)
async def set_temperature(self, temp):
if self.temp_scale == "Celsius":
temp = convert_temperature(temp, TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2
temp = round(convert_temperature(temp, TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2)
self.send_message(b'\x0a\xbf\x20', bytes([int(temp)]))

async def set_current_time(self):
Expand Down
6 changes: 2 additions & 4 deletions custom_components/spaclient/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ async def async_turn_on(self, **kwargs):
#_LOGGER.info("Pump %s status %s", self._pump_num, self._spaclient.get_pump(self._pump_num))
#_LOGGER.info("Turning On Pump %s", self._pump_num)
if self._spaclient.pump_array[self._pump_num - 1] == 1:
self._spaclient.set_pump(self._pump_num, "High")
return
return self._spaclient.set_pump(self._pump_num, "High")

self._spaclient.set_pump(self._pump_num, "Low")

Expand All @@ -92,8 +91,7 @@ async def async_turn_off(self, **kwargs):
#if self._spaclient.get_pump(self._pump_num) == "High":
#_LOGGER.info("Turning Off Pump %s", self._pump_num)
if self._spaclient.get_pump(self._pump_num) == "Low":
self._spaclient.set_pump(self._pump_num, "High")
return
return self._spaclient.set_pump(self._pump_num, "High")

self._spaclient.set_pump(self._pump_num, "Off")

Expand Down

0 comments on commit 3a12565

Please sign in to comment.