def set_preferences(self, preferences): super().set_preferences(preferences) prefs = safe_load(preferences, "{}".format(self.id(), {})) self.high_duration = safe_load(prefs, 'high_duration', 1.5) self.low_duration = safe_load(prefs, 'low_duration', 5.0) self.restricted = safe_load(prefs, 'restricted', True)
def set_preferences(self, preferences): super().set_preferences(preferences) prefs = safe_load(preferences, "{}".format(self.id(), {})) self.bpm = safe_load(prefs, 'bpm', 60) self.beat_duration = self._bpm_to_pulse_duration(self.bpm) self.waveform = safe_load(prefs, 'waveform', 'sin')
def set_preferences(self, preferences): super().set_preferences(preferences) prefs = safe_load(preferences, "{}".format(self.id(), {})) self.bpm = safe_load(prefs, 'bpm', 60) self.color.set_colors(safe_load(prefs, 'colors', None)) self.color_duration = self._bpm_to_pulse_duration(self.bpm)
def update_preferences(self, preferences): self.enabled = safe_load(preferences, 'pref_notifications_enabled', True) self.pulse_frequency = safe_load(preferences, 'pref_notifications_pulse_frequency', 5) self.pulse_duration = safe_load(preferences, 'pref_notifications_pulse_duration', 1)
def get_pins(): pin_red = 22 pin_green = 27 pin_blue = 17 if os.path.exists(FILE_PIN_CONFIG): with open(FILE_PIN_CONFIG, 'r') as f: pins = json.load(f) pin_red = safe_load(pins, 'pin_red') pin_green = safe_load(pins, 'pin_green') pin_blue = safe_load(pins, 'pin_blue') print('Using pin configuration:\n' + 'pin_red = {},\npin_green = {},\npin_blue = {}'.format( pin_red, pin_green, pin_blue)) return pin_red, pin_green, pin_blue
def refresh(self, file=FILE_PREFERENCES): with open(file) as f: j = None try: j = json.load(f) except: j = {} # File doesn't exist yet self.max_brightness = safe_load(j, 'pref_max_brightness', 100) self.min_brightness = safe_load(j, 'pref_min_brightness', 0) self.color_change_interpolate = safe_load( j, 'pref_interpolate_color_changes', True) self.color_change_duration = max( 0.5, safe_load(j, 'pref_color_change_duration', 1.5)) self.inactivity_timeout = safe_load(j, 'pref_inactivity_timeout', 0) self.inactivity_behaviour_id = safe_load( j, 'pref_inactivity_behaviour', Behaviour.NONE) self.inactivity_behaviour_options = safe_load( j, 'pref_inactivity_behaviour_options', {}) self.notifications_enabled = safe_load( j, 'pref_notifications_enabled', False) self.notifications_pulse_frequency = safe_load( j, 'pref_notifications_pulse_frequency', 30)
def update(self, fallback_color): if not self.enabled: return fallback_color now = datetime.now() time_diff = (now - self.last_pulse_timestamp).seconds if time_diff > self.pulse_frequency: if time_diff > self.pulse_duration + self.pulse_frequency: # End the pulse self.last_pulse_timestamp = now try: with open(FILE_NOTIFICATIONS, 'r') as f: notifications = json.load(f) if notifications: self.index = (self.index + 1) % len(notifications) n = notifications[self.index] return safe_load(n, 'rgb', fallback_color) except: pass return fallback_color
def set_preferences(self, preferences): if preferences is None: return prefs = safe_load(preferences, '0', {}) self.duration = safe_load(prefs, 'duration', 10)