コード例 #1
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_lights_some_lights(self, mock_hue_light):
        """Test the process_lights function with multiple groups."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {
                'state': 'on'
            },
            2: {
                'state': 'off'
            }
        }

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(self.hass, self.mock_api,
                                           self.mock_bridge, None)

            self.assertEquals(len(ret), 2)
            mock_hue_light.assert_has_calls([
                call(1, {'state': 'on'}, self.mock_bridge, mock.ANY,
                     self.mock_bridge.allow_unreachable,
                     self.mock_bridge.allow_in_emulated_hue),
                call(2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                     self.mock_bridge.allow_unreachable,
                     self.mock_bridge.allow_in_emulated_hue),
            ])
            mock_dispatcher_send.assert_not_called()
            self.assertEquals(len(self.mock_bridge.lights), 2)
コード例 #2
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_lights_new_light(self, mock_hue_light):
        """
        Test the process_lights function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {
                'state': 'on'
            },
            2: {
                'state': 'off'
            }
        }
        self.mock_bridge.lights = {
            1: self.build_mock_light(self.mock_bridge, 1, 'foo')
        }

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(self.hass, self.mock_api,
                                           self.mock_bridge, None)

            self.assertEquals(len(ret), 1)
            mock_hue_light.assert_has_calls([
                call(2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                     self.mock_bridge.allow_unreachable,
                     self.mock_bridge.allow_in_emulated_hue),
            ])
            mock_dispatcher_send.assert_called_once_with(
                'hue_light_callback_bridge-id_1')
            self.assertEquals(len(self.mock_bridge.lights), 2)
コード例 #3
0
    def test_process_lights_new_light(self, mock_hue_light):
        """
        Test the process_lights function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}
        self.mock_bridge.lights = {
            1: self.build_mock_light(self.mock_bridge, 1, 'foo')}

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(
                self.hass, self.mock_api, self.mock_bridge, None)

            self.assertEqual(len(ret), 1)
            mock_hue_light.assert_has_calls([
                call(
                    2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                    self.mock_bridge.allow_unreachable,
                    self.mock_bridge.allow_in_emulated_hue),
            ])
            mock_dispatcher_send.assert_called_once_with(
                'hue_light_callback_bridge-id_1')
            self.assertEqual(len(self.mock_bridge.lights), 2)
コード例 #4
0
ファイル: test_hue.py プロジェクト: oliverbl4/Anassistant
    def test_process_lights_new_light(self, mock_hue_light):
        """
        Test the process_lights function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}
        self.hass.data[
            hue_light.DATA_KEY][hue_light.DATA_LIGHTS][1] = MagicMock()

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, self.mock_bridge_type,
            None)

        self.assertEquals(len(ret), 1)
        mock_hue_light.assert_has_calls([
            call(
                2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                self.mock_bridge.allow_in_emulated_hue),
        ])
        self.hass.data[hue_light.DATA_KEY][hue_light.DATA_LIGHTS][
            1].schedule_update_ha_state.assert_called_once_with()
        self.assertEquals(
            len(self.hass.data[hue_light.DATA_KEY][hue_light.DATA_LIGHTS]),
            2)
コード例 #5
0
    def test_process_lights_some_lights(self, mock_hue_light):
        """Test the process_lights function with multiple groups."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {
                'state': 'on'
            },
            2: {
                'state': 'off'
            }
        }

        ret = hue_light.process_lights(self.hass, self.mock_api,
                                       self.mock_bridge, self.mock_bridge_type,
                                       None)

        self.assertEquals(len(ret), 2)
        mock_hue_light.assert_has_calls([
            call(1, {'state': 'on'}, self.mock_bridge, mock.ANY,
                 self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                 self.mock_bridge.allow_in_emulated_hue),
            call(2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                 self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                 self.mock_bridge.allow_in_emulated_hue),
        ])
        self.assertEquals(len(self.mock_bridge.lights), 2)
コード例 #6
0
    def test_process_lights_new_light(self, mock_hue_light):
        """
        Test the process_lights function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}
        self.mock_bridge.lights = {1: MagicMock()}

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, self.mock_bridge_type,
            None)

        self.assertEquals(len(ret), 1)
        mock_hue_light.assert_has_calls([
            call(
                2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                self.mock_bridge.allow_in_emulated_hue),
        ])
        self.assertEquals(len(self.mock_bridge.lights), 2)
        self.mock_bridge.lights[1]\
            .schedule_update_ha_state.assert_called_once_with()
コード例 #7
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_lights_api_error(self):
        """Test the process_lights function when the bridge errors out."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = None

        ret = hue_light.process_lights(self.hass, self.mock_api,
                                       self.mock_bridge, None)

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lights, {})
コード例 #8
0
    def test_process_lights_no_lights(self):
        """Test the process_lights function when bridge returns no lights."""
        self.setup_mocks_for_process_lights()

        ret = hue_light.process_lights(self.hass, self.mock_api,
                                       self.mock_bridge, self.mock_bridge_type,
                                       None)

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lights, {})
コード例 #9
0
    def test_process_lights_no_lights(self):
        """Test the process_lights function when bridge returns no lights."""
        self.setup_mocks_for_process_lights()

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, self.mock_bridge_type,
            None)

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lights, {})
コード例 #10
0
    def test_process_lights_api_error(self):
        """Test the process_lights function when the bridge errors out."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = None

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, None)

        self.assertEqual([], ret)
        self.assertEqual(self.mock_bridge.lights, {})
コード例 #11
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_lights_no_lights(self):
        """Test the process_lights function when bridge returns no lights."""
        self.setup_mocks_for_process_lights()

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(self.hass, self.mock_api,
                                           self.mock_bridge, None)

            self.assertEquals([], ret)
            mock_dispatcher_send.assert_not_called()
            self.assertEquals(self.mock_bridge.lights, {})
コード例 #12
0
    def test_process_lights_no_lights(self):
        """Test the process_lights function when bridge returns no lights."""
        self.setup_mocks_for_process_lights()

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(
                self.hass, self.mock_api, self.mock_bridge, None)

            self.assertEqual([], ret)
            mock_dispatcher_send.assert_not_called()
            self.assertEqual(self.mock_bridge.lights, {})
コード例 #13
0
ファイル: test_hue.py プロジェクト: oliverbl4/Anassistant
    def test_process_lights_api_error(self):
        """Test the process_lights function when the bridge errors out."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = None

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, self.mock_bridge_type,
            None)

        self.assertEquals([], ret)
        self.assertEquals(
            {},
            self.hass.data[hue_light.DATA_KEY][hue_light.DATA_LIGHTS])
コード例 #14
0
    def test_process_lights_some_lights(self, mock_hue_light):
        """Test the process_lights function with multiple groups."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}

        ret = hue_light.process_lights(
            self.hass, self.mock_api, self.mock_bridge, self.mock_bridge_type,
            None)

        self.assertEquals(len(ret), 2)
        mock_hue_light.assert_has_calls([
            call(
                1, {'state': 'on'}, self.mock_bridge, mock.ANY,
                self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                self.mock_bridge.allow_in_emulated_hue),
            call(
                2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                self.mock_bridge_type, self.mock_bridge.allow_unreachable,
                self.mock_bridge.allow_in_emulated_hue),
        ])
        self.assertEquals(len(self.mock_bridge.lights), 2)
コード例 #15
0
    def test_process_lights_some_lights(self, mock_hue_light):
        """Test the process_lights function with multiple groups."""
        self.setup_mocks_for_process_lights()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}

        with patch.object(self.hass.helpers.dispatcher, 'dispatcher_send') \
                as mock_dispatcher_send:
            ret = hue_light.process_lights(
                self.hass, self.mock_api, self.mock_bridge, None)

            self.assertEqual(len(ret), 2)
            mock_hue_light.assert_has_calls([
                call(
                    1, {'state': 'on'}, self.mock_bridge, mock.ANY,
                    self.mock_bridge.allow_unreachable,
                    self.mock_bridge.allow_in_emulated_hue),
                call(
                    2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                    self.mock_bridge.allow_unreachable,
                    self.mock_bridge.allow_in_emulated_hue),
            ])
            mock_dispatcher_send.assert_not_called()
            self.assertEqual(len(self.mock_bridge.lights), 2)