示例#1
0
def test_home_driver():
    """Test HomeDriver class."""
    ip_address = "127.0.0.1"
    port = 51826
    path = ".homekit.state"
    pin = b"123-45-678"

    with patch("pyhap.accessory_driver.AccessoryDriver.__init__") as mock_driver:
        driver = HomeDriver(
            "hass", "entry_id", "name", address=ip_address, port=port, persist_file=path
        )

    mock_driver.assert_called_with(address=ip_address, port=port, persist_file=path)
    driver.state = Mock(pincode=pin)
    xhm_uri_mock = Mock(return_value="X-HM://0")
    driver.accessory = Mock(xhm_uri=xhm_uri_mock)

    # pair
    with patch("pyhap.accessory_driver.AccessoryDriver.pair") as mock_pair, patch(
        "homeassistant.components.homekit.accessories.dismiss_setup_message"
    ) as mock_dissmiss_msg:
        driver.pair("client_uuid", "client_public")

    mock_pair.assert_called_with("client_uuid", "client_public")
    mock_dissmiss_msg.assert_called_with("hass", "entry_id")

    # unpair
    with patch("pyhap.accessory_driver.AccessoryDriver.unpair") as mock_unpair, patch(
        "homeassistant.components.homekit.accessories.show_setup_message"
    ) as mock_show_msg:
        driver.unpair("client_uuid")

    mock_unpair.assert_called_with("client_uuid")
    mock_show_msg.assert_called_with("hass", "entry_id", "name", pin, "X-HM://0")
def test_home_driver():
    """Test HomeDriver class."""
    bridge = HomeBridge('hass')
    ip_address = '127.0.0.1'
    port = 51826
    path = '.homekit.state'
    pin = b'123-45-678'

    with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \
            as mock_driver:
        driver = HomeDriver('hass', bridge, ip_address, port, path)

    mock_driver.assert_called_with(bridge, ip_address, port, path)
    driver.state = Mock(pincode=pin)

    # pair
    with patch('pyhap.accessory_driver.AccessoryDriver.pair') as mock_pair, \
        patch('homeassistant.components.homekit.accessories.'
              'dismiss_setup_message') as mock_dissmiss_msg:
        driver.pair('client_uuid', 'client_public')

    mock_pair.assert_called_with('client_uuid', 'client_public')
    mock_dissmiss_msg.assert_called_with('hass')

    # unpair
    with patch('pyhap.accessory_driver.AccessoryDriver.unpair') \
        as mock_unpair, \
        patch('homeassistant.components.homekit.accessories.'
              'show_setup_message') as mock_show_msg:
        driver.unpair('client_uuid')

    mock_unpair.assert_called_with('client_uuid')
    mock_show_msg.assert_called_with('hass', pin)
def test_home_driver():
    """Test HomeDriver class."""
    ip_address = '127.0.0.1'
    port = 51826
    path = '.homekit.state'
    pin = b'123-45-678'

    with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \
            as mock_driver:
        driver = HomeDriver('hass', address=ip_address, port=port,
                            persist_file=path)

    mock_driver.assert_called_with(address=ip_address, port=port,
                                   persist_file=path)
    driver.state = Mock(pincode=pin)

    # pair
    with patch('pyhap.accessory_driver.AccessoryDriver.pair') as mock_pair, \
        patch('homeassistant.components.homekit.accessories.'
              'dismiss_setup_message') as mock_dissmiss_msg:
        driver.pair('client_uuid', 'client_public')

    mock_pair.assert_called_with('client_uuid', 'client_public')
    mock_dissmiss_msg.assert_called_with('hass')

    # unpair
    with patch('pyhap.accessory_driver.AccessoryDriver.unpair') \
        as mock_unpair, \
        patch('homeassistant.components.homekit.accessories.'
              'show_setup_message') as mock_show_msg:
        driver.unpair('client_uuid')

    mock_unpair.assert_called_with('client_uuid')
    mock_show_msg.assert_called_with('hass', pin)
示例#4
0
    def test_home_driver(self):
        """Test HomeDriver class."""
        bridge = HomeBridge('hass')
        ip_address = '127.0.0.1'
        port = 51826
        path = '.homekit.state'

        with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \
                as mock_driver:
            HomeDriver(bridge, ip_address, port, path)

        self.assertEqual(mock_driver.call_args,
                         call(bridge, ip_address, port, path))