Ejemplo n.º 1
0
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.climate import (
    ATTR_CURRENT_TEMPERATURE, ATTR_TEMPERATURE,
    ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH,
    ATTR_OPERATION_MODE, STATE_HEAT, STATE_AUTO)
from homeassistant.components.homekit.thermostats import Thermostat, STATE_OFF
from homeassistant.const import (
    ATTR_SERVICE, EVENT_CALL_SERVICE, ATTR_SERVICE_DATA,
    ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('thermostats')


class TestHomekitThermostats(unittest.TestCase):
    """Test class for all accessory types regarding thermostats."""

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)
Ejemplo n.º 2
0
"""Test different accessory types: Security Systems."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.homekit.security_systems import SecuritySystem
from homeassistant.const import (ATTR_SERVICE, EVENT_CALL_SERVICE,
                                 STATE_ALARM_ARMED_AWAY,
                                 STATE_ALARM_ARMED_HOME,
                                 STATE_ALARM_ARMED_NIGHT, STATE_ALARM_DISARMED)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('security_systems')


class TestHomekitSecuritySystems(unittest.TestCase):
    """Test class for all accessory types regarding security systems."""
    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)
Ejemplo n.º 3
0
 def setUp(self):
     """Setup things to be run when tests are started."""
     self.hass = get_test_home_assistant()
     get_patch_paths('sensors')
Ejemplo n.º 4
0
from pyhap.loader import get_serv_loader, get_char_loader  # noqa F401

from homeassistant.components.homekit.accessories import (
    set_accessory_info, add_preload_service, override_properties,
    HomeAccessory, HomeBridge)
from homeassistant.components.homekit.const import (
    SERV_ACCESSORY_INFO, SERV_BRIDGING_STATE,
    CHAR_MODEL, CHAR_MANUFACTURER, CHAR_NAME, CHAR_SERIAL_NUMBER)

from tests.mock.homekit import (
    get_patch_paths, mock_preload_service,
    MockTypeLoader, MockAccessory, MockService, MockChar)

PATH_SERV = 'pyhap.loader.get_serv_loader'
PATH_CHAR = 'pyhap.loader.get_char_loader'
PATH_ACC, _ = get_patch_paths()


@patch(PATH_CHAR, return_value=MockTypeLoader('char'))
@patch(PATH_SERV, return_value=MockTypeLoader('service'))
def test_add_preload_service(mock_serv, mock_char):
    """Test method add_preload_service.

    The methods 'get_serv_loader' and 'get_char_loader' are mocked.
    """
    acc = MockAccessory('Accessory')
    serv = add_preload_service(acc, 'TestService',
                               ['TestChar', 'TestChar2'],
                               ['TestOptChar', 'TestOptChar2'])

    assert serv.display_name == 'TestService'
Ejemplo n.º 5
0
"""Test different accessory types: Covers."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.cover import (ATTR_POSITION,
                                            ATTR_CURRENT_POSITION)
from homeassistant.components.homekit.covers import Window
from homeassistant.const import (STATE_UNKNOWN, STATE_OPEN, ATTR_SERVICE,
                                 ATTR_SERVICE_DATA, EVENT_CALL_SERVICE)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('covers')


class TestHomekitSensors(unittest.TestCase):
    """Test class for all accessory types regarding covers."""
    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)
Ejemplo n.º 6
0
"""Test different accessory types: Sensors."""
import unittest
from unittest.mock import patch

from homeassistant.components.homekit.const import PROP_CELSIUS
from homeassistant.components.homekit.sensors import (
    TemperatureSensor, calc_temperature)
from homeassistant.const import (
    ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_UNKNOWN)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('sensors')


def test_calc_temperature():
    """Test if temperature in Celsius is calculated correctly."""
    assert calc_temperature(STATE_UNKNOWN) is None
    assert calc_temperature('test') 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."""
Ejemplo n.º 7
0
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.climate import (
    ATTR_CURRENT_TEMPERATURE, ATTR_TEMPERATURE, ATTR_TARGET_TEMP_LOW,
    ATTR_TARGET_TEMP_HIGH, ATTR_OPERATION_MODE, STATE_HEAT, STATE_AUTO)
from homeassistant.components.homekit.thermostats import Thermostat, STATE_OFF
from homeassistant.const import (ATTR_SERVICE, EVENT_CALL_SERVICE,
                                 ATTR_SERVICE_DATA, ATTR_UNIT_OF_MEASUREMENT,
                                 TEMP_CELSIUS)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('thermostats')


class TestHomekitThermostats(unittest.TestCase):
    """Test class for all accessory types regarding thermostats."""
    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)
Ejemplo n.º 8
0
"""Test different accessory types: Covers."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.cover import (
    ATTR_POSITION, ATTR_CURRENT_POSITION)
from homeassistant.components.homekit.covers import Window
from homeassistant.const import (
    STATE_UNKNOWN, STATE_OPEN,
    ATTR_SERVICE, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('covers')


class TestHomekitSensors(unittest.TestCase):
    """Test class for all accessory types regarding covers."""

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)
Ejemplo n.º 9
0
"""Test different accessory types: Switches."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.homekit.switches import Switch
from homeassistant.const import ATTR_SERVICE, EVENT_CALL_SERVICE

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('switches')


class TestHomekitSwitches(unittest.TestCase):
    """Test class for all accessory types regarding switches."""
    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)

    def tearDown(self):
        """Stop down everything that was started."""
        self.hass.stop()
Ejemplo n.º 10
0
"""Test different accessory types: Switches."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.homekit.switches import Switch
from homeassistant.const import ATTR_SERVICE, EVENT_CALL_SERVICE

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('switches')


class TestHomekitSwitches(unittest.TestCase):
    """Test class for all accessory types regarding switches."""

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)

    def tearDown(self):
        """Stop down everything that was started."""
Ejemplo n.º 11
0
"""Test different accessory types: Security Systems."""
import unittest
from unittest.mock import patch

from homeassistant.core import callback
from homeassistant.components.homekit.security_systems import SecuritySystem
from homeassistant.const import (
    ATTR_SERVICE, EVENT_CALL_SERVICE,
    STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
    STATE_ALARM_ARMED_NIGHT, STATE_ALARM_DISARMED)

from tests.common import get_test_home_assistant
from tests.mock.homekit import get_patch_paths, mock_preload_service

PATH_ACC, PATH_FILE = get_patch_paths('security_systems')


class TestHomekitSecuritySystems(unittest.TestCase):
    """Test class for all accessory types regarding security systems."""

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.events = []

        @callback
        def record_event(event):
            """Track called event."""
            self.events.append(event)

        self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)