From c174cef20eb165eda2ac7f3e1e0c594ffba4fbd1 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Sun, 4 Jun 2023 12:23:28 -0400 Subject: [PATCH] Added device-specific option to disable profile changes without a key. --- owrx/connection.py | 2 ++ owrx/property/__init__.py | 4 ++-- owrx/source/__init__.py | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/owrx/connection.py b/owrx/connection.py index 5d6e73c2..e4a9603f 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -305,6 +305,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): self.setSdr(profile[0]) if not self.sdr.isLocked() or magic == "" or key == magic: self.sdr.activateProfile(profile[1]) + else: + self.sdr.activateProfile(self.sdr.getProfileId(), force=True) elif message["type"] == "setfrequency": # If the magic key is set in the settings, only allow # changes if it matches the received key diff --git a/owrx/property/__init__.py b/owrx/property/__init__.py index 7cc84f64..91ebf8e0 100644 --- a/owrx/property/__init__.py +++ b/owrx/property/__init__.py @@ -406,7 +406,7 @@ class PropertyCarousel(PropertyDelegator): self.switch() del self.layers[key] - def switch(self, key=None): + def switch(self, key=None, force=False): before = self.pm self.subscription.cancel() self.pm = self._getDefaultLayer() if key is None else self.layers[key] @@ -416,6 +416,6 @@ class PropertyCarousel(PropertyDelegator): if key not in self: changes[key] = PropertyDeleted else: - if key not in before or before[key] != self[key]: + if key not in before or before[key] != self[key] or force: changes[key] = self[key] self._fireCallbacks(changes) diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index c84a0eff..5ac3cd3e 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -239,10 +239,10 @@ class SdrSource(ABC): def getCommand(self): return [self.getCommandMapper().map(self.getCommandValues())] - def activateProfile(self, profile_id): + def activateProfile(self, profile_id, force=False): logger.debug("activating profile {0} for {1}".format(profile_id, self.getId())) try: - self.profileCarousel.switch(profile_id) + self.profileCarousel.switch(profile_id, force=force) self.setCenterFreq(self.profileCarousel["center_freq"]) except KeyError: logger.warning("invalid profile %s for sdr %s. ignoring", profile_id, self.getId()) @@ -574,7 +574,7 @@ class SdrDeviceDescription(object): ), CheckboxInput( "key_locked", - "Protect access to this device with a magic key", + "Require magic key to switch profiles on this device", ), GainInput("rf_gain", "Device gain", self.hasAgc()), NumberInput(