# Path: beacontools/utils.py
# def mulaw_to_value(mudata):
#     """Convert a mu-law encoded value to linear."""
#     position = ((mudata & 0xF0) >> 4) + 5
#     return ((1 << position) | ((mudata & 0xF) << (position - 4)) | (1 << (position - 5))) - 33
# 
# def data_to_binstring(data):
#     """Convert an array of binary data to a binary string."""
#     return array.array('B', data).tobytes()
# 
# Path: beacontools/const.py
# MANUFACTURER_SPECIFIC_DATA_TYPE = 0xFF
# 
# CJ_TEMPHUM_TYPE = 0x10fe
# 
# COMPLETE_LOCALE_NAME_DATA_TYPE = 0x09


from ..utils import mulaw_to_value, data_to_binstring
from ..const import MANUFACTURER_SPECIFIC_DATA_TYPE, CJ_TEMPHUM_TYPE, COMPLETE_LOCALE_NAME_DATA_TYPE
"""Packet classes for Control-J Monitors."""

class CJMonitorAdvertisement(object):
    """CJ Monitor advertisement."""

    def __init__(self, frame):

        for ltv in frame:
            if ltv['type'] == MANUFACTURER_SPECIFIC_DATA_TYPE:
                msd = ltv['value']
                self._company_id = msd['company_identifier']
                self._beacon_type = msd['data']['beacon_type']
                if self._beacon_type == CJ_TEMPHUM_TYPE:
                    data = msd['data']['data']
                    self._temperature = data['temperature'] / 100.0
                    self._humidity = data['humidity']

# Path: beacontools/utils.py
# def mulaw_to_value(mudata):
#     """Convert a mu-law encoded value to linear."""
#     position = ((mudata & 0xF0) >> 4) + 5
#     return ((1 << position) | ((mudata & 0xF) << (position - 4)) | (1 << (position - 5))) - 33
# 
# def data_to_binstring(data):
#     """Convert an array of binary data to a binary string."""
#     return array.array('B', data).tobytes()
# 
# Path: beacontools/const.py
# MANUFACTURER_SPECIFIC_DATA_TYPE = 0xFF
# 
# CJ_TEMPHUM_TYPE = 0x10fe
# 
# COMPLETE_LOCALE_NAME_DATA_TYPE = 0x09


# Path: beacontools/packet_types/controlj.py
from ..utils import mulaw_to_value, data_to_binstring
from ..const import MANUFACTURER_SPECIFIC_DATA_TYPE, CJ_TEMPHUM_TYPE, COMPLETE_LOCALE_NAME_DATA_TYPE

"""Packet classes for Control-J Monitors."""

class CJMonitorAdvertisement(object):
    """CJ Monitor advertisement."""

    def __init__(self, frame):

        for ltv in frame:
            if ltv['type'] == MANUFACTURER_SPECIFIC_DATA_TYPE:
                msd = ltv['value']
                self._company_id = msd['company_identifier']
                self._beacon_type = msd['data']['beacon_type']
                if self._beacon_type == CJ_TEMPHUM_TYPE:
                    data = msd['data']['data']
                    self._temperature = data['temperature'] / 100.0
                    self._humidity = data['humidity']

                    self._light = mulaw_to_value(data['light']) / 10.0