async def _receive_event(self, message: _Envelope) -> None: converter = RecordConverter.get_converter() event = converter.record_to_object( message._body, self.downlink_manager.registered_classes, self.downlink_manager.strict) await self.downlink_manager._subscribers_on_event(event)
async def __receive_update(self, message: 'Envelope') -> None: key = RecordConverter.get_converter().record_to_object( message.body.get_head().value.get_head().value, self.downlink_manager.registered_classes, self.downlink_manager.strict) value = RecordConverter.get_converter().record_to_object( message.body.get_body(), self.downlink_manager.registered_classes, self.downlink_manager.strict) recon_key = await Recon.to_string( message.body.get_head().value.get_head().value) old_value = self.map.get(recon_key, [Value.absent()])[0] self.map[recon_key] = (key, value) await self.downlink_manager.subscribers_did_update( key, value, old_value)
def get_key_item(self) -> 'Record': key_slot = RecordMap.create() key_slot.add( Slot.create_slot( Text.create_from('key'), RecordConverter.get_converter().object_to_record(self.key))) return key_slot
def get_value_item(self) -> '_Item': """ Convert the request value into an Item object. :return: - Request value as an Item object. """ value_slot = RecordConverter.get_converter().object_to_record( self.value) return value_slot
async def _send_message(self, value: Any) -> None: """ Send a message to the remote agent of the downlink. :param value: - New value for the lane of the remote agent. """ await self._initialised.wait() recon = RecordConverter.get_converter().object_to_record(value) message = _CommandMessage(self._node_uri, self._lane_uri, recon) await self._model._send_message(message)
async def __receive_remove(self, message: '_Envelope') -> None: key = RecordConverter.get_converter().record_to_object( message._body._get_head().value._get_head().value, self.downlink_manager.registered_classes, self.downlink_manager.strict) recon_key = Recon.to_string( message._body._get_head().value._get_head().value) old_value = self._map.pop(recon_key, (Value.absent(), Value.absent()))[1] await self.downlink_manager._subscribers_did_remove(key, old_value)
async def receive_event(self, message: Envelope): if message.body == Absent.get_absent(): event = Value.absent() elif isinstance(message.body, (Text, Num, Bool)): event = message.body else: converter = RecordConverter.get_converter() event = converter.record_to_object( message.body, self.downlink_manager.registered_classes, self.downlink_manager.strict) await self.downlink_manager.subscribers_on_event(event)
def get_key_item(self) -> '_Record': """ Convert the request key into an Item object. :return: - Request key as an Item object. """ key_slot = RecordMap.create() key_slot.add( Slot.create_slot( Text.create_from('key'), RecordConverter.get_converter().object_to_record(self.key))) return key_slot
async def __set_value(self, message: '_Envelope') -> None: """ Set the value of the the downlink and trigger the `did_set` callback of the downlink subscribers. :param message: - The message from the remote agent. :return: """ old_value = self._value converter = RecordConverter.get_converter() self._value = converter.record_to_object( message._body, self.downlink_manager.registered_classes, self.downlink_manager.strict) await self.downlink_manager._subscribers_did_set( self._value, old_value)
async def __send_command(self, host_uri: str, node_uri: str, lane_uri: str, body: Any) -> None: """ Send a command message to a given host. :param host_uri: - Host URI of the remote agent. :param node_uri: - Node URI of the remote agent. :param lane_uri: - Lane URI of the command lane of the remote agent. :param body: - The message body. """ record = RecordConverter.get_converter().object_to_record(body) host_uri = URI.normalise_warp_scheme(host_uri) message = CommandMessage(node_uri, lane_uri, body=record) connection = await self.get_connection(host_uri) await connection.send_message(await message.to_recon())
async def __set_value(self, message: 'Envelope') -> None: """ Set the value of the the downlink and trigger the `did_set` callback of the downlink subscribers. :param message: - The message from the remote agent. :return: """ old_value = self.value if message.body == Absent.get_absent(): self.value = Value.absent() elif isinstance(message.body, (Text, Num, Bool)): self.value = message.body else: converter = RecordConverter.get_converter() self.value = converter.record_to_object( message.body, self.downlink_manager.registered_classes, self.downlink_manager.strict) await self.downlink_manager.subscribers_did_set(self.value, old_value)
def get_value_item(self) -> 'Item': value_slot = RecordConverter.get_converter().object_to_record( self.value) return value_slot