# Path: uchroma/dbus_utils.py
# def _check_variance(items: list):
# def dbus_prepare(obj, variant: bool=False, camel_keys: bool=False) -> tuple:
#     def __init__(self, obj, interface_name, exclude=None):
#     def add_property(self, name: str, signature: str, writable: bool=False):
#     def add_method(self, method, *argspecs):
#     def add_signal(self, signal, *argspecs):
#     def _parse_traits(self):
#     def build(self) -> str:
#     def __init__(self, *args, **kwargs):
#     def __getattribute__(self, name):
#     def __setattr__(self, name, value):
# class DescriptorBuilder(object):
# class TraitsPropertiesMixin(object):
# 
# Path: uchroma/version.py

# 
# Path: uchroma/client/dbus_client.py
# class UChromaClient(object):
# 
#     def __init__(self):
#         self._bus = pydbus.SessionBus()
# 
# 
#     def get_device_paths(self) -> list:
#         dm = self._bus.get(SERVICE)
#         return dm.GetDevices()
# 
# 
#     def get_device(self, identifier):
#         if identifier is None:
#             return None
# 
#         use_key = False
#         if isinstance(identifier, str):
#             if identifier.startswith(BASE_PATH):
#                 return self._bus.get(SERVICE, identifier)
# 
#             if re.match(r'\w{4}:\w{4}.\d{2}', identifier):
#                 use_key = True
#             elif re.match(r'\d+', identifier):
#                 identifier = int(identifier)
#             else:
#                 return None
# 
#         for dev_path in self.get_device_paths():
#             dev = self.get_device(dev_path)
#             if use_key and identifier == dev.Key:
#                 return dev
#             elif identifier == dev.DeviceIndex:
#                 return dev
# 
#         return None
# 
# 
#     def get_layer(self, device, layer_idx):
#         layers = device.CurrentRenderers
#         if layer_idx >= len(layers):
#             raise ValueError("Layer index out of range")
# 
#         return self._bus.get(SERVICE, layers[layer_idx][1])


import logging
from argparse import ArgumentParser
from argcomplete import autocomplete
from uchroma.dbus_utils import dbus_prepare, snake_to_camel
from uchroma.version import __version__
from .dbus_client import UChromaClient
"""
Various helper functions that are used across the library.
"""







class UChromaConsoleUtil(object):
    """
    A base class for command-line utilities
    """
    def __init__(self):
        self._parser = ArgumentParser(description=self.description, add_help=False)

        self._parser.add_argument('-v', '--version', action='version', version=self.version)
        self._parser.add_argument('-g', '--debug', action='store_true',
                                  help="Enable debug output")
        self._parser.add_argument('-d', '--device', type=str,
                                  help="Select target device name or index")
        self._parser.add_argument('-l', '--list', action='store_true',
                                  help="List available devices")

        self._args, self._unparsed = self._parser.parse_known_args()

        if self._args.debug:
            logging.getLogger().setLevel(logging.DEBUG)


# Path: uchroma/dbus_utils.py
# def _check_variance(items: list):
# def dbus_prepare(obj, variant: bool=False, camel_keys: bool=False) -> tuple:
#     def __init__(self, obj, interface_name, exclude=None):
#     def add_property(self, name: str, signature: str, writable: bool=False):
#     def add_method(self, method, *argspecs):
#     def add_signal(self, signal, *argspecs):
#     def _parse_traits(self):
#     def build(self) -> str:
#     def __init__(self, *args, **kwargs):
#     def __getattribute__(self, name):
#     def __setattr__(self, name, value):
# class DescriptorBuilder(object):
# class TraitsPropertiesMixin(object):
# 
# Path: uchroma/version.py

# 
# Path: uchroma/client/dbus_client.py
# class UChromaClient(object):
# 
#     def __init__(self):
#         self._bus = pydbus.SessionBus()
# 
# 
#     def get_device_paths(self) -> list:
#         dm = self._bus.get(SERVICE)
#         return dm.GetDevices()
# 
# 
#     def get_device(self, identifier):
#         if identifier is None:
#             return None
# 
#         use_key = False
#         if isinstance(identifier, str):
#             if identifier.startswith(BASE_PATH):
#                 return self._bus.get(SERVICE, identifier)
# 
#             if re.match(r'\w{4}:\w{4}.\d{2}', identifier):
#                 use_key = True
#             elif re.match(r'\d+', identifier):
#                 identifier = int(identifier)
#             else:
#                 return None
# 
#         for dev_path in self.get_device_paths():
#             dev = self.get_device(dev_path)
#             if use_key and identifier == dev.Key:
#                 return dev
#             elif identifier == dev.DeviceIndex:
#                 return dev
# 
#         return None
# 
# 
#     def get_layer(self, device, layer_idx):
#         layers = device.CurrentRenderers
#         if layer_idx >= len(layers):
#             raise ValueError("Layer index out of range")
# 
#         return self._bus.get(SERVICE, layers[layer_idx][1])


# Path: uchroma/client/cmd.py
import logging
from argparse import ArgumentParser
from argcomplete import autocomplete
from uchroma.dbus_utils import dbus_prepare, snake_to_camel
from uchroma.version import __version__
from .dbus_client import UChromaClient

"""
Various helper functions that are used across the library.
"""







class UChromaConsoleUtil(object):
    """
    A base class for command-line utilities
    """
    def __init__(self):
        self._parser = ArgumentParser(description=self.description, add_help=False)

        self._parser.add_argument('-v', '--version', action='version', version=self.version)
        self._parser.add_argument('-g', '--debug', action='store_true',
                                  help="Enable debug output")
        self._parser.add_argument('-d', '--device', type=str,
                                  help="Select target device name or index")
        self._parser.add_argument('-l', '--list', action='store_true',
                                  help="List available devices")

        self._args, self._unparsed = self._parser.parse_known_args()

        if self._args.debug:
            logging.getLogger().setLevel(logging.DEBUG)


        self._client = UChromaClient()