예제 #1
0
    def __init__(self, *args, **kwargs):
        self._logger = module_logger.getChild(
            self.__class__.__name__)  # type: LazyLogger

        self.SpVoice = None
        self.comtypesClient = None
        self.valid = False
        self._voiceName = None
        self.streamFlags = None
        self.flags = None
        self.interrupt = False
        try:
            self.reset()
        except:
            self._logger.exception('SAPI: Initialization failed: retrying...')
            utils.sleep(1000)  # May not be necessary, but here it is
            try:
                self.reset()
            except:
                self._logger.exception(
                    'SAPI: Initialization failed: Giving up.')
                return
        self.valid = True
        self.COMError = importHelper('_ctypes').COMError
        self.setStreamFlags()
예제 #2
0
def thread_run():
    prctl.set_name("rfxcom")
    threading.current_thread().name = "rfxcom"
    try:
        if not P.initialised:
            _init_board()
        if P.initialised:
            L.l.debug('Waiting for RFX event')
            time_elapsed_minutes = (utils.get_base_location_now_date() -
                                    P.last_packet_received).seconds / 60
            if time_elapsed_minutes > P.MAX_MINUTES_SILENCE:
                L.l.warning(
                    'RFX event not received since {} mins, device err? Reseting!'
                    .format(time_elapsed_minutes))
                P.transport.reset()
            event = P.transport.receive_blocking()
            __rfx_reading(event)
        else:
            if P.init_failed_count > P.MAX_FAILED_RETRY:
                unload()
    except IndexError as iex:
        P.initialised = False
        P.init_failed_count += 1
        utils.sleep(10)
    except Exception as ex:
        L.l.error('Error read RFX tty port, err={}'.format(ex), exc_info=True)
        P.initialised = False
        P.init_failed_count += 1
        utils.sleep(10)
    prctl.set_name("idle")
    threading.current_thread().name = "idle"
예제 #3
0
 def checker(self, *args, **kwargs):
     if not self.valid:
         self._logger.debug('SAPI: Broken - ignoring {0}'.format(
             func.__name__))
         return None
     try:
         return func(self, *args, **kwargs)
     except self.COMError as e:
         self.logSAPIError(e, func.__name__)
     except:
         self._logger.exception('SAPI: {0} error'.format(func.__name__))
     self.valid = False
     self._logger.debug('SAPI: Resetting...')
     utils.sleep(1000)
     try:
         self.reset()
         self.valid = True
         self._logger.debug('SAPI: Resetting succeded.')
         return func(self, *args, **kwargs)
     except self.COMError as e:
         self.valid = False
         self.logSAPIError(e, func.__name__)
     except:
         self.valid = False
         self._logger.error('SAPI: {0} error'.format(func.__name__))
예제 #4
0
 def runCommandAndSpeak(self, text):
     try:
         args = ['espeak']
         self.addCommonArgs(args, text)
         self.process = subprocess.Popen(args, universal_newlines=True)
         while self.process.poll() is None and self.active:
             utils.sleep(10)
     except Exception as e:
         if type(self)._logger.isEnabledFor(LazyLogger.ERROR):
             type(self)._logger.error(e)
예제 #5
0
 def play(self, path):
     if not os.path.exists(path):
         type(self)._logger.info('WindowsAudioPlayer.play() - Missing wav file')
         return
     self.audio = self._player.load(path)
     self.audio.play()
     self.event.clear()
     self.event.wait(self.audio.milliseconds() / 1000.0)
     if self.event.isSet():
         self.audio.stop()
     while self.audio.isplaying():
         utils.sleep(10)
     self.audio = None
예제 #6
0
 def pipe(self, source):  # Plays using ALSA
     self._wavProcess = subprocess.Popen('mpg321 - --wav - | aplay',
                                         stdin=subprocess.PIPE,
                                         stdout=(
                                             open(os.path.devnull, 'w')),
                                         stderr=subprocess.STDOUT,
                                         env=self.env, shell=True,
                                         universal_newlines=True)
     try:
         shutil.copyfileobj(source, self._wavProcess.stdin)
     except IOError as e:
         if e.errno != errno.EPIPE:
             module_logger.ERROR('Error piping audio', hide_tb=True)
     except:
         module_logger.ERROR('Error piping audio', hide_tb=True)
     source.close()
     self._wavProcess.stdin.close()
     while self._wavProcess.poll() is None and self.active:
         utils.sleep(10)
예제 #7
0
 def threadedSay(self, text):
     if not text: return
     self.synth.startSpeakingString_(self.cocoapy.get_NSString(text))
     while self.synth.isSpeaking():
         utils.sleep(10)
예제 #8
0
 def threadedSay(self, text):
     if not text: return
     self.process = subprocess.Popen(['say', text], universal_newlines=True)
     while self.process.poll() is None and self.active:
         utils.sleep(10)
예제 #9
0
def _set_main_heat_source():
    P.thread_pool_status = 'set main source'
    heat_source_relay_list = m.ZoneHeatRelay.find(
        {'$not': {
            m.ZoneHeatRelay.temp_sensor_name: None
        }})
    up_limit = P.temp_limit + P.threshold
    for heat_source_relay in heat_source_relay_list:
        # if heat_source_relay.heat_pin_name == 'puffer gas valve':
        #    traceback.print_stack()
        #    L.l.info('Debug 1 {}'.format(heat_source_relay))
        # is there is a temp sensor defined, consider this source as possible alternate source
        if heat_source_relay.temp_sensor_name is not None:
            temp_rec = m.Sensor.find_one(
                {m.Sensor.sensor_name: heat_source_relay.temp_sensor_name})
            # if alternate source is valid
            # fixok: add temp threshold to avoid quick on/offs
            if temp_rec is not None \
                    and ((temp_rec.temperature >= up_limit and not heat_source_relay.is_alternate_source_switch)
                         or (temp_rec.temperature >= P.temp_limit and heat_source_relay.is_alternate_source_switch)):
                if heat_source_relay.is_alternate_source_switch:
                    # stop main heat source
                    heatrelay_main_source = m.ZoneHeatRelay.find_one(
                        {m.ZoneHeatRelay.is_main_heat_source: True})
                    main_source_zone = m.Zone.find_one(
                        {m.Zone.id: heatrelay_main_source.zone_id})
                    L.l.info(
                        'Stop main heat source {}'.format(main_source_zone))
                    _save_heat_state_db(zone=main_source_zone,
                                        heat_is_on=False)
                    # turn switch valve on to alternate position
                    switch_source_zone = m.Zone.find_one(
                        {m.Zone.id: heat_source_relay.zone_id})
                    L.l.info(
                        'Switch valve {} to on'.format(switch_source_zone))
                    _save_heat_state_db(zone=switch_source_zone,
                                        heat_is_on=True)
                else:
                    # mark this source as active, to be started when there is heat need
                    # if heat_source_relay.is_alternate_heat_source is False:
                    L.l.info(
                        'Alternate heat source is active with temp={}'.format(
                            temp_rec.temperature))
                    heat_source_relay.is_alternate_heat_source = True
                    heat_source_relay.save_changed_fields()
            else:
                # if alternate source is no longer valid
                if heat_source_relay.is_alternate_source_switch:
                    # stop alternate heat source
                    # heatrelay_alt_source = models.ZoneHeatRelay.query.filter_by(is_alternate_heat_source=1).first()
                    # if heatrelay_alt_source is not None:
                    #    alt_source_zone = models.Zone.query.filter_by(id=heatrelay_alt_source.zone_id).first()
                    #    __save_heat_state_db(zone=alt_source_zone, heat_is_on=False)
                    # turn valve back to main position
                    switch_source_zone = m.Zone.find_one(
                        {m.Zone.id: heat_source_relay.zone_id})
                    L.l.info('Switch valve {} back'.format(switch_source_zone))
                    _save_heat_state_db(zone=switch_source_zone,
                                        heat_is_on=False)
                else:
                    # mark this source as inactive, let main source to start
                    if heat_source_relay.is_alternate_heat_source:
                        # force alt source shutdown if was on
                        alt_source_zone = m.Zone.find_one(
                            {m.Zone.id: heat_source_relay.zone_id})
                        L.l.info(
                            'Force alt source {} off'.format(alt_source_zone))
                        _save_heat_state_db(zone=alt_source_zone,
                                            heat_is_on=False)
                        # todo: sleep needed to allow for valve return
                        L.l.info(
                            'Alternate heat source is now inactive, temp source is {}. Sleeping 60s!!!'
                            .format(temp_rec))
                        utils.sleep(60)
                    else:
                        # stop heat puffer alt source
                        heat_source_relay.heat_is_on = False
                    heat_source_relay.is_alternate_heat_source = False
                    heat_source_relay.save_changed_fields()
예제 #10
0
def sleep(ms):
    return utils.sleep(ms)
예제 #11
0
 def runCommandAndSpeak(self, text):
     args = ['recite', text]
     self.process = subprocess.Popen(args, universal_newlines=True)
     while self.process.poll() is None and self.active:
         utils.sleep(10)