def __sendSourceStatus(self): statusValue = self._status.value # type: int msg = IntegerMsg(value=statusValue, fromID=self.id, typeID=MsgID.SOURCE_STATUS_INFO, groupID=GroupID.UI) self.dispatcher.distribute(msg, self.id)
def _sendPlaybackInfo(self, newPlayback: PlaybackStatus) -> None: msg = IntegerMsg(value=newPlayback.value, fromID=self.id, typeID=MsgID.SOURCE_PLAYBACK_INFO, groupID=GroupID.UI) self.dispatcher.distribute(msg, self.id) pass
def _formatMessage(self, parts: List[str]) -> Optional['Message']: msgID = int(parts[0]) if msgID == MsgID.SET_VOL.value: volume = int(parts[1]) return IntegerMsg(value=volume, fromID=self.id, typeID=MsgID.SET_VOL, forID=ModuleID.VOLUME_OPERATOR) elif msgID == MsgID.REQ_CURRENT_VOL_INFO.value: return RequestMsg(self.id, typeID=MsgID.REQ_CURRENT_VOL_INFO, forID=ModuleID.VOLUME_OPERATOR) elif msgID == MsgID.REQ_SOURCE_STATUS.value: return RequestMsg(self.id, typeID=MsgID.REQ_SOURCE_STATUS, groupID=GroupID.SOURCE) elif msgID == MsgID.ACTIVATE_SOURCE.value: sourceID = int(parts[1]) return IntegerMsg(value=sourceID, fromID=self.id, typeID=MsgID.ACTIVATE_SOURCE, groupID=GroupID.SOURCE) elif msgID == MsgID.REQ_NODE.value: sourceID = int(parts[1]) nodeID = int(parts[2]) fromIndex = int(parts[3]) return BiIntegerMsg(value1=nodeID, value2=fromIndex, fromID=self.id, typeID=MsgID.REQ_NODE, forID=ModuleID(sourceID)) elif msgID == MsgID.SOURCE_PLAY_COMMAND.value: sourceID = int(parts[1]) commandID = int(parts[2]) return IntegerMsg(value=commandID, fromID=self.id, typeID=MsgID.SOURCE_PLAY_COMMAND, forID=ModuleID(sourceID)) else: return None
def _createActivationMsg(self, source: 'WebSourcePart', activate: bool) -> IntegerMsg: if activate: activationSourceID = source.sourceID.value else: # deactivate this source = deactivate all sources (only one can be activated at any moment) activationSourceID = 0 return IntegerMsg(value=activationSourceID, fromID=self.id, typeID=MsgID.ACTIVATE_SOURCE, groupID=GroupID.SOURCE)
def __sendIntegerNodeMsgToSource(self, msgID: MsgID, nodeID: NodeID): msg = IntegerMsg(value=nodeID, fromID=self.id, typeID=msgID, forID=self.sourceID) self.dispatcher.distribute(msg, self.id)
def _sendPlayCommandMsg(self, command: PlayCommand) -> None: msg = IntegerMsg(value=command.id, fromID=self._sourcePart.id, typeID=MsgID.SOURCE_PLAY_COMMAND, forID=self._sourcePart.sourceID) self._sourcePart.dispatcher.distribute(msg, self._sourcePart.id)
def _sendVolume(self, value: int): msg = IntegerMsg(value=value, fromID=self._app.id, typeID=MsgID.SET_VOL, forID=ModuleID.VOLUME_OPERATOR) self._app.dispatcher.distribute(msg, self._app.id)
def __sendCurrentVolume(self): msg = IntegerMsg(value=self.volume, fromID=self.id, typeID=MsgID.CURRENT_VOL_INFO, groupID=GroupID.UI) self.dispatcher.distribute(msg, self.id)
def _initializeInThread(self): # always sending "I am here" msg at start, to fill route maps of all dispatchers self.dispatcher.distribute( IntegerMsg(self._getEncodedGroupIDs(), self.id, MsgID.IN_GROUPS_MSG), self.id)