diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-05-19 00:21:32 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-05-19 00:21:32 +0300 |
commit | 70a4e03c962d4fdd321e8756e7cc9f805932b708 (patch) | |
tree | 536c68c2cf913a2d4a9cc6abeb480d350b0d99a9 /src/home/camera/esp32.py | |
parent | 009f1f22f1ff64228460a91e74d49eb409253fec (diff) |
esp32-cam: support applying camera config
Diffstat (limited to 'src/home/camera/esp32.py')
-rw-r--r-- | src/home/camera/esp32.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/home/camera/esp32.py b/src/home/camera/esp32.py index ef0ec53..246022b 100644 --- a/src/home/camera/esp32.py +++ b/src/home/camera/esp32.py @@ -47,6 +47,50 @@ class WebClient: self.delay = 0 self.isfirstrequest = True + def syncsettings(self, settings) -> bool: + status = self.getstatus() + self.logger.debug(f'syncsettings: status={status}') + + changed_anything = False + + for name, value in settings.items(): + server_name = name + if name == 'aec_dsp': + server_name = 'aec2' + + if server_name not in status: + # legacy compatibility + if server_name != 'vflip': + self.logger.warning(f'syncsettings: field `{server_name}` not found in camera status') + continue + + try: + # server returns 0 or 1 for bool values + if type(value) is bool: + value = int(value) + + if status[server_name] == value: + continue + except KeyError as exc: + if name != 'vflip': + self.logger.error(exc) + + try: + # fix for cases like when field is called raw_gma, but method is setrawgma() + name = name.replace('_', '') + + func = getattr(self, f'set{name}') + self.logger.debug(f'syncsettings: calling set{name}({value})') + + func(value) + + changed_anything = True + except AttributeError as exc: + self.logger.exception(exc) + self.logger.error(f'syncsettings: method set{name}() not found') + + return changed_anything + def setdelay(self, delay: int): self.delay = delay @@ -59,7 +103,9 @@ class WebClient: def setflash(self, enable: bool): self._control('flash', int(enable)) - def setresolution(self, fs: FrameSize): + def setframesize(self, fs: Union[int, FrameSize]): + if type(fs) is int: + fs = FrameSize(fs) self._control('framesize', fs.value) def sethmirror(self, enable: bool): |