Fails to start when crc is not installed
Refactoring the DS18B20 plugin to not create a brand new CRC calculator for every read required importing the crc module to even read the plugin, regardless of if it is used or not.
I don't want to require installing dependencies that we don't need, so I need to refactor DS18B20 to only import crc during setup, then reuse that single instance of the calculator.
Traceback (most recent call last):
File "/root/mqtt4hass/mqtt4hass.py", line 471, in <module>
sys.exit(main())
^^^^^^
File "/root/mqtt4hass/mqtt4hass.py", line 444, in main
ctrl = Controller()
^^^^^^^^^^^^
File "/root/mqtt4hass/mqtt4hass.py", line 189, in __init__
self.avialable_plugins = self.__discover_plugins()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/mqtt4hass/mqtt4hass.py", line 179, in __discover_plugins
return {
^
File "/root/mqtt4hass/mqtt4hass.py", line 180, in <dictcomp>
name: importlib.import_module(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/root/mqtt4hass/plugins/ds18b20/__init__.py", line 3, in <module>
from crc import Calculator, Configuration
ModuleNotFoundError: No module named 'crc'