1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-23 20:39:01 +00:00

Homekit Update, Support for TempSensor (°F) (#12676)

* Changed version of "HAP-python" to "v1.1.7"

* Updated acc file to simplify init calls

* Code refactored and '°F' temp Sensors added

* Changed call to 'HomeAccessory' and 'HomeBridge'
* Extended function of 'add_preload_service' to add additional characteristics
* Added function to override characteristic property values

* TemperatureSensor
  * Added unit
  * Added calc_temperature

* Updated tests
This commit is contained in:
cdce8p
2018-02-26 04:27:40 +01:00
committed by Paulus Schoutsen
parent 347ba1a2d8
commit 27b1d448a3
8 changed files with 120 additions and 74 deletions

View File

@@ -1,13 +1,25 @@
"""Test different accessory types: Sensors."""
import unittest
from homeassistant.components.homekit.sensors import TemperatureSensor
from homeassistant.components.homekit.sensors import (
TemperatureSensor, calc_temperature)
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, STATE_UNKNOWN)
ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_UNKNOWN)
from tests.common import get_test_home_assistant
def test_calc_temperature():
"""Test if temperature in Celsius is calculated correctly."""
assert calc_temperature(STATE_UNKNOWN) is None
assert calc_temperature('20') == 20
assert calc_temperature('20.12', TEMP_CELSIUS) == 20.12
assert calc_temperature('75.2', TEMP_FAHRENHEIT) == 24
assert calc_temperature('-20.6', TEMP_FAHRENHEIT) == -29.22
class TestHomekitSensors(unittest.TestCase):
"""Test class for all accessory types regarding sensors."""
@@ -16,7 +28,7 @@ class TestHomekitSensors(unittest.TestCase):
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop down everthing that was started."""
"""Stop down everything that was started."""
self.hass.stop()
def test_temperature_celsius(self):
@@ -32,6 +44,12 @@ class TestHomekitSensors(unittest.TestCase):
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
self.hass.block_till_done()
self.hass.states.set(temperature_sensor, '20')
self.hass.states.set(temperature_sensor, '20',
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
self.hass.block_till_done()
self.assertEqual(acc.char_temp.value, 20)
self.hass.states.set(temperature_sensor, '75.2',
{ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT})
self.hass.block_till_done()
self.assertEqual(acc.char_temp.value, 24)