

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: blickfeld/hardware/services/compute_module.proto, blickfeld/hardware/services/device_operation.proto, blickfeld/hardware/services/identification.proto
# plugin: python-betterproto
import asyncio
from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    Dict,
    Optional,
)

import blickfeld_qb2.betterproto as betterproto
import blickfeld_qb2.betterproto.lib.google.protobuf as betterproto_lib_google_protobuf
import grpclib
from blickfeld_qb2.betterproto.grpc.grpclib_server import ServiceBase

from .. import config as _config__


if TYPE_CHECKING:
    import grpclib.server
    from blickfeld_qb2.betterproto.grpc.grpclib_client import MetadataLike
    from grpclib.metadata import Deadline


@dataclass(eq=False, repr=False)
class IdentificationGetResponse(betterproto.Message):
    """Response message for the identification get command"""

    identification: "_config__.Identification" = betterproto.message_field(1)
    """The current identification"""


class ComputeModule(betterproto.ServiceStub):
    """
    This service is used to control & observe the state of the compute module.
    """

    async def async_reboot(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Reboots the CM4"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.hardware.services.ComputeModule/Reboot",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def reboot(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Reboots the CM4"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_reboot(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )


class DeviceOperation(betterproto.ServiceStub):
    """
    This service is used for starting and stopping the device operation.
    Normally, the device is started and stopped based on the client
    connections. If there is a client using the Qb2, the device will start and
    stay in operation until all clients disconnected. The start function of
    this service overrides this behaviour, i.e. when started using the start
    function the device will stay operational even though no clients are
    connected. This allows a faster retrieval of frames once a client connects
    as the startup phase is skipped.
    """

    async def async_start(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Method to start the device operation. This starts the operation ot the
        deflection mirrors and the laser triggering. When this call is used,
        the device will stay in operation until stop is called (independent//
        of clients being connected or not).
        """

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.hardware.services.DeviceOperation/Start",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def start(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Method to start the device operation. This starts the operation ot the
        deflection mirrors and the laser triggering. When this call is used,
        the device will stay in operation until stop is called (independent//
        of clients being connected or not).
        """

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_start(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_stop(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Method to stop the device operation. This will stop the deflection
        mirror operation and laser triggering.
        """

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.hardware.services.DeviceOperation/Stop",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def stop(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Method to stop the device operation. This will stop the deflection
        mirror operation and laser triggering.
        """

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_stop(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )


class Identification(betterproto.ServiceStub):
    """
    The identification service provides methods to set and read out
    identification data of the Qb2 device.
    """

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "IdentificationGetResponse":
        """Gets identification configuration"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.hardware.services.Identification/Get",
            request,
            IdentificationGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "IdentificationGetResponse":
        """Gets identification configuration"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_get(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )
