# Autogenerated file. Do not edit.
from jacdac.bus import Bus, Client
from .constants import *
from typing import Optional


class RelayClient(Client):
    """
    A switching relay.
     * 
     * The contacts should be labelled `NO` (normally open), `COM` (common), and `NC` (normally closed).
     * When relay is energized it connects `NO` and `COM`.
     * When relay is not energized it connects `NC` and `COM`.
     * Some relays may be missing `NO` or `NC` contacts.
     * When relay module is not powered, or is in bootloader mode, it is not energized (connects `NC` and `COM`).
    Implements a client for the `Relay <https://microsoft.github.io/jacdac-docs/services/relay>`_ service.

    """

    def __init__(self, bus: Bus, role: str) -> None:
        super().__init__(bus, JD_SERVICE_CLASS_RELAY, JD_RELAY_PACK_FORMATS, role)


    @property
    def active(self) -> Optional[bool]:
        """
        Indicates whether the relay circuit is currently energized or not., 
        """
        return self.register(JD_RELAY_REG_ACTIVE).bool_value()

    @active.setter
    def active(self, value: bool) -> None:
        self.register(JD_RELAY_REG_ACTIVE).set_values(value)


    @property
    def variant(self) -> Optional[RelayVariant]:
        """
        (Optional) Describes the type of relay used., 
        """
        return self.register(JD_RELAY_REG_VARIANT).value()

    @property
    def max_switching_current(self) -> Optional[int]:
        """
        (Optional) Maximum switching current for a resistive load., _: mA
        """
        return self.register(JD_RELAY_REG_MAX_SWITCHING_CURRENT).value()

    
