예제 #1
0
 def __init__(self, hass, name, code, username, password):
     """Initialize the Alarm.com status."""
     from pyalarmdotcom import Alarmdotcom
     _LOGGER.debug('Setting up Alarm.com...')
     self._hass = hass
     self._name = name
     self._code = str(code) if code else None
     self._username = username
     self._password = password
     self._websession = async_get_clientsession(self._hass)
     self._state = STATE_UNKNOWN
     self._alarm = Alarmdotcom(
         username, password, self._websession, hass.loop)
예제 #2
0
 def __init__(self, hass, name, code, username, password):
     """Initialize the Alarm.com status."""
     from pyalarmdotcom import Alarmdotcom
     _LOGGER.debug('Setting up Alarm.com...')
     self._hass = hass
     self._name = name
     self._code = str(code) if code else None
     self._username = username
     self._password = password
     self._websession = async_get_clientsession(self._hass)
     self._state = STATE_UNKNOWN
     self._alarm = Alarmdotcom(
         username, password, self._websession, hass.loop)
예제 #3
0
class AlarmDotCom(alarm.AlarmControlPanel):
    """Representation of an Alarm.com status."""

    def __init__(self, hass, name, code, username, password):
        """Initialize the Alarm.com status."""
        from pyalarmdotcom import Alarmdotcom
        _LOGGER.debug('Setting up Alarm.com...')
        self._hass = hass
        self._name = name
        self._code = str(code) if code else None
        self._username = username
        self._password = password
        self._websession = async_get_clientsession(self._hass)
        self._state = STATE_UNKNOWN
        self._alarm = Alarmdotcom(
            username, password, self._websession, hass.loop)

    @asyncio.coroutine
    def async_login(self):
        """Login to Alarm.com."""
        yield from self._alarm.async_login()

    @asyncio.coroutine
    def async_update(self):
        """Fetch the latest state."""
        yield from self._alarm.async_update()
        return self._alarm.state

    @property
    def name(self):
        """Return the name of the alarm."""
        return self._name

    @property
    def code_format(self):
        """Return one or more digits/characters."""
        if self._code is None:
            return None
        if isinstance(self._code, str) and re.search('^\\d+$', self._code):
            return 'Number'
        return 'Any'

    @property
    def state(self):
        """Return the state of the device."""
        if self._alarm.state.lower() == 'disarmed':
            return STATE_ALARM_DISARMED
        if self._alarm.state.lower() == 'armed stay':
            return STATE_ALARM_ARMED_HOME
        if self._alarm.state.lower() == 'armed away':
            return STATE_ALARM_ARMED_AWAY
        return STATE_UNKNOWN

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        return {
            'sensor_status': self._alarm.sensor_status
        }

    @asyncio.coroutine
    def async_alarm_disarm(self, code=None):
        """Send disarm command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_disarm()

    @asyncio.coroutine
    def async_alarm_arm_home(self, code=None):
        """Send arm hom command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_arm_home()

    @asyncio.coroutine
    def async_alarm_arm_away(self, code=None):
        """Send arm away command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_arm_away()

    def _validate_code(self, code):
        """Validate given code."""
        check = self._code is None or code == self._code
        if not check:
            _LOGGER.warning("Wrong code entered")
        return check
예제 #4
0
class AlarmDotCom(alarm.AlarmControlPanel):
    """Representation of an Alarm.com status."""

    def __init__(self, hass, name, code, username, password):
        """Initialize the Alarm.com status."""
        from pyalarmdotcom import Alarmdotcom
        _LOGGER.debug('Setting up Alarm.com...')
        self._hass = hass
        self._name = name
        self._code = str(code) if code else None
        self._username = username
        self._password = password
        self._websession = async_get_clientsession(self._hass)
        self._state = STATE_UNKNOWN
        self._alarm = Alarmdotcom(
            username, password, self._websession, hass.loop)

    @asyncio.coroutine
    def async_login(self):
        """Login to Alarm.com."""
        yield from self._alarm.async_login()

    @asyncio.coroutine
    def async_update(self):
        """Fetch the latest state."""
        yield from self._alarm.async_update()
        return self._alarm.state

    @property
    def name(self):
        """Return the name of the alarm."""
        return self._name

    @property
    def code_format(self):
        """Return one or more digits/characters."""
        if self._code is None:
            return None
        elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
            return 'Number'
        return 'Any'

    @property
    def state(self):
        """Return the state of the device."""
        if self._alarm.state.lower() == 'disarmed':
            return STATE_ALARM_DISARMED
        elif self._alarm.state.lower() == 'armed stay':
            return STATE_ALARM_ARMED_HOME
        elif self._alarm.state.lower() == 'armed away':
            return STATE_ALARM_ARMED_AWAY
        return STATE_UNKNOWN

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        return {
            'sensor_status': self._alarm.sensor_status
        }

    @asyncio.coroutine
    def async_alarm_disarm(self, code=None):
        """Send disarm command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_disarm()

    @asyncio.coroutine
    def async_alarm_arm_home(self, code=None):
        """Send arm hom command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_arm_home()

    @asyncio.coroutine
    def async_alarm_arm_away(self, code=None):
        """Send arm away command."""
        if self._validate_code(code):
            yield from self._alarm.async_alarm_arm_away()

    def _validate_code(self, code):
        """Validate given code."""
        check = self._code is None or code == self._code
        if not check:
            _LOGGER.warning("Wrong code entered")
        return check