コード例 #1
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_groups_some_groups(self, mock_hue_light):
        """Test the process_groups function with multiple groups."""
        self.setup_mocks_for_process_groups()
        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_groups(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, True),
                call(2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                     self.mock_bridge.allow_unreachable,
                     self.mock_bridge.allow_in_emulated_hue, True),
            ])
            mock_dispatcher_send.assert_not_called()
            self.assertEquals(len(self.mock_bridge.lightgroups), 2)
コード例 #2
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_groups_new_group(self, mock_hue_light):
        """
        Test the process_groups function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = {
            1: {
                'state': 'on'
            },
            2: {
                'state': 'off'
            }
        }
        self.mock_bridge.lightgroups = {
            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_groups(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, True),
            ])
            mock_dispatcher_send.assert_called_once_with(
                'hue_light_callback_bridge-id_1')
            self.assertEquals(len(self.mock_bridge.lightgroups), 2)
コード例 #3
0
ファイル: test_hue.py プロジェクト: oliverbl4/Anassistant
    def test_process_groups_some_groups(self, mock_hue_light):
        """Test the process_groups function with multiple groups."""
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}

        ret = hue_light.process_groups(
            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, True),
            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, True),
        ])
        self.assertEquals(
            len(self.hass.data[
                hue_light.DATA_KEY][hue_light.DATA_LIGHTGROUPS]),
            2)
コード例 #4
0
ファイル: test_hue.py プロジェクト: oliverbl4/Anassistant
    def test_process_groups_new_group(self, mock_hue_light):
        """
        Test the process_groups function with new groups.

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

        ret = hue_light.process_groups(
            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, True),
        ])
        self.hass.data[hue_light.DATA_KEY][hue_light.DATA_LIGHTGROUPS][
            1].schedule_update_ha_state.assert_called_once_with()
        self.assertEquals(
            len(self.hass.data[
                hue_light.DATA_KEY][hue_light.DATA_LIGHTGROUPS]),
            2)
コード例 #5
0
    def test_process_groups_new_group(self, mock_hue_light):
        """
        Test the process_groups function with new groups.

        Test what happens when we already have a light and a new one shows up.
        """
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}
        self.mock_bridge.lightgroups = {
                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_groups(
                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, True),
            ])
            mock_dispatcher_send.assert_called_once_with(
                'hue_light_callback_bridge-id_1')
            self.assertEqual(len(self.mock_bridge.lightgroups), 2)
コード例 #6
0
    def test_process_groups_new_group(self, mock_hue_light):
        """
        Test the process_groups function with new groups.

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

        ret = hue_light.process_groups(
            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, True),
        ])
        self.assertEquals(len(self.mock_bridge.lightgroups), 2)
        self.mock_bridge.lightgroups[1]\
            .schedule_update_ha_state.assert_called_once_with()
コード例 #7
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_groups_api_error(self):
        """Test the process_groups function when the bridge errors out."""
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = None

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

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lightgroups, {})
コード例 #8
0
    def test_process_groups_api_error(self):
        """Test the process_groups function when the bridge errors out."""
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = None

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

        self.assertEqual([], ret)
        self.assertEqual(self.mock_bridge.lightgroups, {})
コード例 #9
0
    def test_process_groups_no_state(self):
        """Test the process_groups function when bridge returns no status."""
        self.setup_mocks_for_process_groups()
        self.mock_bridge.get_group.return_value = {'name': 'Group 0'}

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

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lightgroups, {})
コード例 #10
0
    def test_process_groups_no_state(self):
        """Test the process_groups function when bridge returns no status."""
        self.setup_mocks_for_process_groups()
        self.mock_bridge.get_group.return_value = {'name': 'Group 0'}

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

        self.assertEquals([], ret)
        self.assertEquals(self.mock_bridge.lightgroups, {})
コード例 #11
0
ファイル: test_hue.py プロジェクト: zzhmy/home-assistant
    def test_process_groups_no_state(self):
        """Test the process_groups function when bridge returns no status."""
        self.setup_mocks_for_process_groups()
        self.mock_bridge.get_group.return_value = {'name': 'Group 0'}

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

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

        ret = hue_light.process_groups(
            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_LIGHTGROUPS])
コード例 #13
0
    def test_process_groups_no_state(self):
        """Test the process_groups function when bridge returns no status."""
        self.setup_mocks_for_process_groups()
        self.mock_bridge.get_group.return_value = {'name': 'Group 0'}

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

            self.assertEqual([], ret)
            mock_dispatcher_send.assert_not_called()
            self.assertEqual(self.mock_bridge.lightgroups, {})
コード例 #14
0
    def test_process_groups_some_groups(self, mock_hue_light):
        """Test the process_groups function with multiple groups."""
        self.setup_mocks_for_process_groups()
        self.mock_api.get.return_value = {
            1: {'state': 'on'}, 2: {'state': 'off'}}

        ret = hue_light.process_groups(
            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, True),
            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, True),
        ])
        self.assertEquals(len(self.mock_bridge.lightgroups), 2)
コード例 #15
0
    def test_process_groups_some_groups(self, mock_hue_light):
        """Test the process_groups function with multiple groups."""
        self.setup_mocks_for_process_groups()
        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_groups(
                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, True),
                call(
                    2, {'state': 'off'}, self.mock_bridge, mock.ANY,
                    self.mock_bridge.allow_unreachable,
                    self.mock_bridge.allow_in_emulated_hue, True),
            ])
            mock_dispatcher_send.assert_not_called()
            self.assertEqual(len(self.mock_bridge.lightgroups), 2)