From f20536d527d8f0b6d7c7549cc8fc51f28a42659d Mon Sep 17 00:00:00 2001 From: MadOne Date: Mon, 20 Jan 2025 09:26:06 +0000 Subject: [PATCH] Remove matplotlib from dependencys. Make image generation optional. --- custom_components/weishaupt_modbus/kennfeld.py | 16 ++++++++++++---- .../weishaupt_modbus/manifest.json | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/custom_components/weishaupt_modbus/kennfeld.py b/custom_components/weishaupt_modbus/kennfeld.py index 8e30558..ca2272a 100644 --- a/custom_components/weishaupt_modbus/kennfeld.py +++ b/custom_components/weishaupt_modbus/kennfeld.py @@ -7,7 +7,6 @@ import numpy as np from numpy.polynomial import Chebyshev -import matplotlib.pyplot as plt from .configentry import MyConfigEntry @@ -25,12 +24,20 @@ ) SPLINE_AVAILABLE = False + if SPLINE_AVAILABLE is True: log.info( "Scipy available, use precise cubic spline interpolation for heating power" ) from scipy.interpolate import CubicSpline # pylint: disable=E0401 +MATPLOTLIB_AVAILABLE = True +try: + import matplotlib.pyplot as plt +except ModuleNotFoundError: + log.warning("Matplotlib not available. Can't create power map image file") + SPLINE_AVAILABLE = False + class PowerMap: """Power map class.""" @@ -172,9 +179,10 @@ async def initialize(self): self._max_power.append(f(self._all_t)) try: - await self._config_entry.runtime_data.hass.async_add_executor_job( - self.plot_kennfeld_to_file - ) + if MATPLOTLIB_AVAILABLE: + await self._config_entry.runtime_data.hass.async_add_executor_job( + self.plot_kennfeld_to_file + ) except RuntimeError: log.warning("Reconfigure powermap") diff --git a/custom_components/weishaupt_modbus/manifest.json b/custom_components/weishaupt_modbus/manifest.json index 3521936..86588fb 100644 --- a/custom_components/weishaupt_modbus/manifest.json +++ b/custom_components/weishaupt_modbus/manifest.json @@ -1,13 +1,20 @@ { "domain": "weishaupt_modbus", "name": "Weishaupt WBB", - "codeowners": ["@OStrama"], + "codeowners": [ + "@OStrama" + ], "config_flow": true, "documentation": "https://github.com/OStrama/weishaupt_modbus/", "iot_class": "local_polling", "issue_tracker": "https://github.com/OStrama/weishaupt_modbus/issues", - "loggers": ["weishaupt_modbus"], - "requirements": ["pymodbus>=3.6.8", "aiofiles>=24.1.0", "beautifulsoup4>=4.12.3", "matplotlib>=3.9.2"], + "loggers": [ + "weishaupt_modbus" + ], + "requirements": [ + "pymodbus>=3.6.8", + "aiofiles>=24.1.0", + "beautifulsoup4>=4.12.3" + ], "version": "1.0.6" -} - +} \ No newline at end of file