diff --git a/MANIFEST.in b/MANIFEST.in
index 22ffa3f..41b43e5 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,5 +1,5 @@
include README.md
include requirements.txt
-recursive-include octoprint_plotly_graph_lywsd03mmc/templates *
-recursive-include octoprint_plotly_graph_lywsd03mmc/static *
-recursive-include octoprint_plotly_graph_lywsd03mmc/translations *
+recursive-include lywsd03mmc_plotly_graph/templates *
+recursive-include lywsd03mmc_plotly_graph/static *
+recursive-include lywsd03mmc_plotly_graph/translations *
diff --git a/README.md b/README.md
index fd3150a..edfed6b 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-# OctoPrint-PlotlyGraph-LYWSD03MMC
+# lywsd03mmc-plotly-graph
OctoPrint plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph.
diff --git a/octoprint_plotly_graph_lywsd03mmc/__init__.py b/lywsd03mmc_plotly_graph/__init__.py
similarity index 74%
rename from octoprint_plotly_graph_lywsd03mmc/__init__.py
rename to lywsd03mmc_plotly_graph/__init__.py
index e978492..d507f9f 100644
--- a/octoprint_plotly_graph_lywsd03mmc/__init__.py
+++ b/lywsd03mmc_plotly_graph/__init__.py
@@ -5,10 +5,11 @@
import threading
import time
+from lywsd03mmc import Lywsd03mmcClient
-class PlotlyGraphLywsd03mmcPlugin(
+
+class Lywsd03mmcPlotlyGraphPlugin(
octoprint.plugin.SettingsPlugin,
- octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.StartupPlugin
):
@@ -46,15 +47,6 @@ def on_after_startup(self):
else:
self._logger.warning("No MAC address configured. Please configure the sensor MAC address in settings.")
- # AssetPlugin mixin
-
- def get_assets(self):
- return dict(
- js=[],
- css=[],
- less=[]
- )
-
# TemplatePlugin mixin
def get_template_configs(self):
@@ -102,45 +94,34 @@ def _read_sensor(self):
self._battery = None
return
- try:
- # Import here to avoid issues if the library isn't installed
- from lywsd03mmc import Lywsd03mmcClient
-
- # Create or reuse client
- if self._client is None:
- self._logger.info("Connecting to sensor at %s", mac_address)
- try:
- self._client = Lywsd03mmcClient(mac_address)
- except Exception as e:
- self._logger.error("Failed to connect to sensor: %s", e)
- # Reset sensor data when connection fails
- self._temperature = None
- self._humidity = None
- self._battery = None
- return
-
- # Read sensor data
+ # Create or reuse client
+ if self._client is None:
+ self._logger.info("Connecting to sensor at %s", mac_address)
try:
- data = self._client.data
- self._temperature = data.temperature
- self._humidity = data.humidity
- self._battery = data.battery
- self._last_update = time.time()
-
- self._logger.debug("Sensor data - Temp: %.1f°C, Humidity: %d%%, Battery: %d%%",
- self._temperature, self._humidity, self._battery)
+ self._client = Lywsd03mmcClient(mac_address)
except Exception as e:
- self._logger.error("Failed to read sensor data: %s", e)
- # Reset client on data read error to force reconnection on next attempt
- self._client = None
- # Reset sensor data when read fails
+ self._logger.error("Failed to connect to sensor: %s", e)
+ # Reset sensor data when connection fails
self._temperature = None
self._humidity = None
self._battery = None
+ return
- except ImportError:
- self._logger.error("lywsd03mmc library not installed. Please install it: pip install lywsd03mmc")
- # Reset sensor data when library is not available
+ # Read sensor data
+ try:
+ data = self._client.data
+ self._temperature = data.temperature
+ self._humidity = data.humidity
+ self._battery = data.battery
+ self._last_update = time.time()
+
+ self._logger.debug("Sensor data - Temp: %.1f°C, Humidity: %d%%, Battery: %d%%",
+ self._temperature, self._humidity, self._battery)
+ except Exception as e:
+ self._logger.error("Failed to read sensor data: %s", e)
+ # Reset client on data read error to force reconnection on next attempt
+ self._client = None
+ # Reset sensor data when read fails
self._temperature = None
self._humidity = None
self._battery = None
@@ -187,8 +168,8 @@ def get_temperature_data(self, comm, parsed_temps):
def get_update_information(self):
return dict(
- plotlyGraphLywsd03mmc=dict(
- displayName="PlotlyGraph LYWSD03MMC Plugin",
+ lywsd03mmc_plotly_graph=dict(
+ displayName="lywsd03mmc-plotly-graph",
displayVersion=self._plugin_version,
# version check: github repository
@@ -203,9 +184,9 @@ def get_update_information(self):
)
-__plugin_name__ = "PlotlyGraph LYWSD03MMC Sensor"
+__plugin_name__ = "lywsd03mmc-plotly-graph"
__plugin_pythoncompat__ = ">=3.7,<4"
-__plugin_implementation__ = PlotlyGraphLywsd03mmcPlugin()
+__plugin_implementation__ = Lywsd03mmcPlotlyGraphPlugin()
__plugin_version__ = "0.1.0"
__plugin_hooks__ = {
diff --git a/octoprint_plotly_graph_lywsd03mmc/templates/plotly_graph_lywsd03mmc_settings.jinja2 b/lywsd03mmc_plotly_graph/templates/lywsd03mmc_plotly_graph_settings.jinja2
similarity index 86%
rename from octoprint_plotly_graph_lywsd03mmc/templates/plotly_graph_lywsd03mmc_settings.jinja2
rename to lywsd03mmc_plotly_graph/templates/lywsd03mmc_plotly_graph_settings.jinja2
index 06847b0..4be4764 100644
--- a/octoprint_plotly_graph_lywsd03mmc/templates/plotly_graph_lywsd03mmc_settings.jinja2
+++ b/lywsd03mmc_plotly_graph/templates/lywsd03mmc_plotly_graph_settings.jinja2
@@ -4,7 +4,7 @@
-
+
{{ _('The Bluetooth MAC address of your LYWSD03MMC sensor. You can find this in the Xiaomi Home app or by running "sudo hcitool lescan".') }}
@@ -12,7 +12,7 @@
-
+
{{ _('How often to poll the sensor for new data (minimum 10 seconds recommended).') }}
@@ -22,7 +22,7 @@
{{ _('Show humidity readings in the graph.') }}
@@ -32,7 +32,7 @@
{{ _('Show battery level in the graph.') }}
@@ -44,7 +44,7 @@
-
+
{{ _('Label for temperature readings in the graph.') }}
@@ -52,7 +52,7 @@
-
+
{{ _('Label for humidity readings in the graph.') }}
@@ -60,7 +60,7 @@
-
+
{{ _('Label for battery level in the graph.') }}
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..0247596
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,34 @@
+[build-system]
+requires = ["setuptools", "wheel"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "lywsd03mmc-plotly-graph"
+version = "0.1.0"
+description = "Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph"
+authors = [
+ {name = "yutaka551", email = "yutaka551butaman@gmail.com"}
+]
+readme = {file = "README.md", content-type = "text/markdown"}
+license = {text = "MIT"}
+
+requires-python = ">=3.7, <4"
+
+dependencies = [
+ "lywsd03mmc>=0.1.0"
+]
+
+[tool.setuptools]
+include-package-data = true
+
+[tool.setuptools.packages.find]
+include = [
+ "lywsd03mmc_plotly_graph",
+ "lywsd03mmc_plotly_graph.*"
+]
+
+[project.entry-points."octoprint.plugin"]
+lywsd03mmc_plotly_graph = "lywsd03mmc_plotly_graph"
+
+[project.urls]
+Homepage = "https://github.com/yutaka551/lywsd03mmc-plotly-graph"
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 61de12d..0000000
--- a/setup.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# coding=utf-8
-
-# Do not forget to adjust the following variables to your own plugin.
-
-# The plugin's identifier, has to be unique
-plugin_identifier = "plotly_graph_lywsd03mmc"
-
-# The plugin's python package, should be "octoprint_", has to be unique
-plugin_package = "octoprint_plotly_graph_lywsd03mmc"
-
-# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
-# plugin module
-plugin_name = "OctoPrint-PlotlyGraph-LYWSD03MMC"
-
-# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
-plugin_version = "0.1.0"
-
-# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
-# module
-plugin_description = """Plugin to add LYWSD03MMC temperature and humidity sensor data to PlotlyTempGraph"""
-
-# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
-plugin_author = "yutaka551"
-
-# The plugin's author's mail address.
-plugin_author_email = ""
-
-# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
-plugin_url = "https://github.com/yutaka551/lywsd03mmc-plotly-graph"
-
-# The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module
-plugin_license = "AGPLv3"
-
-# Any additional requirements besides OctoPrint should be listed here
-plugin_requires = ["lywsd03mmc>=0.1.0"]
-
-# --------------------------------------------------------------------------------------------------------------------
-# More advanced options that you usually shouldn't have to touch follow after this point
-# --------------------------------------------------------------------------------------------------------------------
-
-# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will
-# already be installed automatically if they exist. Note that if you add something here you'll also need to update
-# MANIFEST.in to match to ensure that python setup.py sdist produces a source distribution that contains all your
-# files. This is sadly due to how python's setup.py works, see also http://stackoverflow.com/a/14159430/2028598
-plugin_additional_data = []
-
-# Any additional python packages you need to install with your plugin that are not contained in .*
-plugin_additional_packages = []
-
-# Any python packages within .* you do NOT want to install with your plugin
-plugin_ignored_packages = []
-
-# Additional parameters for the call to setuptools.setup. If your plugin wants to register additional entry points,
-# define dependency links or other things like that, this is the place to go. Will be merged recursively with the
-# default setup parameters as provided by octoprint_setuptools.create_plugin_setup_parameters using
-# octoprint.util.dict_merge.
-#
-# Example:
-# plugin_requires = ["someDependency==dev"]
-# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
-additional_setup_parameters = {}
-
-########################################################################################################################
-
-from setuptools import setup # noqa: E402
-
-try:
- import octoprint_setuptools
-except ImportError:
- print("Could not import OctoPrint's setuptools, are you sure you are running that under "
- "the same python installation that OctoPrint is installed under?")
- import sys
- sys.exit(-1)
-
-setup_parameters = octoprint_setuptools.create_plugin_setup_parameters(
- identifier=plugin_identifier,
- package=plugin_package,
- name=plugin_name,
- version=plugin_version,
- description=plugin_description,
- author=plugin_author,
- mail=plugin_author_email,
- url=plugin_url,
- license=plugin_license,
- requires=plugin_requires,
- additional_packages=plugin_additional_packages,
- ignored_packages=plugin_ignored_packages,
- additional_data=plugin_additional_data
-)
-
-if len(additional_setup_parameters):
- from octoprint.util import dict_merge
- setup_parameters = dict_merge(setup_parameters, additional_setup_parameters)
-
-setup(**setup_parameters)