diff --git a/pioreactor/actions/led_intensity.py b/pioreactor/actions/led_intensity.py index c17bba56..025d0b41 100644 --- a/pioreactor/actions/led_intensity.py +++ b/pioreactor/actions/led_intensity.py @@ -219,7 +219,6 @@ def led_intensity( logger.info( f"Updated LED {channel} from {old_state[channel]:0.3g}% to {new_state[channel]:0.3g}%." ) - return updated_successfully diff --git a/pioreactor/utils/__init__.py b/pioreactor/utils/__init__.py index 356d8c92..3d716277 100644 --- a/pioreactor/utils/__init__.py +++ b/pioreactor/utils/__init__.py @@ -286,6 +286,7 @@ def _initialize_table(self): ) """ ) + self.conn.commit() def __setitem__(self, key, value): self.cursor.execute( @@ -296,6 +297,7 @@ def __setitem__(self, key, value): """, (key, value), ) + self.conn.commit() def get(self, key, default=None): self.cursor.execute(f"SELECT value FROM {self.table_name} WHERE key = ?", (key,)) @@ -306,6 +308,17 @@ def iterkeys(self): self.cursor.execute(f"SELECT key FROM {self.table_name}") return (row[0] for row in self.cursor.fetchall()) + def pop(self, key, default=None): + self.cursor.execute(f"SELECT value FROM {self.table_name} WHERE key = ?", (key,)) + result = self.cursor.fetchone() + if result is None: + if default is None: + raise KeyError(f"Key '{key}' not found in cache.") + return default + self.cursor.execute(f"DELETE FROM {self.table_name} WHERE key = ?", (key,)) + self.conn.commit() + return result[0] + def __contains__(self, key): self.cursor.execute(f"SELECT 1 FROM {self.table_name} WHERE key = ?", (key,)) return self.cursor.fetchone() is not None @@ -315,6 +328,7 @@ def __iter__(self): def __delitem__(self, key): self.cursor.execute(f"DELETE FROM {self.table_name} WHERE key = ?", (key,)) + self.conn.commit() def __getitem__(self, key): self.cursor.execute(f"SELECT value FROM {self.table_name} WHERE key = ?", (key,))