Exemplo n.º 1
0
    def get(self, request):

        # Get current device state object
        current_device = DeviceViewer()

        # Get current environment state object
        current_environment = EnvironmentViewer()

        # Get current recipe state object
        current_recipe = RecipeViewer()

        # Get stored recipe objects
        recipe_objects = RecipeModel.objects.all().order_by("name")
        recipes = []
        for recipe_object in recipe_objects:
            recipes.append(SimpleRecipeViewer(recipe_object))

        # Get datetime picker form
        datetime_form = forms.DateTimeForm()

        # Get resource viewer: TODO: This should access connect manager through
        # coordinator manager. See viewers.py for example implementation
        valid_internet_connection = ConnectUtilities.valid_internet_connection(
        )

        # Build and return response
        response = {
            "current_device": current_device,
            "current_environment": current_environment,
            "current_recipe": current_recipe,
            "recipes": recipes,
            "datetime_form": datetime_form,
            "valid_internet_connection": valid_internet_connection,
        }
        return Response(response)
Exemplo n.º 2
0
    def get(self, request: Request) -> Response:
        """Gets dashboard view."""
        self.logger.debug("Getting dashboard view")

        # Get managers
        app_config = apps.get_app_config(APP_NAME)
        coordinator = app_config.coordinator
        network = coordinator.network
        recipe = coordinator.recipe

        # Get current environment state object
        current_environment = viewers.EnvironmentViewer()  # TODO: Fix me!

        # Get stored recipe objects
        recipe_objects = models.RecipeModel.objects.all().order_by("name")
        recipes = []
        for recipe_object in recipe_objects:
            recipes.append(viewers.RecipeViewer(recipe_object))

        # Get datetime picker form
        datetime_form = forms.DateTimeForm()

        # Build and return response
        response = {
            "serial_number": os.getenv("SERIAL_NUMBER"),
            "manager_modes": coordinator.manager_modes,
            "manager_healths": coordinator.manager_healths,
            "current_environment": current_environment,
            "recipe_mode": recipe.mode,
            "recipe_name": recipe.recipe_name,
            "recipe_uuid": recipe.recipe_uuid,
            "recipe_start_datestring": recipe.start_datestring,
            "recipe_percent_complete_string": recipe.percent_complete_string,
            "recipe_time_elapsed_string": recipe.time_elapsed_string,
            "recipe_time_remaining_string": recipe.time_remaining_string,
            "recipe_current_phase": recipe.current_phase,
            "recipe_current_cycle": recipe.current_cycle,
            "recipe_current_environment_name": recipe.current_environment_name,
            "recipes": recipes,
            "datetime_form": datetime_form,
            "network_is_connected": network.is_connected,
        }

        # Return response
        self.logger.debug("Returning response: {}".format(response))
        return Response(response, 200)