Skip to content

Commit

Permalink
setup calibration on start
Browse files Browse the repository at this point in the history
  • Loading branch information
steersbob committed Dec 16, 2023
1 parent 63e6429 commit e50c344
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 2 additions & 3 deletions brewblox_tilt/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from fastapi import FastAPI

from . import broadcaster, mqtt, parser, scanner, utils
from .stored import devices
from . import broadcaster, mqtt, parser, scanner, stored, utils

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,7 +43,7 @@ def create_app() -> FastAPI:

# Call setup functions for modules
mqtt.setup()
devices.setup()
stored.setup()
parser.setup()
scanner.setup()

Expand Down
2 changes: 1 addition & 1 deletion brewblox_tilt/broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def repeat(self):
await asyncio.sleep(self.scan_interval)
await self.run()
except Exception as ex:
LOGGER.error(ex, exc_info=config.debug)
LOGGER.error(utils.strex(ex), exc_info=config.debug)
await asyncio.sleep(EXCEPTION_DELAY_S)


Expand Down
6 changes: 6 additions & 0 deletions brewblox_tilt/stored/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import calibration, devices


def setup():
calibration.setup()
devices.setup()
14 changes: 14 additions & 0 deletions brewblox_tilt/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import traceback
from functools import lru_cache

from .models import ServiceConfig
Expand All @@ -11,3 +12,16 @@ def get_config() -> ServiceConfig: # pragma: no cover

def time_ms():
return time.time_ns() // 1000000


def strex(ex: Exception, tb=False):
"""
Generic formatter for exceptions.
A formatted traceback is included if `tb=True`.
"""
msg = f'{type(ex).__name__}({str(ex)})'
if tb:
trace = ''.join(traceback.format_exception(None, ex, ex.__traceback__))
return f'{msg}\n\n{trace}'
else:
return msg

0 comments on commit e50c344

Please sign in to comment.