コード例 #1
0
    async def write_value(self, value: PortValue) -> None:
        if self._slave.is_online():
            try:
                await self._slave.api_call(
                    'PATCH',
                    f'/ports/{self._remote_id}/value',
                    value,
                    timeout=settings.slaves.long_timeout)

                # Immediately fetch the current port value from slave and update it locally. This ensures that calls to
                # Port.get_value() will return the correct updated value.
                remote_value = await self._slave.api_call(
                    'GET', f'/ports/{self._remote_id}/value')
                self.set_cached_value(remote_value)

            except core_responses.HTTPError as e:
                if e.code == 502 and e.msg.startswith('port error:'):
                    raise core_ports.PortError(e.msg.split(':', 1)[1].strip())

                if e.code == 504 and e.msg == 'port timeout':
                    raise core_ports.PortTimeout()

                raise exceptions.adapt_api_error(e) from e

        else:  # Offline
            # Allow provisioning for offline devices
            self.debug('marking value for provisioning')
            self._cached_value = value
            self._provisioning.add('value')
            await self.save()  # Save provisioning value

            # We need to trigger a port-update because our provisioning attribute has changed
            self.trigger_update()
コード例 #2
0
    def wrapper(*args, **kwargs) -> Any:
        # Transform BLE exceptions into port exceptions, where applicable
        try:
            return func(*args, **kwargs)

        except BLETimeout as e:
            raise core_ports.PortTimeout() from e

        except BLEException as e:
            raise core_ports.PortError(str(e)) from e
コード例 #3
0
    async def write_value(self, value: PortValue) -> None:
        if self._slave.is_online():
            try:
                await self._slave.api_call(
                    'PATCH',
                    f'/ports/{self._remote_id}/value',
                    value,
                    timeout=settings.slaves.long_timeout
                )
                self.push_remote_value(value)

            except core_responses.Accepted:
                # The value has been successfully sent to the slave but it hasn't been applied right away. We should
                # update the cached value later, as soon as we receive a corresponding value-change event.
                pass

            except core_responses.HTTPError as e:
                if e.code == 502 and e.code == 'port-error':
                    message = e.params.get('message')
                    if message:
                        raise core_ports.PortError(message)

                    else:
                        raise core_ports.PortError()

                if e.code == 504 and e.code == 'port-timeout':
                    raise core_ports.PortTimeout()

                raise exceptions.adapt_api_error(e) from e

        else:  # Offline
            # Allow provisioning for offline devices
            self.debug('marking value for provisioning')
            self._cached_value = value
            self._provisioning.add('value')
            await self.save()  # Save provisioning value

            # We need to trigger a port-update because our provisioning attribute has changed
            await self.trigger_update()
コード例 #4
0
ファイル: vports.py プロジェクト: qtoggle/qtoggleserver
 def map_id(self, new_id: str) -> None:
     raise core_ports.PortError('Virtual ports cannot be mapped')