Ejemplo n.º 1
0
 def test_check_ha_config_file_correct(self, mock_check):
     """Check that restart propagates to stop."""
     mock_check.return_value = check_config.HomeAssistantConfig()
     assert run_coroutine_threadsafe(
         config_util.async_check_ha_config_file(self.hass),
         self.hass.loop
     ).result() is None
Ejemplo n.º 2
0
 def test_check_ha_config_file_correct(self, mock_check):
     """Check that restart propagates to stop."""
     mock_check.return_value = check_config.HomeAssistantConfig()
     assert run_coroutine_threadsafe(
         config_util.async_check_ha_config_file(self.hass),
         self.hass.loop
     ).result() is None
Ejemplo n.º 3
0
    def test_check_ha_config_file_wrong(self, mock_check):
        """Check that restart with a bad config doesn't propagate to stop."""
        mock_check.return_value = check_config.HomeAssistantConfig()
        mock_check.return_value.add_error("bad")

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass),
            self.hass.loop).result() == 'bad'
Ejemplo n.º 4
0
    def test_check_ha_config_file_wrong(self, mock_check):
        """Check that restart with a bad config doesn't propagate to stop."""
        mock_check.return_value = check_config.HomeAssistantConfig()
        mock_check.return_value.add_error("bad")

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass),
            self.hass.loop
        ).result() == 'bad'
Ejemplo n.º 5
0
    def post(self, request):
        """Validate configuration and return results."""
        errors = yield from async_check_ha_config_file(request.app['hass'])

        state = 'invalid' if errors else 'valid'

        return self.json({
            "result": state,
            "errors": errors,
        })
Ejemplo n.º 6
0
    def test_check_ha_config_file_correct(self, mock_create):
        """Check that restart propagates to stop."""
        process_mock = mock.MagicMock()
        attrs = {
            'communicate.return_value': mock_coro((b'output', None)),
            'wait.return_value': mock_coro(0)}
        process_mock.configure_mock(**attrs)
        mock_create.return_value = mock_coro(process_mock)

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass), self.hass.loop
        ).result() is None
Ejemplo n.º 7
0
    def test_check_ha_config_file_correct(self, mock_create):
        """Check that restart propagates to stop."""
        process_mock = mock.MagicMock()
        attrs = {
            'communicate.return_value': mock_coro(('output', 'error')),
            'wait.return_value': mock_coro(0)}
        process_mock.configure_mock(**attrs)
        mock_create.return_value = mock_coro(process_mock)

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass), self.hass.loop
        ).result() is None
Ejemplo n.º 8
0
    def async_handle_core_service(call):
        """Service handler for handling core services."""
        if call.service == SERVICE_HOMEASSISTANT_STOP:
            hass.async_add_job(hass.async_stop())
            return

        try:
            yield from conf_util.async_check_ha_config_file(hass)
        except HomeAssistantError:
            return

        if call.service == SERVICE_HOMEASSISTANT_RESTART:
            hass.async_add_job(hass.async_stop(RESTART_EXIT_CODE))
Ejemplo n.º 9
0
    def async_handle_core_service(call):
        """Service handler for handling core services."""
        if call.service == SERVICE_HOMEASSISTANT_STOP:
            hass.async_add_job(hass.async_stop())
            return

        try:
            yield from conf_util.async_check_ha_config_file(hass)
        except HomeAssistantError:
            return

        if call.service == SERVICE_HOMEASSISTANT_RESTART:
            hass.async_add_job(hass.async_stop(RESTART_EXIT_CODE))
Ejemplo n.º 10
0
    def test_check_ha_config_file_wrong(self, mock_create):
        """Check that restart with a bad config doesn't propagate to stop."""
        process_mock = mock.MagicMock()
        attrs = {
            'communicate.return_value':
                mock_coro(('\033[34mhello'.encode('utf-8'), None)),
            'wait.return_value': mock_coro(1)}
        process_mock.configure_mock(**attrs)
        mock_create.return_value = mock_coro(process_mock)

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass),
            self.hass.loop
        ).result() == 'hello'
Ejemplo n.º 11
0
    def test_check_ha_config_file_wrong(self, mock_create):
        """Check that restart with a bad config doesn't propagate to stop."""
        process_mock = mock.MagicMock()
        attrs = {
            'communicate.return_value':
                mock_coro(('\033[34mhello'.encode('utf-8'), 'error')),
            'wait.return_value': mock_coro(1)}
        process_mock.configure_mock(**attrs)
        mock_create.return_value = mock_coro(process_mock)

        assert run_coroutine_threadsafe(
            config_util.async_check_ha_config_file(self.hass),
            self.hass.loop
        ).result() == 'hello'
Ejemplo n.º 12
0
    def test_check_ha_config_file_wrong(self, mock_create):
        """Check that restart with a bad config doesn't propagate to stop."""
        process_mock = mock.MagicMock()
        attrs = {
            'communicate.return_value':
                mock_generator((r'\033[hellom'.encode('utf-8'), 'error')),
            'wait.return_value': mock_generator(1)}
        process_mock.configure_mock(**attrs)
        mock_create.return_value = mock_generator(process_mock)

        with self.assertRaises(HomeAssistantError):
            run_coroutine_threadsafe(
                config_util.async_check_ha_config_file(self.hass),
                self.hass.loop
            ).result()
Ejemplo n.º 13
0
    def async_handle_core_service(call):
        """Service handler for handling core services."""
        if call.service == SERVICE_HOMEASSISTANT_STOP:
            hass.async_create_task(hass.async_stop())
            return

        try:
            errors = yield from conf_util.async_check_ha_config_file(hass)
        except HomeAssistantError:
            return

        if errors:
            _LOGGER.error(errors)
            hass.components.persistent_notification.async_create(
                "Config error. See dev-info panel for details.",
                "Config validating", "{0}.check_config".format(ha.DOMAIN))
            return

        if call.service == SERVICE_HOMEASSISTANT_RESTART:
            hass.async_create_task(hass.async_stop(RESTART_EXIT_CODE))
Ejemplo n.º 14
0
    def async_handle_core_service(call):
        """Service handler for handling core services."""
        if call.service == SERVICE_HOMEASSISTANT_STOP:
            hass.async_add_job(hass.async_stop())
            return

        try:
            errors = yield from conf_util.async_check_ha_config_file(hass)
        except HomeAssistantError:
            return

        if errors:
            _LOGGER.error(errors)
            hass.components.persistent_notification.async_create(
                "Config error. See dev-info panel for details.",
                "Config validating", "{0}.check_config".format(ha.DOMAIN))
            return

        if call.service == SERVICE_HOMEASSISTANT_RESTART:
            hass.async_add_job(hass.async_stop(RESTART_EXIT_CODE))