def _modem_sm(self):
import datetime<EOL>read_timeout = READ_IDLE_TIMEOUT<EOL>while self.ser:<EOL><INDENT>try:<EOL><INDENT>resp = self.read(read_timeout)<EOL><DEDENT>except (serial.SerialException, SystemExit, TypeError):<EOL><INDENT>_LOGGER.debug('<STR_LIT>', self.port)<EOL>break<EOL><DEDENT>if self.state != self.STATE_IDLE and len(resp) == <NUM_LIT:0>:<EOL><INDENT>read_timeout = READ_IDLE_TIMEOUT<EOL>self.set_state(self.STATE_IDLE)<EOL>self.incomingcallnotificationfunc(self.state)<EOL>continue<EOL><DEDENT>resp = resp.decode()<EOL>resp = resp.strip('<STR_LIT:\r\n>')<EOL>if self.cmd_response == '<STR_LIT>':<EOL><INDENT>self.cmd_responselines.append(resp)<EOL><DEDENT>_LOGGER.debug('<STR_LIT>', resp)<EOL>if resp in ['<STR_LIT:OK>', '<STR_LIT>']:<EOL><INDENT>self.cmd_response = resp<EOL>continue<EOL><DEDENT>if resp in ['<STR_LIT>']:<EOL><INDENT>if self.state == self.STATE_IDLE:<EOL><INDENT>self.cid_name = '<STR_LIT>'<EOL>self.cid_number = '<STR_LIT>'<EOL>self.cid_time = datetime.datetime.now()<EOL><DEDENT>self.set_state(self.STATE_RING)<EOL>self.incomingcallnotificationfunc(self.state)<EOL>read_timeout = READ_RING_TIMOUT<EOL>continue<EOL><DEDENT>if len(resp) <= <NUM_LIT:4> or resp.find('<STR_LIT:=>') == -<NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>read_timeout = READ_RING_TIMOUT<EOL>cid_field, cid_data = resp.split('<STR_LIT:=>')<EOL>cid_field = cid_field.strip()<EOL>cid_data = cid_data.strip()<EOL>if cid_field in ['<STR_LIT>']:<EOL><INDENT>self.cid_time = datetime.datetime.now()<EOL>continue<EOL><DEDENT>if cid_field in ['<STR_LIT>']:<EOL><INDENT>self.cid_number = cid_data<EOL>continue<EOL><DEDENT>if cid_field in ['<STR_LIT>']:<EOL><INDENT>self.cid_name = cid_data<EOL>self.set_state(self.STATE_CALLERID)<EOL>self.incomingcallnotificationfunc(self.state)<EOL>_LOGGER.debug('<STR_LIT>',<EOL>self.cid_time.strftime("<STR_LIT>"),<EOL>self.cid_name,<EOL>self.cid_number)<EOL>try:<EOL><INDENT>self.write(self.cmd_callerid)<EOL><DEDENT>except serial.SerialException:<EOL><INDENT>_LOGGER.error('<STR_LIT>', self.port)<EOL>break<EOL><DEDENT><DEDENT>continue<EOL><DEDENT>self.set_state(self.STATE_FAILED)<EOL>_LOGGER.debug('<STR_LIT>')<EOL>return<EOL>
Handle modem response state machine.