# Path: config/hass/custom_components/aarlo/pyaarlo/constant.py
# BATTERY_KEY = 'batteryLevel'
# 
# BATTERY_TECH_KEY = 'batteryTech'
# 
# CHARGING_KEY = 'chargingState'
# 
# CHARGER_KEY = 'chargerTech'
# 
# CONNECTION_KEY = 'connectionState'
# 
# RESOURCE_KEYS = [ACTIVITY_STATE_KEY, AIR_QUALITY_KEY, AUDIO_DETECTED_KEY, BATTERY_KEY, BATTERY_TECH_KEY,
#                  BRIGHTNESS_KEY, CONNECTION_KEY, CHARGER_KEY, CHARGING_KEY, FLIP_KEY, HUMIDITY_KEY, LAMP_STATE_KEY,
#                  MIRROR_KEY, MOTION_DETECTED_KEY, MOTION_ENABLED_KEY,
#                  MOTION_SENS_KEY, POWER_SAVE_KEY, PRIVACY_KEY,
#                  SIGNAL_STR_KEY, SIREN_STATE_KEY, TEMPERATURE_KEY,
#                  AUDIO_CONFIG_KEY, AUDIO_PLAYLIST_KEY, AUDIO_STATUS_KEY, AUDIO_SPEAKER_KEY, AUDIO_TRACK_KEY, AUDIO_POSITION_KEY]
# 
# RESOURCE_UPDATE_KEYS = [ACTIVITY_STATE_KEY, AIR_QUALITY_KEY, AUDIO_DETECTED_KEY, BATTERY_KEY, BATTERY_TECH_KEY,
#                         CHARGER_KEY, CHARGING_KEY, CONNECTION_KEY, LAMP_STATE_KEY,
#                         HUMIDITY_KEY, MOTION_DETECTED_KEY, PRIVACY_KEY,
#                         SIGNAL_STR_KEY, SIREN_STATE_KEY, TEMPERATURE_KEY,
#                         AUDIO_CONFIG_KEY, AUDIO_PLAYLIST_KEY, AUDIO_STATUS_KEY, AUDIO_SPEAKER_KEY, AUDIO_TRACK_KEY, AUDIO_POSITION_KEY]
# 
# SIGNAL_STR_KEY = 'signalStrength'
# 
# XCLOUD_ID_KEY = 'xCloudId'


import threading
from .constant import (BATTERY_KEY, BATTERY_TECH_KEY, CHARGING_KEY, CHARGER_KEY,
                       CONNECTION_KEY, RESOURCE_KEYS,
                       RESOURCE_UPDATE_KEYS, SIGNAL_STR_KEY,
                       XCLOUD_ID_KEY)

    def __init__(self, name, arlo, attrs):
        self._name = name
        self._arlo = arlo
        self._attrs = attrs

        self._lock = threading.Lock()
        self._attr_cbs_ = []

        # stuff we use a lot
        self._device_id = attrs.get('deviceId', None)
        self._device_type = attrs.get('deviceType', None)
        self._unique_id = attrs.get('uniqueId', None)

        # add a listener
        self._arlo.be.add_listener(self, self._event_handler)

    def __repr__(self):
        # Representation string of object.
        return "<{0}:{1}:{2}>".format(self.__class__.__name__, self._device_type, self._name)

    def _event_handler(self, resource, event):
        self._arlo.debug("*DEVICE* {}: got {} event {}".format(self.name, resource, event))

        # Find properties. Event either contains a item called properites or it
        # is the whole thing.
        props = event.get("properties", event)

        # Save out new values.
        for key in props:

# Path: config/hass/custom_components/aarlo/pyaarlo/constant.py
# BATTERY_KEY = 'batteryLevel'
# 
# BATTERY_TECH_KEY = 'batteryTech'
# 
# CHARGING_KEY = 'chargingState'
# 
# CHARGER_KEY = 'chargerTech'
# 
# CONNECTION_KEY = 'connectionState'
# 
# RESOURCE_KEYS = [ACTIVITY_STATE_KEY, AIR_QUALITY_KEY, AUDIO_DETECTED_KEY, BATTERY_KEY, BATTERY_TECH_KEY,
#                  BRIGHTNESS_KEY, CONNECTION_KEY, CHARGER_KEY, CHARGING_KEY, FLIP_KEY, HUMIDITY_KEY, LAMP_STATE_KEY,
#                  MIRROR_KEY, MOTION_DETECTED_KEY, MOTION_ENABLED_KEY,
#                  MOTION_SENS_KEY, POWER_SAVE_KEY, PRIVACY_KEY,
#                  SIGNAL_STR_KEY, SIREN_STATE_KEY, TEMPERATURE_KEY,
#                  AUDIO_CONFIG_KEY, AUDIO_PLAYLIST_KEY, AUDIO_STATUS_KEY, AUDIO_SPEAKER_KEY, AUDIO_TRACK_KEY, AUDIO_POSITION_KEY]
# 
# RESOURCE_UPDATE_KEYS = [ACTIVITY_STATE_KEY, AIR_QUALITY_KEY, AUDIO_DETECTED_KEY, BATTERY_KEY, BATTERY_TECH_KEY,
#                         CHARGER_KEY, CHARGING_KEY, CONNECTION_KEY, LAMP_STATE_KEY,
#                         HUMIDITY_KEY, MOTION_DETECTED_KEY, PRIVACY_KEY,
#                         SIGNAL_STR_KEY, SIREN_STATE_KEY, TEMPERATURE_KEY,
#                         AUDIO_CONFIG_KEY, AUDIO_PLAYLIST_KEY, AUDIO_STATUS_KEY, AUDIO_SPEAKER_KEY, AUDIO_TRACK_KEY, AUDIO_POSITION_KEY]
# 
# SIGNAL_STR_KEY = 'signalStrength'
# 
# XCLOUD_ID_KEY = 'xCloudId'


# Path: config/hass/custom_components/aarlo/pyaarlo/device.py
import threading
from .constant import (BATTERY_KEY, BATTERY_TECH_KEY, CHARGING_KEY, CHARGER_KEY,
                       CONNECTION_KEY, RESOURCE_KEYS,
                       RESOURCE_UPDATE_KEYS, SIGNAL_STR_KEY,
                       XCLOUD_ID_KEY)


    def __init__(self, name, arlo, attrs):
        self._name = name
        self._arlo = arlo
        self._attrs = attrs

        self._lock = threading.Lock()
        self._attr_cbs_ = []

        # stuff we use a lot
        self._device_id = attrs.get('deviceId', None)
        self._device_type = attrs.get('deviceType', None)
        self._unique_id = attrs.get('uniqueId', None)

        # add a listener
        self._arlo.be.add_listener(self, self._event_handler)

    def __repr__(self):
        # Representation string of object.
        return "<{0}:{1}:{2}>".format(self.__class__.__name__, self._device_type, self._name)

    def _event_handler(self, resource, event):
        self._arlo.debug("*DEVICE* {}: got {} event {}".format(self.name, resource, event))

        # Find properties. Event either contains a item called properites or it
        # is the whole thing.
        props = event.get("properties", event)

        # Save out new values.
        for key in props:

            if key in RESOURCE_KEYS or key in RESOURCE_UPDATE_KEYS: