mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix homekit temperaturesensor round (#27047)
* Fix homekit temperature sensor for round with one decimal * Removing unnecesary operations * Adapting tests for new temperature_to_homekit() result precision
This commit is contained in:
parent
85947591c5
commit
c6b08b28b2
@ -96,7 +96,7 @@ class TemperatureSensor(HomeAccessory):
|
|||||||
temperature = temperature_to_homekit(temperature, unit)
|
temperature = temperature_to_homekit(temperature, unit)
|
||||||
self.char_temp.set_value(temperature)
|
self.char_temp.set_value(temperature)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"%s: Current temperature set to %d°C", self.entity_id, temperature
|
"%s: Current temperature set to %.1f°C", self.entity_id, temperature
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ def convert_to_float(state):
|
|||||||
|
|
||||||
def temperature_to_homekit(temperature, unit):
|
def temperature_to_homekit(temperature, unit):
|
||||||
"""Convert temperature to Celsius for HomeKit."""
|
"""Convert temperature to Celsius for HomeKit."""
|
||||||
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS) * 2) / 2
|
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
|
||||||
|
|
||||||
|
|
||||||
def temperature_to_states(temperature, unit):
|
def temperature_to_states(temperature, unit):
|
||||||
|
@ -96,10 +96,10 @@ async def test_thermostat(hass, hk_driver, cls, events):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_target_temp.value == 22.0
|
assert acc.char_target_temp.value == 22.2
|
||||||
assert acc.char_current_heat_cool.value == 1
|
assert acc.char_current_heat_cool.value == 1
|
||||||
assert acc.char_target_heat_cool.value == 1
|
assert acc.char_target_heat_cool.value == 1
|
||||||
assert acc.char_current_temp.value == 18.0
|
assert acc.char_current_temp.value == 17.8
|
||||||
assert acc.char_display_units.value == 0
|
assert acc.char_display_units.value == 0
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
@ -432,7 +432,7 @@ async def test_thermostat_fahrenheit(hass, hk_driver, cls, events):
|
|||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.get_temperature_range() == (7.0, 35.0)
|
assert acc.get_temperature_range() == (7.0, 35.0)
|
||||||
assert acc.char_heating_thresh_temp.value == 20.0
|
assert acc.char_heating_thresh_temp.value == 20.1
|
||||||
assert acc.char_cooling_thresh_temp.value == 24.0
|
assert acc.char_cooling_thresh_temp.value == 24.0
|
||||||
assert acc.char_current_temp.value == 23.0
|
assert acc.char_current_temp.value == 23.0
|
||||||
assert acc.char_target_temp.value == 22.0
|
assert acc.char_target_temp.value == 22.0
|
||||||
|
@ -173,7 +173,7 @@ def test_convert_to_float():
|
|||||||
def test_temperature_to_homekit():
|
def test_temperature_to_homekit():
|
||||||
"""Test temperature conversion from HA to HomeKit."""
|
"""Test temperature conversion from HA to HomeKit."""
|
||||||
assert temperature_to_homekit(20.46, TEMP_CELSIUS) == 20.5
|
assert temperature_to_homekit(20.46, TEMP_CELSIUS) == 20.5
|
||||||
assert temperature_to_homekit(92.1, TEMP_FAHRENHEIT) == 33.5
|
assert temperature_to_homekit(92.1, TEMP_FAHRENHEIT) == 33.4
|
||||||
|
|
||||||
|
|
||||||
def test_temperature_to_states():
|
def test_temperature_to_states():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user