コード例 #1
0
ファイル: __init__.py プロジェクト: 2Fake/core
    async def async_setup(self):
        """Async setup of august device data and activities."""
        token = self._august_gateway.access_token
        user_data, locks, doorbells = await asyncio.gather(
            self._api.async_get_user(token),
            self._api.async_get_operable_locks(token),
            self._api.async_get_doorbells(token),
        )
        if not doorbells:
            doorbells = []
        if not locks:
            locks = []

        self._doorbells_by_id = {
            device.device_id: device
            for device in doorbells
        }
        self._locks_by_id = {device.device_id: device for device in locks}
        self._house_ids = {
            device.house_id
            for device in chain(locks, doorbells)
        }

        await self._async_refresh_device_detail_by_ids(
            [device.device_id for device in chain(locks, doorbells)])

        # We remove all devices that we are missing
        # detail as we cannot determine if they are usable.
        # This also allows us to avoid checking for
        # detail being None all over the place
        self._remove_inoperative_locks()
        self._remove_inoperative_doorbells()

        pubnub = AugustPubNub()
        for device in self._device_detail_by_id.values():
            pubnub.register_device(device)

        self.activity_stream = ActivityStream(self._hass, self._api,
                                              self._august_gateway,
                                              self._house_ids, pubnub)
        await self.activity_stream.async_setup()
        pubnub.subscribe(self.async_pubnub_message)
        self._pubnub_unsub = async_create_pubnub(user_data["UserID"], pubnub)

        if self._locks_by_id:
            tasks = []
            for lock_id in self._locks_by_id:
                detail = self._device_detail_by_id[lock_id]
                tasks.append(
                    self.async_status_async(
                        lock_id,
                        bool(detail.bridge and detail.bridge.hyper_bridge)))
            await asyncio.gather(*tasks)
コード例 #2
0
    async def async_setup(self):
        """Async setup of august device data and activities."""
        token = self._august_gateway.access_token
        user_data, locks, doorbells = await asyncio.gather(
            self._api.async_get_user(token),
            self._api.async_get_operable_locks(token),
            self._api.async_get_doorbells(token),
        )
        if not doorbells:
            doorbells = []
        if not locks:
            locks = []

        self._doorbells_by_id = {
            device.device_id: device
            for device in doorbells
        }
        self._locks_by_id = {device.device_id: device for device in locks}
        self._house_ids = {
            device.house_id
            for device in chain(locks, doorbells)
        }

        await self._async_refresh_device_detail_by_ids(
            [device.device_id for device in chain(locks, doorbells)])

        # We remove all devices that we are missing
        # detail as we cannot determine if they are usable.
        # This also allows us to avoid checking for
        # detail being None all over the place
        self._remove_inoperative_locks()
        self._remove_inoperative_doorbells()

        pubnub = AugustPubNub()
        for device in self._device_detail_by_id.values():
            pubnub.register_device(device)

        self.activity_stream = ActivityStream(self._hass, self._api,
                                              self._august_gateway,
                                              self._house_ids, pubnub)
        await self.activity_stream.async_setup()
        pubnub.subscribe(self.async_pubnub_message)
        self._pubnub_unsub = async_create_pubnub(user_data["UserID"], pubnub)

        if self._locks_by_id:
            # Do not prevent setup as the sync can timeout
            # but it is not a fatal error as the lock
            # will recover automatically when it comes back online.
            asyncio.create_task(self._async_initial_sync())
コード例 #3
0
    async def async_setup(self):
        """Async setup of august device data and activities."""
        token = self._august_gateway.access_token
        # This used to be a gather but it was less reliable with august's recent api changes.
        user_data = await self._api.async_get_user(token)
        locks = await self._api.async_get_operable_locks(token)
        doorbells = await self._api.async_get_doorbells(token)
        if not doorbells:
            doorbells = []
        if not locks:
            locks = []

        self._doorbells_by_id = {
            device.device_id: device
            for device in doorbells
        }
        self._locks_by_id = {device.device_id: device for device in locks}
        self._house_ids = {
            device.house_id
            for device in chain(locks, doorbells)
        }

        await self._async_refresh_device_detail_by_ids(
            [device.device_id for device in chain(locks, doorbells)])

        # We remove all devices that we are missing
        # detail as we cannot determine if they are usable.
        # This also allows us to avoid checking for
        # detail being None all over the place

        # Currently we know how to feed data to yalexe_ble
        # but we do not know how to send it to homekit_controller
        # yet
        _async_trigger_ble_lock_discovery(
            self._hass,
            [
                lock_detail
                for lock_detail in self._device_detail_by_id.values() if
                isinstance(lock_detail, LockDetail) and lock_detail.offline_key
            ],
        )

        self._remove_inoperative_locks()
        self._remove_inoperative_doorbells()

        pubnub = AugustPubNub()
        for device in self._device_detail_by_id.values():
            pubnub.register_device(device)

        self.activity_stream = ActivityStream(self._hass, self._api,
                                              self._august_gateway,
                                              self._house_ids, pubnub)
        await self.activity_stream.async_setup()
        pubnub.subscribe(self.async_pubnub_message)
        self._pubnub_unsub = async_create_pubnub(user_data["UserID"], pubnub)

        if self._locks_by_id:
            # Do not prevent setup as the sync can timeout
            # but it is not a fatal error as the lock
            # will recover automatically when it comes back online.
            asyncio.create_task(self._async_initial_sync())