def EnableSensor(self, sensor, enable): """Enable a sensor/actuator Args: sensor: Hash composed from name and device class/type enable: 1 to enable, 0 to disable Returns: True for success, False otherwise. """ info('Enable sensor: ' + str(sensor) + ' ' + str(enable)) try: if sensor is None: return False if enable is None: return False with self.sensorMutex: if enable == 0: #add item to the list if sensor not in self.disabledSensors: DbManager.Insert(self.disabledSensorTable, sensor) self.disabledSensors[sensor] = 1 else: #remove item from the list if sensor in self.disabledSensors: DbManager.Delete(self.disabledSensorTable, sensor) del self.disabledSensors[sensor] #save list except Exception as ex: error('EnableSensor Failed with exception: ' + str(ex)) return False return True
def EnableSensor(self, sensor, enable): #sensor is the hash composed from name and device class/type info('Enable sensor: ' + str(sensor) + ' ' + str(enable)) try: if sensor is None: return False if enable is None: return False with self.sensorMutex: if enable == 0: #add item to the list if sensor not in self.disabledSensors: rowId = DbManager.Insert(self.disabledSensorTable, sensor) self.disabledSensors[sensor] = 1 else: #remove item from the list if sensor in self.disabledSensors: DbManager.Delete(self.disabledSensorTable, sensor) del self.disabledSensors[sensor] #save list except Exception as ex: error('EnableSensor Failed with exception: ' + str(ex)) return False self.AddRefresh() return True
def test_delayed_load(self): self.test_engine.stop() del self.test_engine del self.test_client now = datetime.datetime.utcnow() if (now.second > 35): print('Sleep until the minute rolls over') time.sleep(60 - now.second) now = datetime.datetime.strftime(datetime.datetime.utcnow(), '%Y-%m-%dT%H:%M:%S.%fZ') self.schedule_events = [{ 'id': 'delay_1', 'title': 'date_job', 'actions': ['date_job_action'], 'config': { 'type': 'date', 'start_date': now } }, { 'id': 'delay_2', 'title': 'daily_job', 'actions': ['daily_job_action'], 'config': { 'type': 'interval', 'unit': 'day', 'interval': 1, 'start_date': now } }, { 'id': 'delay_3', 'title': 'weekly_job', 'actions': ['weekly_job_action'], 'config': { 'type': 'interval', 'unit': 'week', 'interval': 1, 'start_date': now } }, { 'id': 'delay_4', 'title': 'monthly_job', 'actions': ['monthly_job_action'], 'config': { 'type': 'interval', 'unit': 'month', 'interval': 1, 'start_date': now } }, { 'id': 'delay_5', 'title': 'yearly_job', 'actions': ['yearly_job_action'], 'config': { 'type': 'interval', 'unit': 'year', 'interval': 1, 'start_date': now } }] for event in self.schedule_events: event_json = json.dumps(event) try: DbManager.Insert('scheduled_events', event['id'], event_json) except sqlite3.IntegrityError as e: DbManager.Update('scheduled_events', 'event = ?', event_json, 'id = ?', event['id']) print('Pause before loading scheduler') time.sleep(20) print('Starting scheduler, time is {}'.format( datetime.datetime.utcnow())) self.test_client = TestClient() self.test_engine = SchedulerEngine(self.test_client, 'test') self.check_schedules_run(self.schedule_events)
def AddDbItem(self, id, jsonData): debug('') bVal = False with self.mutex: bVal = DbManager.Insert(self.tablename, id, jsonData) return bVal